diff options
author | 3gg <3gg@shellblade.net> | 2022-05-07 08:27:30 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2022-05-07 08:27:30 -0700 |
commit | d52ef50957064da5dbfb76839e009c48ff2050c6 (patch) | |
tree | b7e5c0d2df05848bcf8100ecff010e0f9d35a6cf | |
parent | 344960f7470d7b6e5cb0c0b1d7e751d47063a98c (diff) |
Add string comparison.
-rw-r--r-- | cstring/include/cstring.h | 12 |
1 files changed, 12 insertions, 0 deletions
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 @@ | |||
3 | 3 | ||
4 | #include <assert.h> | 4 | #include <assert.h> |
5 | #include <bsd/string.h> | 5 | #include <bsd/string.h> |
6 | #include <stdbool.h> | ||
6 | 7 | ||
7 | /// A fixed-size string. | 8 | /// A fixed-size string. |
8 | /// The string is null-terminated so that it can be used with the usual C APIs. | 9 | /// The string is null-terminated so that it can be used with the usual C APIs. |
@@ -56,6 +57,17 @@ | |||
56 | \ | 57 | \ |
57 | static inline STRING STRING##_concat_path(STRING a, STRING b) { \ | 58 | static inline STRING STRING##_concat_path(STRING a, STRING b) { \ |
58 | return STRING##_concat(STRING##_concat(a, STRING##_make("/")), b); \ | 59 | return STRING##_concat(STRING##_concat(a, STRING##_make("/")), b); \ |
60 | } \ | ||
61 | \ | ||
62 | static inline bool STRING##_eq(STRING a, STRING b) { \ | ||
63 | if (a.length != b.length) { \ | ||
64 | return false; \ | ||
65 | } \ | ||
66 | return strncmp(a.str, b.str, a.length) == 0; \ | ||
67 | } \ | ||
68 | \ | ||
69 | static inline bool STRING##_eq_cstr(STRING a, const char* b) { \ | ||
70 | return strncmp(a.str, b, a.length) == 0; \ | ||
59 | } | 71 | } |
60 | 72 | ||
61 | DEF_STRING(sstring, 32) // Small. | 73 | DEF_STRING(sstring, 32) // Small. |