From 031b0cc53493249be6cb421c65d089e1ce0a06f2 Mon Sep 17 00:00:00 2001 From: Walther Chen Date: Tue, 5 Dec 2023 16:09:09 -0500 Subject: [PATCH] fix strings.last_index_any for single char --- core/strings/strings.odin | 3 ++- tests/core/strings/test_core_strings.odin | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 539829a1a..5cee25a66 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1792,7 +1792,8 @@ last_index_any :: proc(s, chars: string) -> (res: int) { if r >= utf8.RUNE_SELF { r = utf8.RUNE_ERROR } - return index_rune(chars, r) + i := index_rune(chars, r) + return i if i < 0 else 0 } if len(s) > 8 { diff --git a/tests/core/strings/test_core_strings.odin b/tests/core/strings/test_core_strings.odin index fdaf3af28..3424675b3 100644 --- a/tests/core/strings/test_core_strings.odin +++ b/tests/core/strings/test_core_strings.odin @@ -67,6 +67,18 @@ test_index_any_larger_string_found :: proc(t: ^testing.T) { expect(t, index == 8, "index_any should be 8") } +@test +test_last_index_any_small_string_found :: proc(t: ^testing.T) { + index := strings.last_index_any(".", "/:.\"") + expect(t, index == 0, "last_index_any should be 0") +} + +@test +test_last_index_any_small_string_not_found :: proc(t: ^testing.T) { + index := strings.last_index_any(".", "/:\"") + expect(t, index == -1, "last_index_any should be -1") +} + Cut_Test :: struct { input: string, offset: int,