代码拉取完成,页面将自动刷新
package encoding
import (
"io"
"strings"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/htmlindex"
"golang.org/x/text/encoding/simplifiedchinese"
)
type EncodingFactory func(io.Reader) (Encoding, error)
type Encoding encoding.Encoding
var encodings = map[string]EncodingFactory{
// default
"nop": Plain,
"plain": Plain,
// utf8 (validate input) - shadow htmlindex utf8 codecs not validating input
"unicode-1-1-utf-8": utf8Encoding,
"utf-8": utf8Encoding,
"utf8": utf8Encoding,
// simplified chinese
"gbk": enc(simplifiedchinese.GBK), // shadow htmlindex using 'GB10830' for GBK
// 8bit charmap encodings
"iso8859-6e": enc(charmap.ISO8859_6E),
"iso8859-6i": enc(charmap.ISO8859_6I),
"iso8859-8e": enc(charmap.ISO8859_8E),
"iso8859-8i": enc(charmap.ISO8859_8I),
// utf16 bom codecs (seekable data source required)
"utf-16-bom": utf16BOMRequired,
"utf-16be-bom": utf16BOMBigEndian,
"utf-16le-bom": utf16BOMLittleEndian,
}
// Plain file encoding not transforming any read bytes.
var Plain = enc(encoding.Nop)
// UTF-8 encoding copying input to output sequence replacing invalid UTF-8
// converted to '\uFFFD'.
//
// See: http://encoding.spec.whatwg.org/#replacement
var utf8Encoding = enc(mixed{})
// FindEncoding searches for an EncodingFactoryby name.
func FindEncoding(name string) (EncodingFactory, bool) {
if name == "" {
return Plain, true
}
d, ok := encodings[strings.ToLower(name)]
if ok {
return d, ok
}
codec, err := htmlindex.Get(name)
if err != nil {
return nil, false
}
return enc(codec), true
}
func enc(e Encoding) EncodingFactory {
return func(io.Reader) (Encoding, error) {
return e, nil
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。