summaryrefslogtreecommitdiff
path: root/source/base/base_string.h
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-04-17 17:49:10 +0200
committernasr <nsrddyn@gmail.com>2026-04-17 17:50:28 +0200
commit078e21a1feb811f9ef7797ce3ee5d2e8ffcccfce (patch)
treec1121bed141fb536be6b21a6fc54ccd2b5ac7302 /source/base/base_string.h
parent9d09d66a273f68fae7efb71504bf40c664b91983 (diff)
feature(main): during my work on other projects I improved the base library a bit.
this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr <nsrddyn@gmail.com> feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr <nsrddyn@gmail.com>
Diffstat (limited to 'source/base/base_string.h')
-rw-r--r--source/base/base_string.h79
1 files changed, 55 insertions, 24 deletions
diff --git a/source/base/base_string.h b/source/base/base_string.h
index 29ccf1e..eb51e65 100644
--- a/source/base/base_string.h
+++ b/source/base/base_string.h
@@ -1,9 +1,15 @@
1#ifndef BASE_STRING_H 1#ifndef BASE_STRING_H
2#define BASE_STRING_H 2#define BASE_STRING_H
3 3
4#define PushString(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } 4#define PushString8(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) }
5#define StringCast(data, size) (string8){(u8 *)(data), (u64)(size) } 5#define PushString16(arena, count) (string16){ .data = (PushArrayZero(arena, u16, (count))), .size = (count) }
6#define StringPCast(data, size) (string8 *){(u8 *)(data), (u64)(size) } 6#define PushString32(arena, count) (string32){ .data = (PushArrayZero(arena, u32, (count))), .size = (count) }
7
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
7 13
8#define StringFmt "%.*s" 14#define StringFmt "%.*s"
9#define ULongFmt "%lu" 15#define ULongFmt "%lu"
@@ -16,6 +22,51 @@ struct string8
16 u64 size; 22 u64 size;
17}; 23};
18 24
25typedef struct string16 string16;
26struct string16
27{
28 u16 *data;
29 u64 size;
30};
31
32typedef struct string32 string32;
33struct string32
34{
35 u32 *data;
36 u64 size;
37};
38
39//- string linked list implementation
40typedef struct string8_node string8_node;
41struct string8_node
42{
43 string8 *next;
44 string8 string;
45};
46
47typedef struct string8_list string8_list;
48struct string8_list
49{
50 string8 *first;
51 string8 *last;
52 u64 count;
53};
54
55typedef struct string16_list string16_list;
56struct string16_list
57{
58 string16 *next;
59 string16 string;
60};
61
62typedef struct string32_list string32_list;
63struct string32_list
64{
65 string32 *first;
66 string32 *last;
67 u64 count;
68};
69
19internal b8 70internal b8
20string8_cmp(string8 a, string8 b) 71string8_cmp(string8 a, string8 b)
21{ 72{
@@ -23,31 +74,11 @@ string8_cmp(string8 a, string8 b)
23 return (b8)(memcmp(a.data, b.data, a.size) == 0); 74 return (b8)(memcmp(a.data, b.data, a.size) == 0);
24} 75}
25 76
26internal u64
27string8_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
39internal void 77internal void
40string8_append_char(string8 *buf, u8 c) 78string8_appendc(string8 *buf, u8 c)
41{ 79{
42 buf->data[buf->size] = c; 80 buf->data[buf->size] = c;
43 buf->size += 1; 81 buf->size += 1;
44} 82}
45 83
46read_only global_variable
47string8 nil_string =
48{
49 .data = NULL,
50 .size = 0,
51};
52
53#endif /* BASE_STRING_H */ 84#endif /* BASE_STRING_H */