diff options
| author | nasr <nsrddyn@gmail.com> | 2026-04-13 15:33:05 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-13 15:36:24 +0200 |
| commit | 9d09d66a273f68fae7efb71504bf40c664b91983 (patch) | |
| tree | 41a46c52a01338bf22d5f3ebdf0bb27dc3d33cc1 /source/base/base_string.h | |
feature(main): init
feature(main): init
feature(main): init
feature(main): init
Diffstat (limited to 'source/base/base_string.h')
| -rw-r--r-- | source/base/base_string.h | 53 |
1 files changed, 53 insertions, 0 deletions
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 @@ | |||
| 1 | #ifndef BASE_STRING_H | ||
| 2 | #define BASE_STRING_H | ||
| 3 | |||
| 4 | #define PushString(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } | ||
| 5 | #define StringCast(data, size) (string8){(u8 *)(data), (u64)(size) } | ||
| 6 | #define StringPCast(data, size) (string8 *){(u8 *)(data), (u64)(size) } | ||
| 7 | |||
| 8 | #define StringFmt "%.*s" | ||
| 9 | #define ULongFmt "%lu" | ||
| 10 | #define ULLongFmt "%llu" | ||
| 11 | |||
| 12 | typedef struct string8 string8; | ||
| 13 | struct string8 | ||
| 14 | { | ||
| 15 | u8 *data; | ||
| 16 | u64 size; | ||
| 17 | }; | ||
| 18 | |||
| 19 | internal b8 | ||
| 20 | string8_cmp(string8 a, string8 b) | ||
| 21 | { | ||
| 22 | if (a.size != b.size) return 0; | ||
| 23 | return (b8)(memcmp(a.data, b.data, a.size) == 0); | ||
| 24 | } | ||
| 25 | |||
| 26 | internal u64 | ||
| 27 | string8_to_u64(u8 *buf, umm len) | ||
| 28 | { | ||
| 29 | u64 value = 0; | ||
| 30 | for (umm i = 0; i < len; ++i) | ||
| 31 | { | ||
| 32 | u8 c = buf[i]; | ||
| 33 | if (c < '0' || c > '9') break; | ||
| 34 | value = value * 10 + (c - '0'); | ||
| 35 | } | ||
| 36 | return value; | ||
| 37 | } | ||
| 38 | |||
| 39 | internal void | ||
| 40 | string8_append_char(string8 *buf, u8 c) | ||
| 41 | { | ||
| 42 | buf->data[buf->size] = c; | ||
| 43 | buf->size += 1; | ||
| 44 | } | ||
| 45 | |||
| 46 | read_only global_variable | ||
| 47 | string8 nil_string = | ||
| 48 | { | ||
| 49 | .data = NULL, | ||
| 50 | .size = 0, | ||
| 51 | }; | ||
| 52 | |||
| 53 | #endif /* BASE_STRING_H */ | ||
