charset

package
v1.17.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: MIT Imports: 13 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UTF8BOM = []byte{'\xef', '\xbb', '\xbf'}

UTF8BOM is the utf-8 byte-order marker

Functions

func DetectEncoding

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

DetectEncoding detect the encoding of content

func RemoveBOMIfPresent

func RemoveBOMIfPresent(content []byte) []byte

RemoveBOMIfPresent removes a UTF-8 BOM from a []byte

func ToUTF8

func ToUTF8(content string) string

ToUTF8 converts content to UTF8 encoding and ignore error

func ToUTF8DropErrors

func ToUTF8DropErrors(content []byte) []byte

ToUTF8DropErrors makes sure the return string is valid utf-8; attempts conversion if possible

func ToUTF8WithErr

func ToUTF8WithErr(content []byte) (string, error)

ToUTF8WithErr converts content to UTF8 encoding

func ToUTF8WithFallback

func ToUTF8WithFallback(content []byte) []byte

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

func ToUTF8WithFallbackReader added in v1.15.0

func ToUTF8WithFallbackReader(rd io.Reader) io.Reader

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

Types

type EscapeStatus added in v1.16.0

type EscapeStatus struct {
	Escaped      bool
	HasError     bool
	HasBadRunes  bool
	HasControls  bool
	HasSpaces    bool
	HasMarks     bool
	HasBIDI      bool
	BadBIDI      bool
	HasRTLScript bool
	HasLTRScript bool
}

EscapeStatus represents the findings of the unicode escaper

func EscapeControlBytes added in v1.16.0

func EscapeControlBytes(text []byte) (EscapeStatus, []byte)

EscapeControlBytes escapes the unicode control sequences a provided []byte and returns the findings as an EscapeStatus and the escaped []byte

func EscapeControlReader added in v1.16.0

func EscapeControlReader(text io.Reader, output io.Writer) (escaped EscapeStatus, err error)

EscapeControlReader escapes the unicode control sequences a provided Reader writing the escaped output to the output and returns the findings as an EscapeStatus and an error

func EscapeControlString added in v1.16.0

func EscapeControlString(text string) (EscapeStatus, string)

EscapeControlString escapes the unicode control sequences in a provided string and returns the findings as an EscapeStatus and the escaped string

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

Jump to

Keyboard shortcuts

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