charset

package
v1.27.0-dev Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 17 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ToUTF8WithFallbackReaderPrefetchSize = 16 * 1024

Functions

func AllowRuneNBSP added in v1.26.0

func AllowRuneNBSP() map[rune]bool

func DetectEncoding

func DetectEncoding(content []byte) (encoding string, _ error)

DetectEncoding detect the encoding of content it always returns a detected or guessed "encoding" string, no matter error happens or not

func ToUTF8

func ToUTF8(content []byte, opts ConvertOpts) []byte

func ToUTF8DropErrors

func ToUTF8DropErrors(content []byte) []byte

func ToUTF8WithFallback

func ToUTF8WithFallback(content []byte, opts ConvertOpts) []byte

ToUTF8WithFallback detects the encoding of content and converts to UTF-8 if possible

func ToUTF8WithFallbackReader added in v1.15.0

func ToUTF8WithFallbackReader(rd io.Reader, opts ConvertOpts) io.Reader

ToUTF8WithFallbackReader detects the encoding of content and converts to UTF-8 reader if possible

Types

type AmbiguousTable added in v1.17.4

type AmbiguousTable struct {
	Confusable []rune
	With       []rune
	Locale     string
	RangeTable *unicode.RangeTable
}

AmbiguousTable matches a confusable rune with its partner for the Locale

func AmbiguousTablesForLocale added in v1.17.4

func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable

AmbiguousTablesForLocale provides the table of ambiguous characters for this locale.

type ConvertOpts added in v1.21.5

type ConvertOpts struct {
	KeepBOM           bool
	ErrorReplacement  []byte
	ErrorReturnOrigin bool
}

type EscapeOptions added in v1.26.0

type EscapeOptions struct {
	Allowed map[rune]bool
}

func EscapeOptionsForView added in v1.26.0

func EscapeOptionsForView() EscapeOptions

type EscapeStatus added in v1.16.0

type EscapeStatus struct {
	Escaped      bool // it means that some characters were escaped, and they can also be unescaped back
	HasInvisible bool
	HasAmbiguous bool
}

EscapeStatus represents the findings of the Unicode escaper

func EscapeControlHTML added in v1.17.4

func EscapeControlHTML(html template.HTML, locale translation.Locale, opts ...EscapeOptions) (escaped *EscapeStatus, output template.HTML)

EscapeControlHTML escapes the Unicode control sequences in a provided html document

func EscapeControlReader added in v1.16.0

func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, opts ...EscapeOptions) (*EscapeStatus, error)

EscapeControlReader escapes the Unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus

func (*EscapeStatus) Or added in v1.16.0

func (status *EscapeStatus) Or(other *EscapeStatus) *EscapeStatus

Or combines two EscapeStatus structs into one representing the conjunction of the two

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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