diff options
author | Bo-Yi Wu <appleboy.tw@gmail.com> | 2019-05-28 23:45:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 23:45:54 +0800 |
commit | 743697a549bda16508ab961ac79a8bc5bdca3bbd (patch) | |
tree | 23d40a210acd7b84dd62f6c5ec73dfea938faa5f /modules/templates | |
parent | 31557b12744410633ceb6fc12b53fb09038cee35 (diff) | |
download | gitea-743697a549bda16508ab961ac79a8bc5bdca3bbd.tar.gz gitea-743697a549bda16508ab961ac79a8bc5bdca3bbd.zip |
refactor: append, build variable and type switch (#4940)
* refactor: append, build variable and type switch
* fix: remove redundant space.
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 098a642556..ef4a68add0 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -156,8 +156,7 @@ func NewFuncMap() []template.FuncMap { var path []string index := strings.LastIndex(str, "/") if index != -1 && index != len(str) { - path = append(path, str[0:index+1]) - path = append(path, str[index+1:]) + path = append(path, str[0:index+1], str[index+1:]) } else { path = append(path, str) } @@ -330,10 +329,10 @@ func ToUTF8(content string) string { return res } -// ReplaceLeft replaces all prefixes 'old' in 's' with 'new'. -func ReplaceLeft(s, old, new string) string { - oldLen, newLen, i, n := len(old), len(new), 0, 0 - for ; i < len(s) && strings.HasPrefix(s[i:], old); n++ { +// ReplaceLeft replaces all prefixes 'oldS' in 's' with 'newS'. +func ReplaceLeft(s, oldS, newS string) string { + oldLen, newLen, i, n := len(oldS), len(newS), 0, 0 + for ; i < len(s) && strings.HasPrefix(s[i:], oldS); n++ { i += oldLen } @@ -348,7 +347,7 @@ func ReplaceLeft(s, old, new string) string { j := 0 for ; j < n*newLen; j += newLen { - copy(replacement[j:j+newLen], new) + copy(replacement[j:j+newLen], newS) } copy(replacement[j:], s[i:]) |