cesu8

package
v0.113.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

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

View Source
const (
	UTF8  = "UTF-8"
	CESU8 = "CESU-8"
)

Encoding constants.

View Source
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

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

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

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

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

func FullRune(p []byte) bool

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

func RuneLen

func RuneLen(r rune) int

RuneLen returns the number of bytes required to encode the rune.

func Size

func Size(p []byte) int

Size returns the amount of bytes needed to encode an UTF-8 byte slice to CESU-8.

func StringSize

func StringSize(s string) int

StringSize is like Size with a string as parameter.

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.

func (*Decoder) Transform

func (d *Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform implements the transform.Transformer interface.

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.

func (*Encoder) Transform

func (e *Encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform implements the transform.Transformer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL