charset

package
v0.0.0-...-8363780 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoBOM BOM
	// UTF-8, BOM bytes: EF BB BF
	BOMUTF8 = BOM(bomUTF8)
	// UTF-16BE, BOM bytes: FE FF
	BOMUTF16BE = BOM(bomUTF16BE)
	// UTF-16LE, BOM bytes: FF FE
	BOMUTF16LE = BOM(bomUTF16LE)
	// UTF-32BE, BOM bytes: 00 00 FE FF
	BOMUTF32BE = BOM(bomUTF32BE)
	// UTF-32LE, BOM bytes: FF FE 00 00
	BOMUTF32LE = BOM(bomUTF32LE)
)

Functions

func AutoDecode

func AutoDecode(data []byte, encodings []Encoding, keyWords []string) (text []byte, encName string, err error)

AutoDecode tries to automatically decode the passed data as text. If data begins with an UTF BOM, then the BOM information will be used for decoding. If there is no BOM, then data will be decoded with all passed encodings and the passed keyWords will be counted in the error free decoded texts. The decoded text and encoding name will be returned for the encoding with the most key-word matches. If no key-word was found for any of the encodings, then data will be returned unchanged with an empty string as encoding name.

func DecodeStringWithBOM

func DecodeStringWithBOM(b []byte) (string, error)

func DecodeUTF16

func DecodeUTF16(b []byte, byteOrder binary.ByteOrder) ([]byte, error)

func DecodeUTF16String

func DecodeUTF16String(b []byte, byteOrder binary.ByteOrder) (string, error)

func DecodeUTF32

func DecodeUTF32(b []byte, byteOrder binary.ByteOrder) ([]byte, error)

func DecodeUTF32String

func DecodeUTF32String(b []byte, byteOrder binary.ByteOrder) (string, error)

func DecodeWithBOM

func DecodeWithBOM(b []byte) ([]byte, error)

func EncodeUTF16

func EncodeUTF16(b []byte, byteOrder binary.ByteOrder) ([]byte, error)

func EncodeUTF32

func EncodeUTF32(b []byte, byteOrder binary.ByteOrder) ([]byte, error)

func EncodingNames

func EncodingNames() []string

EncodingNames returns the sorted names of all supported encodings

func TrimBOM

func TrimBOM(b []byte, bom BOM) []byte

Types

type BOM

type BOM string

BOM is a Unicode Byte Order Mark

func BOMOfBytes

func BOMOfBytes(b []byte) BOM

func BOMOfString

func BOMOfString(str string) BOM

func SplitBOM

func SplitBOM(b []byte) (BOM, []byte)

func (BOM) Decode

func (bom BOM) Decode(data []byte) ([]byte, error)

func (BOM) DecodeString

func (bom BOM) DecodeString(data []byte) (string, error)

func (BOM) Encoding

func (bom BOM) Encoding() (Encoding, error)

func (BOM) Endian

func (bom BOM) Endian() binary.ByteOrder

func (BOM) String

func (bom BOM) String() string

String implements the fmt.Stringer interface.

type Encoding

type Encoding interface {
	Encode(utf8Str []byte) (encodedStr []byte, err error)
	Decode(encodedStr []byte) (utf8Str []byte, err error)
	Name() string
	String() string

	// BOM returns the Unicode Byte Order Mark of the encoding
	// or NoBOM if the encoding has no BOM.
	BOM() BOM
}

Encoding provides threadsafe methods for encoding and decoding text

func GetEncoding

func GetEncoding(name string) (Encoding, error)

GetEncoding returns an Encoding for a name or an error. Common variants of the passed name will be considered.

func MustGetEncoding

func MustGetEncoding(name string) Encoding

MustGetEncoding returns an Encoding for a name or panics. Common variants of the passed name will be considered.

func UTF16Encoding

func UTF16Encoding(byteOrder binary.ByteOrder) Encoding

UTF16Encoding returns an UTF-16 Encoding with the passed binary.ByteOrder

func UTF32Encoding

func UTF32Encoding(byteOrder binary.ByteOrder) Encoding

UTF32Encoding returns an UTF-32 Encoding with the passed binary.ByteOrder

func UTF8Encoding

func UTF8Encoding() Encoding

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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