diff options
Diffstat (limited to 'src/str.c')
-rw-r--r-- | src/str.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -6,12 +6,24 @@ #include <string.h> #include "str.h" -int str_cmp(str s1, str s2) +bool str_eq(str s1, str s2) { if (s1.len != s2.len) - return (int) s1.len - (int) s2.len; + return false; + + return memcmp(s1.data, s2.data, s1.len) == 0; +} + - return memcmp(s1.data, s2.data, s1.len); +int str_cmp(str s1, str s2) +{ + size_t min_len = s1.len < s2.len ? s1.len : s2.len; + int cmp = memcmp(s1.data, s2.data, min_len); + + if (cmp == 0) + return (int) s1.len - (int) s2.len; + else + return cmp; } static bool match_char(char c, str tokens) |