From d5780a3e4ee9f2275a5253c55525ce5ead89efb2 Mon Sep 17 00:00:00 2001 From: Joachim Hereth <7327644+jhereth@users.noreply.github.com> Date: Sat, 2 Dec 2023 22:41:53 +0100 Subject: [PATCH] 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 --- lib/pure/strutils.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 6d79259412..479acc0753 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -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] = {}