Skip to content

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
)
func AppendRune(p []byte, r rune) []byte

AppendRune appends the UTF-8 encoding of r to p. Invalid runes encode as RuneError.

func DecodeLastRune(p []byte) (rune, int)

DecodeLastRune unpacks the last UTF-8 encoding in p.

func DecodeLastRuneInString(s string) (rune, int)

DecodeLastRuneInString is like DecodeLastRune but its input is a string.

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.

func DecodeRuneInString(s string) (rune, int)

DecodeRuneInString is like DecodeRune but its input is a string.

func EncodeRune(p []byte, r rune) int

EncodeRune writes the UTF-8 encoding of r into p, which must be large enough, and returns the number of bytes written.

func FullRune(p []byte) bool

FullRune 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.

func FullRuneInString(s string) bool

FullRuneInString is like FullRune but its input is a string.

func RuneCount(p []byte) int

RuneCount returns the number of runes in p, counting each invalid byte as one rune.

func RuneCountInString(s string) int

RuneCountInString is like RuneCount but its input is a string.

func RuneLen(r rune) int

RuneLen returns the number of bytes needed to encode r, or -1 if r is not a valid Unicode scalar value.

func RuneStart(b byte) bool

RuneStart reports whether b could be the first byte of an encoded rune.

func Valid(p []byte) bool

Valid reports whether p consists entirely of valid UTF-8 encodings.

func ValidRune(r rune) bool

ValidRune reports whether r can be legally encoded as UTF-8.

func ValidString(s string) bool

ValidString reports whether s consists entirely of valid UTF-8 encodings.