diff options
| author | nasr <nsrddyn@gmail.com> | 2026-04-16 17:10:02 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-16 17:10:02 +0200 |
| commit | 8ea6a3c8621287d11296b8300029f32a27743d9a (patch) | |
| tree | cd12aa5fcd3e058fa74b45705c7b82524658d444 /source/base/base_string.h | |
| parent | f430bfe8f71430032bec689bf0bbdc94ac409c22 (diff) | |
feature(checkpoint): checkpoint cleaning up base library
Diffstat (limited to 'source/base/base_string.h')
| -rw-r--r-- | source/base/base_string.h | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/source/base/base_string.h b/source/base/base_string.h index d879450..eb51e65 100644 --- a/source/base/base_string.h +++ b/source/base/base_string.h | |||
| @@ -1,17 +1,84 @@ | |||
| 1 | #ifndef BASE_STRING_H | 1 | #ifndef BASE_STRING_H |
| 2 | #define BASE_STRING_H | 2 | #define BASE_STRING_H |
| 3 | 3 | ||
| 4 | // let's use this for strings | 4 | #define PushString8(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } |
| 5 | // to better differentiate between stuff | 5 | #define PushString16(arena, count) (string16){ .data = (PushArrayZero(arena, u16, (count))), .size = (count) } |
| 6 | typedef u8 s8; | 6 | #define PushString32(arena, count) (string32){ .data = (PushArrayZero(arena, u32, (count))), .size = (count) } |
| 7 | typedef struct string string ; | ||
| 8 | 7 | ||
| 9 | struct string | 8 | #define String8(data, size) (string8){(u8 *)(data), (u64)(size) } |
| 9 | #define String16(data, size) (string16){(u16 *)(data), (u64)(size) } | ||
| 10 | #define String32(data, size) (string32){(u32 *)(data), (u64)(size) } | ||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | #define StringFmt "%.*s" | ||
| 15 | #define ULongFmt "%lu" | ||
| 16 | #define ULLongFmt "%llu" | ||
| 17 | |||
| 18 | typedef struct string8 string8; | ||
| 19 | struct string8 | ||
| 20 | { | ||
| 21 | u8 *data; | ||
| 22 | u64 size; | ||
| 23 | }; | ||
| 24 | |||
| 25 | typedef struct string16 string16; | ||
| 26 | struct string16 | ||
| 27 | { | ||
| 28 | u16 *data; | ||
| 29 | u64 size; | ||
| 30 | }; | ||
| 31 | |||
| 32 | typedef struct string32 string32; | ||
| 33 | struct string32 | ||
| 34 | { | ||
| 35 | u32 *data; | ||
| 36 | u64 size; | ||
| 37 | }; | ||
| 38 | |||
| 39 | //- string linked list implementation | ||
| 40 | typedef struct string8_node string8_node; | ||
| 41 | struct string8_node | ||
| 10 | { | 42 | { |
| 11 | s8 *data; | 43 | string8 *next; |
| 12 | umm size; | 44 | string8 string; |
| 13 | }; | 45 | }; |
| 14 | 46 | ||
| 15 | // TODO(nasr): helper functions for string | 47 | typedef struct string8_list string8_list; |
| 48 | struct string8_list | ||
| 49 | { | ||
| 50 | string8 *first; | ||
| 51 | string8 *last; | ||
| 52 | u64 count; | ||
| 53 | }; | ||
| 54 | |||
| 55 | typedef struct string16_list string16_list; | ||
| 56 | struct string16_list | ||
| 57 | { | ||
| 58 | string16 *next; | ||
| 59 | string16 string; | ||
| 60 | }; | ||
| 61 | |||
| 62 | typedef struct string32_list string32_list; | ||
| 63 | struct string32_list | ||
| 64 | { | ||
| 65 | string32 *first; | ||
| 66 | string32 *last; | ||
| 67 | u64 count; | ||
| 68 | }; | ||
| 69 | |||
| 70 | internal b8 | ||
| 71 | string8_cmp(string8 a, string8 b) | ||
| 72 | { | ||
| 73 | if (a.size != b.size) return 0; | ||
| 74 | return (b8)(memcmp(a.data, b.data, a.size) == 0); | ||
| 75 | } | ||
| 76 | |||
| 77 | internal void | ||
| 78 | string8_appendc(string8 *buf, u8 c) | ||
| 79 | { | ||
| 80 | buf->data[buf->size] = c; | ||
| 81 | buf->size += 1; | ||
| 82 | } | ||
| 16 | 83 | ||
| 17 | #endif /* BASE_STRING_H */ | 84 | #endif /* BASE_STRING_H */ |
