Ascii trim

This commit is contained in:
2026-07-27 19:45:00 +02:00
parent 8534075307
commit bd008c51fe
4 changed files with 116 additions and 11 deletions
+32 -4
View File
@@ -416,7 +416,7 @@ void string_test_1(void)
{
TRACEF("\n");
Str str1 = S_("Hello");
Str str1 = S("Hello");
printf("str1: %.*s len %d\n", str1.len, str1.str, str1.len);
U64 str1_index_of_l = str_find_byte(str1, 'l');
U64 str1_index_of_g = str_find_byte(str1, 'g');
@@ -424,7 +424,7 @@ void string_test_1(void)
MARENA_DEFINE(arena, 512, 1);
Allocator alloc = marena_allocator(&arena);
Str str2 = str_dup(&alloc, S_(" World"));
Str str2 = str_dup(&alloc, S(" World"));
Str str3 = str_concat(&alloc, str1, str2);
printf("str3: %.*s len %d\n", str3.len, str3.str, str3.len);
}
@@ -433,8 +433,8 @@ void string_split_test_1(void)
{
TRACEF("\n");
Str str1 = S_("a:bb|ccc");
Str sep = S_("|:");
Str str1 = S("a:bb|ccc");
Str sep = S("|:");
STRVEC_DEFINE(strings, 16);
str_split(str1, sep, &strings);
@@ -443,7 +443,34 @@ void string_split_test_1(void)
printf("split %u: '%.*s'\n", i, str->len, str->str);
}
}
void string_test_misc(void)
{
TRACEF("\n");
Str str1 = S("Hello World");
bool prefix1 = str_starts_with(str1, S("He"));
bool prefix2 = str_starts_with(str1, S(""));
bool prefix3 = str_starts_with(str1, S("false"));
bool suffix1 = str_ends_with(str1, S("orld"));
bool suffix2 = str_ends_with(str1, S(""));
bool suffix3 = str_ends_with(str1, S("false"));
printf("matches: %d %d %d %d %d %d\n", prefix1, prefix2, prefix3, suffix1, suffix2, suffix3);
Str str2 = S(" Hello World\t \n");
Str str2_trim = str_ascii_trim(str2);
printf("str2_trim: '%.*s'\n", str2_trim.len, str2_trim.str);
printf("str2_trim == str1: %d\n", str_eq(str1, str2_trim));
Str str3 = str_empty();
Str str3_trim = str_ascii_trim(str3);
printf("str3_trim: '%.*s'\n", str3_trim.len, str3_trim.str);
Str str4 = S(" \t\t ");
Str str4_trim = str_ascii_trim(str4);
printf("str4_trim: '%.*s'\n", str4_trim.len, str4_trim.str);
}
int main(int argc, char *argv[])
{
arena_test_1();
@@ -458,6 +485,7 @@ int main(int argc, char *argv[])
apool_test_miniarena();
string_test_1();
string_split_test_1();
string_test_misc();
}