charsetutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknown = errors.New("unknown character set")

Error of a character set name that no character set answers to

Functions

func Canonical

func Canonical(name string) (string, bool)

Canonical name of a character set label in any spelling, false when no character set answers to it

func Decode

func Decode(data []byte, name string) (string, error)

Text of bytes in the named character set, a *DecodeError for bytes it cannot decode or ErrUnknown for an unknown name

func DecodeReplace

func DecodeReplace(data []byte, name string) (string, error)

Text of bytes in the named character set with every undecodable sequence turned into U+FFFD, the error only ErrUnknown for an unknown name

func Encode

func Encode(text, name string) ([]byte, error)

Bytes of text in the named character set, an *EncodeError for a character it cannot encode or ErrUnknown for an unknown name

func Locale

func Locale() string

Canonical name of the process locale's character set: the codeset LC_ALL, LC_CTYPE or LANG names, the C library's codeset for a locale that names none, and UTF-8 for an unset, C or POSIX locale, on Android, or for a codeset this package does not know

Types

type DecodeError

type DecodeError struct {
	Charset string // canonical name of the character set
	Offset  int    // offset of the first byte of the sequence that does not decode, always inside the input
	Reason  string // what is wrong with that sequence
}

Bytes that are not valid text in a character set, found at a byte offset of the input

func (*DecodeError) Error

func (e *DecodeError) Error() string

Message naming the offset, the character set and the reason

type EncodeError

type EncodeError struct {
	Charset string // canonical name of the character set
	Offset  int    // byte offset of the character in the text
	Char    rune   // the character, -1 when the text is not valid UTF-8 at Offset
}

Text holding a character the character set has no bytes for, or text that is not valid UTF-8

func (*EncodeError) Error

func (e *EncodeError) Error() string

Message naming the character, its offset and the character set

Jump to

Keyboard shortcuts

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