MCPcopy Create free account
hub / github.com/gogs/gogs / DetectEncoding

Function DetectEncoding

internal/tool/tool.go:33–47  ·  view source on GitHub ↗

DetectEncoding returns best guess of encoding of given content.

(content []byte)

Source from the content-addressed store, hash-verified

31
32// DetectEncoding returns best guess of encoding of given content.
33func DetectEncoding(content []byte) (string, error) {
34 if utf8.Valid(content) {
35 log.Trace("Detected encoding: UTF-8 (fast)")
36 return "UTF-8", nil
37 }
38
39 result, err := chardet.NewTextDetector().DetectBest(content)
40 if result.Charset != "UTF-8" && len(conf.Repository.ANSICharset) > 0 {
41 log.Trace("Using default ANSICharset: %s", conf.Repository.ANSICharset)
42 return conf.Repository.ANSICharset, err
43 }
44
45 log.Trace("Detected encoding: %s", result.Charset)
46 return result.Charset, err
47}
48
49// BasicAuthDecode decodes username and password portions of HTTP Basic Authentication
50// from encoded content.

Callers 2

ToUTF8WithErrFunction · 0.92
NewDiffFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected