refactor: append, build variable and type switch (#4940)

* refactor: append, build variable and type switch

* fix: remove redundant space.
This commit is contained in:
Bo-Yi Wu 2019-05-28 23:45:54 +08:00 committed by GitHub
parent 31557b1274
commit 743697a549
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 46 deletions

View file

@ -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:])