]> Cypherpunks repositories - gostls13.git/commitdiff
strings, bytes: document behavior of Replace when old is empty
authorCaleb Spare <cespare@gmail.com>
Mon, 25 Aug 2014 21:42:27 +0000 (14:42 -0700)
committerRob Pike <r@golang.org>
Mon, 25 Aug 2014 21:42:27 +0000 (14:42 -0700)
Fixes #8143.

LGTM=r
R=rsc, bradfitz, r
CC=golang-codereviews
https://golang.org/cl/135760043

src/pkg/bytes/bytes.go
src/pkg/strings/strings.go

index d8b6f998b3cba58dc2273750bce19c04cba53bcd..34c22bbfb1df12dafb5da95bbd88628341bfb6ca 100644 (file)
@@ -605,6 +605,9 @@ func Runes(s []byte) []rune {
 
 // Replace returns a copy of the slice s with the first n
 // non-overlapping instances of old replaced by new.
+// If old is empty, it matches at the beginning of the slice
+// and after each UTF-8 sequence, yielding up to k+1 replacements
+// for a k-rune slice.
 // If n < 0, there is no limit on the number of replacements.
 func Replace(s, old, new []byte, n int) []byte {
        m := 0
index 53bcd6b98a67c82ddf58b4aadb0902069a3eed42..5f19695d3ffb75b1700c1063f4ea3785190e1af9 100644 (file)
@@ -635,6 +635,9 @@ func TrimSuffix(s, suffix string) string {
 
 // Replace returns a copy of the string s with the first n
 // non-overlapping instances of old replaced by new.
+// If old is empty, it matches at the beginning of the string
+// and after each UTF-8 sequence, yielding up to k+1 replacements
+// for a k-rune string.
 // If n < 0, there is no limit on the number of replacements.
 func Replace(s, old, new string, n int) string {
        if old == new || n == 0 {