Skip to content

Commit

Permalink
strings: clarify Replacer's replacement order
Browse files Browse the repository at this point in the history
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 golang#25071

Change-Id: Icf3aa6a9d459b94764c9d577e4a76ad8c04d158d
Reviewed-on: https://go-review.googlesource.com/109375
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
ALTree authored and bradfitz committed Apr 26, 2018
1 parent bf6530a commit 2191c3a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/strings/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2191c3a

Please sign in to comment.