encoding

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CharsetUTF8    = "utf-8"
	CharsetUTF16   = "utf-16"
	CharsetUTF16BE = "utf-16be"
	CharsetUTF16LE = "utf-16le"
	CharsetISO8859 = "iso-8859-1"
)

Variables

View Source
var (
	UTF16BEBOM = []byte{0xFE, 0xFF}
	UTF16LEBOM = []byte{0xFF, 0xFE}
)

Functions

func DetectEncoding

func DetectEncoding(contentType string, data []byte) encoding.Encoding

DetectEncoding attempts to determine the encoding of data. It first checks the Content-Type header, then falls back to examining the data. If no encoding can be determined, it returns UTF-8 as the default.

func GetEncodingFromCharset

func GetEncodingFromCharset(charset string) encoding.Encoding

GetEncodingFromCharset returns the encoding for a given charset name. Returns nil if the charset is unknown.

func GetEncodingFromContentType

func GetEncodingFromContentType(contentType string) encoding.Encoding

GetEncodingFromContentType extracts and returns the encoding from a Content-Type header. Returns nil if no charset is specified or the charset is unknown.

func HasUTF16BOM

func HasUTF16BOM(data []byte) bool

HasUTF16BOM returns true if the data begins with a UTF-16 byte order mark.

Types

This section is empty.

Jump to

Keyboard shortcuts

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