Fix string function behavior with NUL characters (#1746)

This commit is contained in:
Rangi
2025-07-14 21:43:32 -04:00
committed by GitHub
parent 0149122cd0
commit 8a19c5c30a
3 changed files with 54 additions and 21 deletions

View File

@@ -0,0 +1,33 @@
def s equs "hello\0world"
println #s
MACRO assert_equal
assert !strcmp(\1, \2)
ENDM
assert strlen(#s) == 11
assert strfind(#s, "o\0w") == 4
assert strfind(#s, "orld") == 7
assert strrfind(#s, "o\0w") == 4
assert strrfind(#s, "o") == 7
assert_equal strcat(#s, "\0lol"), "hello\0world\0lol"
assert_equal #s ++ "\0lol", "hello\0world\0lol"
assert_equal strupr(#s), "HELLO\0WORLD"
assert_equal strlwr("HELLO\0WORLD"), #s
assert_equal strslice(#s, 4, 7), "o\0w"
assert_equal strslice(#s, 6), "world"
assert_equal strrpl(#s, "o", "XX"), "hellXX\0wXXrld"
assert_equal strrpl(#s, "\0", "0"), "hello0world"
assert_equal strfmt("%s", #s), #s
assert_equal strchar(#s, 5), "\0"
assert_equal strchar(#s, -1), "d"
assert strin(#s, "o\0w") == 5
assert strin(#s, "orld") == 8
assert strrin(#s, "o\0w") == 5
assert strrin(#s, "o") == 8
assert_equal strsub(#s, 5, 3), "o\0w"
assert_equal strsub(#s, 7), "world"

Binary file not shown.