diff options
author | Emrah URHAN <raxetul@gmail.com> | 2015-11-22 19:40:18 +0200 |
---|---|---|
committer | Emrah URHAN <raxetul@gmail.com> | 2015-11-22 19:40:18 +0200 |
commit | 737da1a3748d7c82af771d3ba4aa4c76ba219eee (patch) | |
tree | b59104944ba28771752adcc1231a847b6704ac4d /modules/base/tool.go | |
parent | f63a468dfce812423b78a47cfa2583c5ad2faa49 (diff) | |
parent | efaf60ba5a4a7c0954dbaf57203859db3258281f (diff) |
Latest develop updates is merged with my RaspberryPi Dockerfile version.
Merge branch 'develop' of https://github.com/gogits/gogs into develop
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r-- | modules/base/tool.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go index b9a97c9c..78983b36 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -23,6 +23,8 @@ import ( "github.com/Unknwon/i18n" "github.com/microcosm-cc/bluemonday" + "github.com/gogits/chardet" + "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/setting" ) @@ -43,6 +45,22 @@ func EncodeSha1(str string) string { return hex.EncodeToString(h.Sum(nil)) } +func ShortSha(sha1 string) string { + if len(sha1) == 40 { + return sha1[:10] + } + return sha1 +} + +func DetectEncoding(content []byte) (string, error) { + detector := chardet.NewTextDetector() + result, err := detector.DetectBest(content) + if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 { + return setting.Repository.AnsiCharset, err + } + return result.Charset, err +} + func BasicAuthDecode(encoded string) (string, string, error) { s, err := base64.StdEncoding.DecodeString(encoded) if err != nil { |