diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 17a3ffe..33753fc 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -1,3 +1,7 @@ +27-04-2024 René Huiberts + + Added: ASCII string api + 27-04-2024 René Huiberts Added: project layout diff --git a/src/string.c b/src/string.c new file mode 100644 index 0000000..ca9e06e --- /dev/null +++ b/src/string.c @@ -0,0 +1,20 @@ +internal String8 +str8_initialize(u8 *cstring, u64 length) +{ + String8 result = { cstring, length }; + return result; +} + +internal String8 +str8_range(u8 *first, u8 *opl) { + String8 result = { first, (u64)(opl - first) }; + return result; +} + +internal String8 +str8_from_cstring(u8 *cstring) { + u8 *ptr = cstring; + for (;*ptr != 0; ptr += 1); + String8 result = str8_range(cstring, ptr); + return result; +} diff --git a/src/string.h b/src/string.h new file mode 100644 index 0000000..a336377 --- /dev/null +++ b/src/string.h @@ -0,0 +1,23 @@ +#ifndef STRING_H +#define STRING_H 1 + +typedef struct String8 String8; +struct String8 +{ + u8 *str; + u64 length; +}; + +internal String8 str8_initialize(u8 *cstring, u64 length); +#define str8_lit(cstring) \ + str8_initialize((u8*)(cstring), sizeof(cstring) - 1) + +#define str8_lit_comp(cstring) \ + {(u8*)(cstring), sizeof(cstring) - 1} + +//= rhjr: helper macros + +#define print_str8(str8) \ + printf("%.*s\n", (i32) str8.length, str8.str) + +#endif // STRING_H