From 5e45c34f211b826c8b15c7ac21e81afa6749fa83 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 6 Jun 2025 15:30:38 +0200 Subject: [PATCH] - Deprecate `String.is_zstr` and `String.quick_zstr` #2188. --- lib/std/core/string.c3 | 5 ++--- releasenotes.md | 1 + test/unit/stdlib/core/string.c3 | 13 ------------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 89dfd0bc7..5345fddd6 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -807,7 +807,7 @@ fn usz String.utf8_codepoints(s) This function can safely be used with data pointing to null. However, it will not work correctly if the pointer is invalid, for example it is already freed. *> -fn bool String.is_zstr(self) +fn bool String.is_zstr(self) @deprecated("Unsafe, use copy instead") { return self.ptr && *(self.ptr + self.len) == 0; } @@ -828,9 +828,8 @@ fn bool String.is_zstr(self) @ensure return[self.len] == 0 *> -fn ZString String.quick_zstr(self) +fn ZString String.quick_zstr(self) @deprecated("Unsafe, use zstr_tcopy instead") { - if (self.is_zstr() @inline) return (ZString)self.ptr; return self.zstr_tcopy(); } diff --git a/releasenotes.md b/releasenotes.md index 05b2445f7..d9a7ce09f 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -21,6 +21,7 @@ - Fixes to `$define` handling of binary ops. ### Stdlib changes +- Deprecate `String.is_zstr` and `String.quick_zstr` #2188. ## 0.7.2 Change list diff --git a/test/unit/stdlib/core/string.c3 b/test/unit/stdlib/core/string.c3 index 245489917..cb043ebae 100644 --- a/test/unit/stdlib/core/string.c3 +++ b/test/unit/stdlib/core/string.c3 @@ -30,19 +30,6 @@ fn void test_count() assert(s2.count(" ") == 0); } -fn void quick_zstr() -{ - String str = "1234"; - ZString a = str.quick_zstr(); - ZString b = str[0..2].quick_zstr(); - ZString c = str[1..].quick_zstr(); - String empty = {}; - ZString d = empty.quick_zstr(); - assert((void*)a == str.ptr); - assert((void*)b != str.ptr); - assert((void*)c == &str[1]); - assert(d[0] == 0); -} fn void test_print_null() {