Add str_join

This commit is contained in:
2026-07-31 00:27:04 +02:00
parent a94640e71d
commit 7f2713eeff
4 changed files with 93 additions and 8 deletions
+29
View File
@@ -470,7 +470,35 @@ void string_test_misc(void)
Str str4_trim = str_ascii_trim(str4);
printf("str4_trim: '%.*s'\n", str4_trim.len, str4_trim.str);
S64 found = str_substr(str1, S("World"));
printf("1. found %ld\n", found);
found = str_substr(str_empty(), S("World"));
printf("2. found %ld\n", found);
found = str_substr(str_empty(), S(""));
printf("3. found %ld\n", found);
found = str_substr(str1, S(" "));
printf("4. found %ld\n", found);
}
void string_test_join(void)
{
TRACEF("\n");
Arena arena;
arena_init(&arena, &ArenaOptions_Default);
Allocator allocator = arena_allocator(&arena);
Str strs[3] = {S("1"), S("two"), S("3-3")};
StrVec vec = STRVEC_STATIC_INITIALIZER(strs);
Str str = str_join(&allocator, vec, S("/"));
printf("str_join 1 '%.*s'\n", str.len, str.str);
str = str_join(&allocator, vec, S(""));
printf("str_join 2 '%.*s'\n", str.len, str.str);
vec.len = 0;
str = str_join(&allocator, vec, S("/"));
printf("str_join 2 '%.*s'\n", str.len, str.str);
}
int main(int argc, char *argv[])
{
arena_test_1();
@@ -486,6 +514,7 @@ int main(int argc, char *argv[])
string_test_1();
string_split_test_1();
string_test_misc();
string_test_join();
}