Skip to content

Commit 02e8faa

Browse files
sharkdpDavid Peter
authored and
David Peter
committed
Fix str_replace implementation
1 parent d091acc commit 02e8faa

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

examples/prelude_tests.nbt

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ assert(str_contains("hello world", "HELLO") == false)
7070

7171
assert(str_replace("hello world", "hello", "HEY") == "HEY world")
7272
assert(str_replace("xxx", "x", "yY") == "yYyYyY")
73+
assert(str_replace("a b", " ", " ") == "a b")
7374

7475
assert(str_repeat("xy", 3) == "xyxyxy")
7576

numbat/modules/core/strings.nbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn str_replace(s: String, pattern: String, replacement: String) -> String =
2424
then s
2525
else if str_contains(s, pattern)
2626
then if str_slice(s, 0, str_length(pattern)) == pattern
27-
then str_replace(str_append(replacement, str_slice(s, str_length(pattern), str_length(s))), pattern, replacement)
27+
then str_append(replacement, str_replace(str_slice(s, str_length(pattern), str_length(s)), pattern, replacement))
2828
else str_append(str_slice(s, 0, 1), str_replace(str_slice(s, 1, str_length(s)), pattern, replacement))
2929
else s
3030

0 commit comments

Comments
 (0)