62#define str_strip_prefix(IT, PREFIX) _Generic((PREFIX),\
63 str : str_strip_prefix_str,\
64 char * : str_strip_prefix_cstr,\
65 bool (*)(char c): str_strip_prefix_if\
78#define str_strip_postfix(IT, POSTFIX) _Generic((POSTFIX),\
79 str : str_strip_postfix_str,\
80 char * : str_strip_postfix_cstr,\
81 bool (*)(char c): str_strip_postfix_if\
99#define cstr_cmp_cstr strcmp
102#define str_cmp(LHS, RHS) _Generic((LHS),\
103 str : _Generic((RHS),\
105 char *: str_cmp_cstr\
107 char *: _Generic((RHS),\
126#define str_eq(LHS, RHS) _Generic((LHS),\
127 str : _Generic((RHS),\
131 char *: _Generic((RHS),\
133 char *: cstr_eq_cstr\
150#define str_eq_any(LHS, COUNT, RHS, ...) _Generic((LHS),\
151 str : _Generic((RHS),\
152 str : str_eq_str_any,\
153 char *: str_eq_cstr_any\
155 char *: _Generic((RHS),\
156 str : cstr_eq_str_any,\
157 char *: cstr_eq_cstr_any\
159)((LHS), (COUNT), (RHS) __VA_OPT(, __VA_ARGS__))
bool cstr_eq_cstr_any(const char *it, size_t count,...)
Compares a string to several others to see if its contents are equal to any of them.
Definition str.c:151
bool str_eq_cstr_any(str it, size_t count,...)
Compares a string to several others to see if its contents are equal to any of them.
Definition str.c:127
bool str_eq_cstr(str a, const char *b)
Compares two strings to see if their contents are equal.
Definition str.c:104
str str_strip_prefix_if(str it, bool(*predicate)(char c))
Returns a non-owning copy of a str with all leading characters satisfying predicate removed.
Definition str.c:56
str str_strip_prefix_cstr(str it, const char *prefix)
Returns a non-owning copy of a str with a given prefix removed, if it is present.
Definition str.c:48
bool cstr_eq_str(const char *a, str b)
Compares two strings to see if their contents are equal.
Definition str.c:109
str str_strip_whitespace(str it)
Returns a non-owning copy of a str with all leading and trailing whitespace removed.
Definition str.c:25
str str_strip_postfix_str(str it, str postfix)
Returns a non-owning copy of a str with a given postfix removed, if it is present.
Definition str.c:61
int str_cmp_str(str a, str b)
Compares two strings lexicographically.
Definition str.c:81
bool str_eq_str(str a, str b)
Compares two strings to see if their contents are equal.
Definition str.c:100
bool cstr_eq_str_any(const char *it, size_t count,...)
Compares a string to several others to see if its contents are equal to any of them.
Definition str.c:139
str str_strip_whitespace_pre(str it)
Returns a non-owning copy of a str with all leading whitespace removed.
Definition str.c:31
str str_strip_prefix_str(str it, str prefix)
Returns a non-owning copy of a str with a given prefix removed, if it is present.
Definition str.c:41
int str_cmp_cstr(str a, const char *b)
Compares two strings lexicographically.
Definition str.c:88
str str_strip_postfix_if(str it, bool(*predicate)(char c))
Returns a non-owning copy of a str with all trailing characters satisfying predicate removed.
Definition str.c:74
str str_strip_postfix_cstr(str it, const char *postfix)
Returns a non-owning copy of a str with a given postfix removed, if it is present.
Definition str.c:67
int cstr_cmp_str(const char *a, str b)
Compares two strings lexicographically.
Definition str.c:96
str str_from_cstr(char *sz)
Constructs a non-owning str from a null-terminated C-string.
Definition str.c:23
bool str_is_sz(str it)
Checks if a str is null-terminated.
Definition str.c:79
bool str_eq_str_any(str it, size_t count,...)
Compares a string to several others to see if its contents are equal to any of them.
Definition str.c:115
str str_strip_whitespace_post(str it)
Returns a non-owning copy of a str with all trailing whitespace removed.
Definition str.c:36
bool cstr_eq_cstr(const char *a, const char *b)
Compares two strings to see if their contents are equal.
Definition str.c:113
A string "slice", which is a pointer & length pair.
Definition str.h:30
char * data
Pointer to the start of the string.
Definition str.h:32
size_t len
The length of the string.
Definition str.h:37