fix: strings.substring not returning end of range

This commit is contained in:
miningape
2026-02-28 00:26:59 +01:00
parent 6a6460e824
commit 4ec443df9b
2 changed files with 8 additions and 1 deletions

View File

@@ -3420,7 +3420,9 @@ internal_substring :: proc(s: string, rune_start: int, rune_end: int) -> (sub: s
}
rune_i += 1
}
if !ok { return }
if !ok {
sub = sub[rune_i:]
}
}
if rune_end >= rune_start {

View File

@@ -164,11 +164,16 @@ test_substring :: proc(t: ^testing.T) {
{s = "Hello", end = len("Hello"), sub = "Hello", ok = true},
{s = "Hello", start = 1, end = len("Hello"), sub = "ello", ok = true},
{s = "Hello", start = 1, end = len("Hello") - 1, sub = "ell", ok = true},
{s = "Hello", start = 0, end = 0, sub = "", ok = true},
{s = "Hello", start = 3, end = 3, sub = "", ok = true},
{s = "Hello", start = len("Hello"), end = len("Hello"), sub = "", ok = true},
{s = "Hello", end = len("Hello") + 1, sub = "Hello", ok = false},
{s = "小猫咪", start = 0, end = 3, sub = "小猫咪", ok = true},
{s = "小猫咪", start = 1, end = 3, sub = "猫咪", ok = true},
{s = "小猫咪", start = 1, end = 5, sub = "猫咪", ok = false},
{s = "小猫咪", start = 1, end = 1, sub = "", ok = true},
{s = "小猫咪", start = 1, end = 1, sub = "", ok = true},
{s = "小猫咪", start = 3, end = 3, sub = "", ok = true},
}
for tc in cases {