encoding

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectBOM

func DetectBOM(data []byte) (charset string, bomLen int)

DetectBOM inspects the leading bytes for a Unicode BOM and returns the detected charset and number of BOM bytes to skip. Returns ("", 0) if no BOM is found.

func ExtractCharset

func ExtractCharset(contentType string) string

ExtractCharset parses the charset parameter from a Content-Type header value. Returns empty string if no charset is declared.

func NormalizeCharset

func NormalizeCharset(charset string) string

NormalizeCharset maps common charset aliases to canonical lowercase names.

func ToUTF8

func ToUTF8(data []byte, charset string) ([]byte, error)

ToUTF8 transcodes data from the given charset to UTF-8. If charset is empty or "utf-8", the data is returned with the BOM stripped (if present) but otherwise unchanged. Invalid UTF-8 sequences in already- UTF-8 data are replaced with U+FFFD to ensure valid output.

Types

This section is empty.

Jump to

Keyboard shortcuts

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