Browse Source

Add string comparison.

main
3gg 7 months ago
parent
commit
d52ef50957
  1. 12
      cstring/include/cstring.h

12
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.

Loading…
Cancel
Save