소스 검색

Fix str_replace implementation

David Peter 1 년 전
부모
커밋
02e8faa39a
2개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 0
      examples/prelude_tests.nbt
  2. 1 1
      numbat/modules/core/strings.nbt

+ 1 - 0
examples/prelude_tests.nbt

@@ -70,6 +70,7 @@ assert(str_contains("hello world", "HELLO") == false)
 
 assert(str_replace("hello world", "hello", "HEY") == "HEY world")
 assert(str_replace("xxx", "x", "yY") == "yYyYyY")
+assert(str_replace("a b", " ", "   ") == "a   b")
 
 assert(str_repeat("xy", 3) == "xyxyxy")
 

+ 1 - 1
numbat/modules/core/strings.nbt

@@ -24,7 +24,7 @@ fn str_replace(s: String, pattern: String, replacement: String) -> String =
     then s
     else if str_contains(s, pattern)
            then if str_slice(s, 0, str_length(pattern)) == pattern
-               then str_replace(str_append(replacement, str_slice(s, str_length(pattern), str_length(s))), pattern, replacement)
+               then str_append(replacement, str_replace(str_slice(s, str_length(pattern), str_length(s)), pattern, replacement))
                else str_append(str_slice(s, 0, 1), str_replace(str_slice(s, 1, str_length(s)), pattern, replacement))
            else s