diff options
Diffstat (limited to 'source/base/base_string.c')
| -rw-r--r-- | source/base/base_string.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/source/base/base_string.c b/source/base/base_string.c new file mode 100644 index 0000000..cb2d71d --- /dev/null +++ b/source/base/base_string.c | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | internal umm | ||
| 2 | skip_whitespaces(string *buffer) | ||
| 3 | { | ||
| 4 | s32 index = 0; | ||
| 5 | while (buffer->size > index) | ||
| 6 | { | ||
| 7 | ++index; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | internal b8 | ||
| 12 | compare_string_struct(string c1, string c2) | ||
| 13 | { | ||
| 14 | if (c1.size != c2.size) | ||
| 15 | { | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | |||
| 19 | for (s32 index = 0; | ||
| 20 | index < c1.size; | ||
| 21 | ++index) | ||
| 22 | { | ||
| 23 | if (c1.Data[index] != c2.Data[index]) | ||
| 24 | { | ||
| 25 | return -1; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | return 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | internal b8 | ||
| 33 | compare_string(char *c1, char *c2) | ||
| 34 | { | ||
| 35 | if (sizeof(*c1) != sizeof(*c2)) | ||
| 36 | { | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | |||
| 40 | for ( | ||
| 41 | u64 word_idx = 0; | ||
| 42 | word_idx <= sizeof(*c1); | ||
| 43 | ++word_idx) | ||
| 44 | { | ||
| 45 | if (*c1 != *c2) | ||
| 46 | { | ||
| 47 | return -1; | ||
| 48 | } | ||
| 49 | ++c1; | ||
| 50 | ++c2; | ||
| 51 | } | ||
| 52 | |||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** NOTE(nasr): Helper function to parse strings to int using ascii codes **/ | ||
| 57 | internal u64 | ||
| 58 | parse_u64(char *buf, umm len) | ||
| 59 | { | ||
| 60 | u64 value = 0; | ||
| 61 | |||
| 62 | for (umm buffer_idx = 0; buffer_idx < len; ++buffer_idx) | ||
| 63 | { | ||
| 64 | char c = buf[buffer_idx]; | ||
| 65 | if (c < '0' || c > '9') | ||
| 66 | { | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | value = value * 10 + (c - '0'); | ||
| 70 | } | ||
| 71 | |||
| 72 | return value; | ||
| 73 | } | ||
