summaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/str.c b/src/str.c
index 4f6d5c7..e14591d 100644
--- a/src/str.c
+++ b/src/str.c
@@ -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)