Documentation ¶
Index ¶
- Variables
- func AutoDecode(data []byte, encodings []Encoding, keyWords []string) (text []byte, encName string, err error)
- func DecodeStringWithBOM(b []byte) (string, error)
- func DecodeUTF16(b []byte, byteOrder binary.ByteOrder) ([]byte, error)
- func DecodeUTF16String(b []byte, byteOrder binary.ByteOrder) (string, error)
- func DecodeUTF32(b []byte, byteOrder binary.ByteOrder) ([]byte, error)
- func DecodeUTF32String(b []byte, byteOrder binary.ByteOrder) (string, error)
- func DecodeWithBOM(b []byte) ([]byte, error)
- func EncodeUTF16(b []byte, byteOrder binary.ByteOrder) ([]byte, error)
- func EncodeUTF32(b []byte, byteOrder binary.ByteOrder) ([]byte, error)
- func EncodingNames() []string
- func TrimBOM(b []byte, bom BOM) []byte
- type BOM
- type Encoding
Constants ¶
This section is empty.
Variables ¶
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 DecodeUTF16String ¶
func DecodeUTF32String ¶
func DecodeWithBOM ¶
func EncodingNames ¶
func EncodingNames() []string
EncodingNames returns the sorted names of all supported encodings
Types ¶
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 ¶
GetEncoding returns an Encoding for a name or an error. Common variants of the passed name will be considered.
func MustGetEncoding ¶
MustGetEncoding returns an Encoding for a name or panics. Common variants of the passed name will be considered.
func UTF16Encoding ¶
UTF16Encoding returns an UTF-16 Encoding with the passed binary.ByteOrder
func UTF32Encoding ¶
UTF32Encoding returns an UTF-32 Encoding with the passed binary.ByteOrder
func UTF8Encoding ¶
func UTF8Encoding() Encoding