From d52ef50957064da5dbfb76839e009c48ff2050c6 Mon Sep 17 00:00:00 2001
From: 3gg <3gg@shellblade.net>
Date: Sat, 7 May 2022 08:27:30 -0700
Subject: Add string comparison.

---
 cstring/include/cstring.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'cstring/include')

diff --git a/cstring/include/cstring.h b/cstring/include/cstring.h
index 644f1e1..ae650eb 100644
--- a/cstring/include/cstring.h
+++ b/cstring/include/cstring.h
@@ -3,6 +3,7 @@
 
 #include <assert.h>
 #include <bsd/string.h>
+#include <stdbool.h>
 
 /// A fixed-size string.
 /// The string is null-terminated so that it can be used with the usual C APIs.
@@ -56,6 +57,17 @@
                                                                                \
   static inline STRING STRING##_concat_path(STRING a, STRING b) {              \
     return STRING##_concat(STRING##_concat(a, STRING##_make("/")), b);         \
+  }                                                                            \
+                                                                               \
+  static inline bool STRING##_eq(STRING a, STRING b) {                         \
+    if (a.length != b.length) {                                                \
+      return false;                                                            \
+    }                                                                          \
+    return strncmp(a.str, b.str, a.length) == 0;                               \
+  }                                                                            \
+                                                                               \
+  static inline bool STRING##_eq_cstr(STRING a, const char* b) {               \
+    return strncmp(a.str, b, a.length) == 0;                                   \
   }
 
 DEF_STRING(sstring, 32)    // Small.
-- 
cgit v1.2.3