Documentation ¶
Overview ¶
Package cesu8 implements functions and constants to support text encoded in CESU-8. It implements functions comparable to the unicode/utf8 package for UTF-8 de- and encoding.
Package cesu8 implements functions and constants to support text encoded in CESU-8. It implements functions comparable to the unicode/utf8 package for UTF-8 de- and encoding.
Index ¶
- Constants
- func DecodeRune(p []byte) (rune, int)
- func DefaultDecoder() transform.Transformer
- func DefaultEncoder() transform.Transformer
- func EncodeRune(p []byte, r rune) int
- func FullRune(p []byte) bool
- func ReplaceErrorHandler(err *DecodeError) (rune, error)
- func RuneLen(r rune) int
- func Size(p []byte) int
- func StringSize(s string) int
- type DecodeError
- type Decoder
- type Encoder
Constants ¶
const ( UTF8 = "UTF-8" CESU8 = "CESU-8" )
Encoding constants.
const (
// CESUMax is the maximum amount of bytes used by an CESU-8 codepoint encoding.
CESUMax = 6
)
Variables ¶
This section is empty.
Functions ¶
func DecodeRune ¶
DecodeRune unpacks the first CESU-8 encoding in p and returns the rune and its width in bytes.
func DefaultDecoder ¶
func DefaultDecoder() transform.Transformer
DefaultDecoder returns the default CESU-8 to UTF-8 decoder.
func DefaultEncoder ¶
func DefaultEncoder() transform.Transformer
DefaultEncoder returns the default UTF-8 to CESU-8 encoder.
func EncodeRune ¶
EncodeRune writes into p (which must be large enough) the CESU-8 encoding of the rune. It returns the number of bytes written.
func FullRune ¶
FullRune reports whether the bytes in p begin with a full CESU-8 encoding of a rune.
func ReplaceErrorHandler ¶
func ReplaceErrorHandler(err *DecodeError) (rune, error)
ReplaceErrorHandler is a decoding error handling function replacing invalid CESU-8 data with the unicode replacement character '\uFFFD'.
Types ¶
type DecodeError ¶
type DecodeError struct {
// contains filtered or unexported fields
}
DecodeError is raised when a transformer detects invalid encoded data.
func (*DecodeError) Enc ¶
func (e *DecodeError) Enc() string
Enc returns the expected encoding of the erroneous data.
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
func (*DecodeError) Is ¶ added in v0.107.4
func (e *DecodeError) Is(target error) bool
Is returns true on the target driver errors.Fatal, false otherwise.
func (*DecodeError) Pos ¶
func (e *DecodeError) Pos() int
Pos returns the position of the invalid rune.
func (*DecodeError) Value ¶
func (e *DecodeError) Value() []byte
Value returns the value which should be decoded.
type Decoder ¶
type Decoder struct { transform.NopResetter // contains filtered or unexported fields }
Decoder supports decoding of CESU-8 encoded data into UTF-8.
func NewDecoder ¶
func NewDecoder(errorHandler func(err *DecodeError) (rune, error)) *Decoder
NewDecoder creates a new decoder instance. With parameter errorHandler a custom error handling function could be used in case the decoder would detect invalid CESU-8 encoded characters.
type Encoder ¶
type Encoder struct { transform.NopResetter // contains filtered or unexported fields }
Encoder supports encoding of UTF-8 encoded data into CESU-8.
func NewEncoder ¶
func NewEncoder(errorHandler func(err *DecodeError) (rune, error)) *Encoder
NewEncoder creates a new encoder instance. With parameter errorHandler a custom error handling function could be used in case the encoder would detect invalid UTF-8 encoded characters.