diff options
author | Unknwon <u@gogs.io> | 2015-12-27 17:02:36 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-27 17:02:36 -0500 |
commit | 44637f03ccef3f005da41da5d1880df80cceebb2 (patch) | |
tree | 7cc21d72a5a08e0694d0c5571b378c63498fa39c /modules/base/tool.go | |
parent | 240fe07287564be8c31e412b68350060b4c049d4 (diff) | |
download | gitea-44637f03ccef3f005da41da5d1880df80cceebb2.tar.gz gitea-44637f03ccef3f005da41da5d1880df80cceebb2.zip |
#2282 fast detection of utf-8
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r-- | modules/base/tool.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go index 75f475fa4f..5927dad01c 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -18,6 +18,7 @@ import ( "regexp" "strings" "time" + "unicode/utf8" "github.com/Unknwon/com" "github.com/Unknwon/i18n" @@ -53,6 +54,11 @@ func ShortSha(sha1 string) string { } func DetectEncoding(content []byte) string { + if utf8.Valid(content[:1024]) { + log.Debug("Detected encoding: utf-8 (fast)") + return "utf-8" + } + _, name, certain := charset.DetermineEncoding(content, "") if name != "utf-8" && len(setting.Repository.AnsiCharset) > 0 { log.Debug("Using default AnsiCharset: %s", setting.Repository.AnsiCharset) |