From ab3edaa58eed4ff73410954ca094531d49eb5844 Mon Sep 17 00:00:00 2001 From: talha Date: Thu, 15 Feb 2024 09:58:42 +0500 Subject: added personal libraries to git tracking --- strings/strings.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 strings/strings.cpp (limited to 'strings/strings.cpp') diff --git a/strings/strings.cpp b/strings/strings.cpp new file mode 100644 index 0000000..4c8486f --- /dev/null +++ b/strings/strings.cpp @@ -0,0 +1,31 @@ +u64 CstrSize(const char* cstr) +{ + u8 *iter = (u8*)cstr; + u64 size = 0; + for(;*iter != 0; *iter++) { + size += 1; + } + + return size; +} + +struct str8 Str8(u8 *string, u64 size) +{ + struct str8 result = {string, size}; + return result; +} + +struct res_str8 Str8InitCstr(struct arena *a, const char* cstr) +{ + u64 cstr_size = CstrSize(cstr); + struct res_void cstr_res = arena_alloc(a, cstr_size); + u8 *str = (u8 *)cstr_res.memory; + u64 str_size = cstr_res.bytes_count; + + MemCopy((void*)str, (void*)cstr, str_size*sizeof(u8)); + + struct res_str8 result = {}; + result.string = Str8(str, str_size); + result.bytes_count = str_size; + return result; +} -- cgit v1.2.3