From dd5586abec207dd4acd16d51ce0d392c03e5e957 Mon Sep 17 00:00:00 2001 From: nasr Date: Thu, 26 Mar 2026 22:35:30 +0100 Subject: feature(main): init feature(main): init --- source/base/base_string.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 source/base/base_string.h (limited to 'source/base/base_string.h') diff --git a/source/base/base_string.h b/source/base/base_string.h new file mode 100644 index 0000000..189b38a --- /dev/null +++ b/source/base/base_string.h @@ -0,0 +1,59 @@ +#ifndef BASE_STRING_H +#define BASE_STRING_H + +#include + +#define StringLit(string) \ + (string8){ .data = (u8 *)(string), .size = (sizeof(string) - 1) } + + #define PushString(arena, size) \ + (string8){ (u8 *)PushArray((arena), u8, (size)), (u64)(size) } + +#define StringFmt "%.*s" +#define ULongFmt "%lu" +#define ULLongFmt "%llu" + +typedef struct string8 string8; +struct string8 +{ + u8 *data; + u64 size; +}; + +internal b8 +string8_cmp(string8 a, string8 b) +{ + if (a.size != b.size) return 0; + return (b8)(memcmp(a.data, b.data, a.size) == 0); +} + +internal u64 +string8_to_u64(u8 *buf, umm len) +{ + u64 value = 0; + for (umm i = 0; i < len; ++i) + { + u8 c = buf[i]; + if (c < '0' || c > '9') break; + value = value * 10 + (c - '0'); + } + return value; +} + +internal void +string8_append_char(string8 *buf, u8 c) +{ + buf->data[buf->size] = c; + buf->size += 1; +} + +read_only global_variable +string8 nil_string = +{ + + .data = NULL, + .size = 0, + +}; + +#endif /* BASE_STRING_H */ -- cgit v1.3