]> Cypherpunks repositories - gostls13.git/commitdiff
strings: clarify Replacer's replacement order
authorAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 25 Apr 2018 18:48:01 +0000 (20:48 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 26 Apr 2018 15:11:58 +0000 (15:11 +0000)
NewReplacer's documentation says that "replacements are performed in
order", meaning that substrings are replaced in the order they appear
in the target string, and not that the old->new replacements are
applied in the order they're passed to NewReplacer.

Rephrase the doc to make this clearer.

Fixes #25071

Change-Id: Icf3aa6a9d459b94764c9d577e4a76ad8c04d158d
Reviewed-on: https://go-review.googlesource.com/109375
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/strings/replace.go

index bb0524427b3c51477ad4e0664ec139ec09fffb7b..58a11a63dbeb486c4084762be656f2daa0a0b226 100644 (file)
@@ -18,8 +18,9 @@ type replacer interface {
        WriteString(w io.Writer, s string) (n int, err error)
 }
 
-// NewReplacer returns a new Replacer from a list of old, new string pairs.
-// Replacements are performed in order, without overlapping matches.
+// NewReplacer returns a new Replacer from a list of old, new string
+// pairs. Replacements are performed in the order they appear in the
+// target string, without overlapping matches.
 func NewReplacer(oldnew ...string) *Replacer {
        if len(oldnew)%2 == 1 {
                panic("strings.NewReplacer: odd argument count")