mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
refactor: append, build variable and type switch (#4940)
* refactor: append, build variable and type switch * fix: remove redundant space.
This commit is contained in:
parent
31557b1274
commit
743697a549
8 changed files with 42 additions and 46 deletions
|
@ -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:])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue