More string stuff
This commit is contained in:
+35
@@ -3,6 +3,7 @@
|
||||
#include "mini_arena.h"
|
||||
#include "platform.h"
|
||||
#include "pool.h"
|
||||
#include "string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -411,6 +412,38 @@ void apool_test_autogrow(void)
|
||||
|
||||
}
|
||||
|
||||
void string_test_1(void)
|
||||
{
|
||||
TRACEF("\n");
|
||||
|
||||
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');
|
||||
printf("str1: index of l %ld, index of g: %ld\n", str1_index_of_l, str1_index_of_g);
|
||||
|
||||
MARENA_DEFINE(arena, 512, 1);
|
||||
Allocator alloc = marena_allocator(&arena);
|
||||
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);
|
||||
}
|
||||
|
||||
void string_split_test_1(void)
|
||||
{
|
||||
TRACEF("\n");
|
||||
|
||||
Str str1 = S_("a:bb|ccc");
|
||||
Str sep = S_("|:");
|
||||
STRVEC_DEFINE(strings, 16);
|
||||
|
||||
str_split(str1, sep, &strings);
|
||||
for (U32 i = 0; i < strings.len; i++) {
|
||||
Str *str = &strings.strings[i];
|
||||
printf("split %u: '%.*s'\n", i, str->len, str->str);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
arena_test_1();
|
||||
@@ -423,6 +456,8 @@ int main(int argc, char *argv[])
|
||||
apool_test();
|
||||
apool_test_autogrow();
|
||||
apool_test_miniarena();
|
||||
string_test_1();
|
||||
string_split_test_1();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user