2022-07-18 23:30:32 +00:00
|
|
|
# go-utf8
|
2018-07-02 06:04:04 +00:00
|
|
|
|
2022-07-18 23:36:02 +00:00
|
|
|
Package **utf8** provides tools for working with Unicode encoded as UTF-8, for the Go programming language.
|
2018-07-02 06:04:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Documention
|
|
|
|
|
2022-07-18 23:30:32 +00:00
|
|
|
Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-utf8
|
2018-07-02 06:04:04 +00:00
|
|
|
|
2022-07-18 23:30:32 +00:00
|
|
|
[![GoDoc](https://godoc.org/github.com/reiver/go-utf8?status.svg)](https://godoc.org/github.com/reiver/go-utf8)
|
2018-07-02 06:04:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```go
|
|
|
|
var reader io.Reader
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
2022-07-18 23:36:02 +00:00
|
|
|
r, n, err := utf8.ReadRune(reader)
|
2018-07-02 06:04:04 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
```go
|
|
|
|
var writer io.Writer
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
var r rune
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
2022-07-18 23:36:02 +00:00
|
|
|
n, err := utf8.WriteRune(w, r)
|
2018-07-02 06:04:04 +00:00
|
|
|
```
|
2018-07-11 03:43:45 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
var reader io.Reader
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
2022-07-18 23:36:02 +00:00
|
|
|
runeReader := utf8.NewRuneReader(reader)
|
2018-07-11 03:43:45 +00:00
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
r, n, err := runeReader.ReadRune()
|
|
|
|
```
|
2018-07-11 04:01:30 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
var reader io.Reader
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
2022-07-18 23:36:02 +00:00
|
|
|
runeScanner := utf8.NewRuneScanner(reader)
|
2018-07-11 04:01:30 +00:00
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
r, n, err := runeScanner.ReadRune()
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
err = runeScanner.UnreadRune()
|
|
|
|
```
|