R=gri
CC=golang-dev
https://golang.org/cl/2763041
This commit is contained in:
Russ Cox 2010-10-26 21:52:54 -07:00
parent e48c0fb562
commit d86ab015f7
45 changed files with 68 additions and 199 deletions

View file

@ -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
}