Documentation
¶
Index ¶
- Constants
- func FormatBinary(r rune) string
- func ReadRune(reader io.Reader) (rune, int, error)
- func RuneLength(r rune) int
- func WriteRune(writer io.Writer, r rune) (int, error)
- type InvalidUTF8Complainer
- type NilReaderComplainer
- type NilWriterComplainer
- type RuneReader
- type RuneScanner
- type RuneWriter
Constants ¶
const (
RuneError = '\uFFFD' // Unicode Replacement Character (U+FFFD).
)
Variables ¶
This section is empty.
Functions ¶
func FormatBinary ¶
FormatBinary returns a representation of a rune as a sequence of bytes, given in binary format.
Example
utf8.FormatBinary('۵')
// Outputs:
// <<0b11011011 ; 0b10110101>>
func ReadRune ¶
ReadRune reads a single UTF-8 encoded Unicode character from an io.Reader, and returns the Unicode character (as a Go rune) and the number of bytes read.
If ‘reader’ is nil then ReaderRune will return an error that matches utf8.NilReaderComplainer.
Example ¶
Here is an example usage of ReadRune:
r, n, err := utf8.ReadRune(reader)
if nil != err {
switch err.(type) {
case utf8.NilReaderComplainer:
//@TODO
case utf8.InvalidUTF8Complainer:
//@TODO
default:
//TODO
}
}
if utf8.RuneError == r {
//@TODO
}
Number Of Bytes ¶
Note that a single UTF-8 encoded Unicode character could be more than one byte.
For example, the Unicode "≡" (IDENTICAL TO) character gets encoded using 3 bytes under UTF-8.
func RuneLength ¶
RuneLength returns the number of bytes in a UTF-8 encoding of this Unicode code point.
Example
length := utf8.RuneLength('A')
// length == 1
Example
length := utf8.RuneLength('r')
// length == 1
Example
length := utf8.RuneLength('¡')
// length == 2
Example
length := utf8.RuneLength('۵')
// length == 2
func WriteRune ¶
WriteRune writes a single UTF-8 encoded Unicode character and returns the number of bytes written.
If ‘writer’ is nil then WriteRune will return an error that matches utf8.NilWriterComplainer.
Example ¶
Here is an example usage of WriteRune:
n, err := utf8.WriteRune(writer, r)
if nil != err {
switch err.(type) {
case utf8.NilWriterComplainer:
//@TODO
default:
//TODO
}
}
Types ¶
type InvalidUTF8Complainer ¶
type InvalidUTF8Complainer interface {
error
InvalidUTF8Complainer()
}
InvalidUTF8Complainer is a type of error that could be returned by the utf8.ReadRune() function, by the utf8.RuneReader.ReadRune() method, and by the utf8.RuneScanner.ReadRune() method.
Here is how one might use this type:
r, n, err := utf8.ReadRune(reader)
if nil != err {
switch {
case utf8.InvalidUTF8Complainer:
//@TODO
default:
//@TODO
}
}
type NilReaderComplainer ¶
type NilReaderComplainer interface {
error
NilReaderComplainer()
}
type NilWriterComplainer ¶
type NilWriterComplainer interface {
error
NilWriterComplainer()
}
type RuneReader ¶
type RuneReader struct {
// contains filtered or unexported fields
}
A utf8.RuneReader implements the io.RuneReader interface by reading from an io.Reader.
func RuneReaderWrap ¶
func RuneReaderWrap(reader io.Reader) RuneReader
type RuneScanner ¶
type RuneScanner struct {
// contains filtered or unexported fields
}
A utf8.RuneScanner implements the io.RuneScanner interface by reading from an io.Reader.
func RuneScannerWrap ¶
func RuneScannerWrap(reader io.Reader) RuneScanner
func (*RuneScanner) UnreadRune ¶
func (receiver *RuneScanner) UnreadRune() error
type RuneWriter ¶
type RuneWriter struct {
// contains filtered or unexported fields
}
RuneWriter writes a single UTF-8 encoded Unicode characters.
func RuneWriterWrap ¶
func RuneWriterWrap(writer io.Writer) RuneWriter
RuneWriterWrap wraps an io.Writer and returns a RuneWriter.