mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
parent
e48c0fb562
commit
d86ab015f7
45 changed files with 68 additions and 199 deletions
|
|
@ -527,21 +527,10 @@ func Replace(s, old, new string, n int) string {
|
|||
} else {
|
||||
j += Index(s[start:], old)
|
||||
}
|
||||
w += copyString(t[w:], s[start:j])
|
||||
w += copyString(t[w:], new)
|
||||
w += copy(t[w:], s[start:j])
|
||||
w += copy(t[w:], new)
|
||||
start = j + len(old)
|
||||
}
|
||||
w += copyString(t[w:], s[start:])
|
||||
w += copy(t[w:], s[start:])
|
||||
return string(t[0:w])
|
||||
}
|
||||
|
||||
func copyString(dst []byte, src string) int {
|
||||
n := len(dst)
|
||||
if n > len(src) {
|
||||
n = len(src)
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
dst[i] = src[i]
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue