From 9d09d66a273f68fae7efb71504bf40c664b91983 Mon Sep 17 00:00:00 2001 From: nasr Date: Mon, 13 Apr 2026 15:33:05 +0200 Subject: feature(main): init feature(main): init feature(main): init feature(main): init --- source/base/base_string.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 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..29ccf1e --- /dev/null +++ b/source/base/base_string.h @@ -0,0 +1,53 @@ +#ifndef BASE_STRING_H +#define BASE_STRING_H + +#define PushString(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } +#define StringCast(data, size) (string8){(u8 *)(data), (u64)(size) } +#define StringPCast(data, size) (string8 *){(u8 *)(data), (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