strutils.multiReplace: Making order of replacement explicit (#23022)

In the docs for strutils.multiReplace:

Making it more explicit that left to right comes before the order in the
replacements arg (but that the latter matters too).

E.g.

```
echo "ab".multiReplace(@[("a", "1"), ("ax", "2")])
echo "ab".multiReplace(@[("ab", "2"), ("a", "1")])
```

gives

```
1b
2
```

resolves #23016
This commit is contained in:
Joachim Hereth
2023-12-02 22:41:53 +01:00
committed by GitHub
parent a25843cf80
commit d5780a3e4e

View File

@@ -2290,8 +2290,9 @@ func multiReplace*(s: string, replacements: varargs[(string, string)]): string =
## If the resulting string is not longer than the original input string,
## only a single memory allocation is required.
##
## The order of the replacements does matter. Earlier replacements are
## preferred over later replacements in the argument list.
## Replacements are done left to right in the string. If at a given position
## multiple replacements match, earlier replacements are preferred over
## later replacements in the argument list.
result = newStringOfCap(s.len)
var i = 0
var fastChk: set[char] = {}