diff options
Diffstat (limited to 'source/base/base_string.h')
| -rw-r--r-- | source/base/base_string.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/source/base/base_string.h b/source/base/base_string.h new file mode 100644 index 0000000..c4b9f94 --- /dev/null +++ b/source/base/base_string.h | |||
| @@ -0,0 +1,78 @@ | |||
| 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 | typedef struct string16 string16; | ||
| 20 | struct string16 | ||
| 21 | { | ||
| 22 | u16 *data; | ||
| 23 | u64 size; | ||
| 24 | }; | ||
| 25 | |||
| 26 | typedef struct string32 string32; | ||
| 27 | struct string32 | ||
| 28 | { | ||
| 29 | u32 *data; | ||
| 30 | u64 size; | ||
| 31 | }; | ||
| 32 | |||
| 33 | //- string linked list implementation | ||
| 34 | typedef struct string8_node string8_node; | ||
| 35 | struct string8_node | ||
| 36 | { | ||
| 37 | string8 *next; | ||
| 38 | string8 string; | ||
| 39 | }; | ||
| 40 | |||
| 41 | typedef struct string8_list string8_list; | ||
| 42 | struct string8_list | ||
| 43 | { | ||
| 44 | string8 *first; | ||
| 45 | string8 *last; | ||
| 46 | u64 count; | ||
| 47 | }; | ||
| 48 | |||
| 49 | typedef struct string16_list string16_list; | ||
| 50 | struct string16_list | ||
| 51 | { | ||
| 52 | string16 *next; | ||
| 53 | string16 string; | ||
| 54 | }; | ||
| 55 | |||
| 56 | typedef struct string32_list string32_list; | ||
| 57 | struct string32_list | ||
| 58 | { | ||
| 59 | string32 *first; | ||
| 60 | string32 *last; | ||
| 61 | u64 count; | ||
| 62 | }; | ||
| 63 | |||
| 64 | internal b8 | ||
| 65 | string8_cmp(string8 a, string8 b) | ||
| 66 | { | ||
| 67 | if (a.size != b.size) return 0; | ||
| 68 | return (b8)(memcmp(a.data, b.data, a.size) == 0); | ||
| 69 | } | ||
| 70 | |||
| 71 | internal void | ||
| 72 | string8_appendc(string8 *buf, u8 c) | ||
| 73 | { | ||
| 74 | buf->data[buf->size] = c; | ||
| 75 | buf->size += 1; | ||
| 76 | } | ||
| 77 | |||
| 78 | #endif /* BASE_STRING_H */ | ||
