diff options
Diffstat (limited to 'source/base/base_string.c')
| -rw-r--r-- | source/base/base_string.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/source/base/base_string.c b/source/base/base_string.c new file mode 100644 index 0000000..9d09914 --- /dev/null +++ b/source/base/base_string.c | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | internal b8 | ||
| 2 | compare_string(string c1, string c2) | ||
| 3 | { | ||
| 4 | if (c1.size != c2.size) | ||
| 5 | { | ||
| 6 | return 0; | ||
| 7 | } | ||
| 8 | |||
| 9 | for (u64 index = 0; index < c1.size; ++index) | ||
| 10 | { | ||
| 11 | if (c1.data[index] != c2.data[index]) | ||
| 12 | { | ||
| 13 | return 0; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | return 1; | ||
| 18 | } | ||
| 19 | |||
| 20 | internal b8 | ||
| 21 | compare_u8(u8 *c1, u8 *c2, u64 len) | ||
| 22 | { | ||
| 23 | if (sizeof(c1) != len || sizeof(c2) != len) | ||
| 24 | { | ||
| 25 | return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | if (sizeof(*c1) != sizeof(*c2)) | ||
| 29 | { | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | |||
| 33 | for (u64 word_idx = 0; word_idx <= sizeof(*c1); ++word_idx) | ||
| 34 | { | ||
| 35 | if (*c1 != *c2) | ||
| 36 | { | ||
| 37 | return 0; | ||
| 38 | } | ||
| 39 | |||
| 40 | ++c1; | ||
| 41 | ++c2; | ||
| 42 | } | ||
| 43 | |||
| 44 | return 1; | ||
| 45 | } | ||
| 46 | |||
| 47 | internal u64 | ||
| 48 | to_u64(u8 *buf, umm len) | ||
| 49 | { | ||
| 50 | u64 value = 0; | ||
| 51 | |||
| 52 | for (umm buffer_idx = 0; buffer_idx < len; ++buffer_idx) | ||
| 53 | { | ||
| 54 | u8 c = buf[buffer_idx]; | ||
| 55 | if (c < '0' || c > '9') | ||
| 56 | { | ||
| 57 | break; | ||
| 58 | } | ||
| 59 | value = value * 10 + (c - '0'); | ||
| 60 | } | ||
| 61 | |||
| 62 | return value; | ||
| 63 | } | ||
