std/unicode/utf8
import "github.com/eugenioenko/goalchemy/std/unicode/utf8"Package utf8 encodes and decodes UTF-8 text.
const ( RuneError = '�' RuneSelf = 0x80 MaxRune = '\U0010FFFF' UTFMax = 4)AppendRune
Section titled “AppendRune”func AppendRune(p []byte, r rune) []byteAppendRune appends the UTF-8 encoding of r to p. Invalid runes encode as RuneError.
DecodeLastRune
Section titled “DecodeLastRune”func DecodeLastRune(p []byte) (rune, int)DecodeLastRune unpacks the last UTF-8 encoding in p.
DecodeLastRuneInString
Section titled “DecodeLastRuneInString”func DecodeLastRuneInString(s string) (rune, int)DecodeLastRuneInString is like DecodeLastRune but its input is a string.
DecodeRune
Section titled “DecodeRune”func DecodeRune(p []byte) (rune, int)DecodeRune unpacks the first UTF-8 encoding in p and returns the rune and its width in bytes. It returns (RuneError, 0) for empty input and (RuneError, 1) for an invalid encoding.
DecodeRuneInString
Section titled “DecodeRuneInString”func DecodeRuneInString(s string) (rune, int)DecodeRuneInString is like DecodeRune but its input is a string.
EncodeRune
Section titled “EncodeRune”func EncodeRune(p []byte, r rune) intEncodeRune writes the UTF-8 encoding of r into p, which must be large enough, and returns the number of bytes written.
FullRune
Section titled “FullRune”func FullRune(p []byte) boolFullRune reports whether the bytes in p begin with a full UTF-8 encoding of a rune. An invalid encoding is considered a full rune since it will convert as a width-1 error rune.
FullRuneInString
Section titled “FullRuneInString”func FullRuneInString(s string) boolFullRuneInString is like FullRune but its input is a string.
RuneCount
Section titled “RuneCount”func RuneCount(p []byte) intRuneCount returns the number of runes in p, counting each invalid byte as one rune.
RuneCountInString
Section titled “RuneCountInString”func RuneCountInString(s string) intRuneCountInString is like RuneCount but its input is a string.
RuneLen
Section titled “RuneLen”func RuneLen(r rune) intRuneLen returns the number of bytes needed to encode r, or -1 if r is not a valid Unicode scalar value.
RuneStart
Section titled “RuneStart”func RuneStart(b byte) boolRuneStart reports whether b could be the first byte of an encoded rune.
func Valid(p []byte) boolValid reports whether p consists entirely of valid UTF-8 encodings.
ValidRune
Section titled “ValidRune”func ValidRune(r rune) boolValidRune reports whether r can be legally encoded as UTF-8.
ValidString
Section titled “ValidString”func ValidString(s string) boolValidString reports whether s consists entirely of valid UTF-8 encodings.