hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 50391ff7ab875019a6fdd575fd2d08db7e2aff4b
parent 73d1176378d969b58d91ad26a0551bae670474dc
Author: Christopher M. Riedl <cmr@bluescreens.de>
Date:   Fri, 25 Feb 2022 22:39:05 -0600

strings::replace: fix algorithm

Signed-off-by: Christopher M. Riedl <cmr@bluescreens.de>

Diffstat:
Mstrings/replace.ha | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/strings/replace.ha b/strings/replace.ha @@ -14,13 +14,13 @@ export fn replace(s: str, needle: str, target: str) str = { for (true) { match_idx = match(bytes::index(res[match_idx..], needle)) { case let s: size => - yield s - match_idx; + yield match_idx + s; case void => break; }; delete(res[match_idx..match_idx + len(needle)]); insert(res[match_idx], target...); - match_idx += len(needle); + match_idx += len(target); }; return fromutf8(res); };