shared: add NM_IN_STRSET_ASCII_CASE() macro

This commit is contained in:
Thomas Haller 2020-07-30 19:14:24 +02:00
parent b16b42266d
commit 3b64d88a93
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 30 additions and 0 deletions

View file

@ -1233,6 +1233,16 @@ nm_strcmp_p (gconstpointer a, gconstpointer b)
/*****************************************************************************/
static inline int
_NM_IN_STRSET_ASCII_CASE_op_streq (const char *x, const char *s)
{
return s && g_ascii_strcasecmp (x, s) == 0;
}
#define NM_IN_STRSET_ASCII_CASE(x, ...) _NM_IN_STRSET_EVAL_N(||, _NM_IN_STRSET_ASCII_CASE_op_streq, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
/*****************************************************************************/
#define nm_g_slice_free(ptr) \
g_slice_free (typeof (*(ptr)), ptr)

View file

@ -891,6 +891,25 @@ again:
/*****************************************************************************/
static void
test_in_strset_ascii_case (void)
{
const char *x;
x = NULL;
g_assert (NM_IN_STRSET_ASCII_CASE (x, NULL));
g_assert (NM_IN_STRSET_ASCII_CASE (x, NULL, "b"));
g_assert (!NM_IN_STRSET_ASCII_CASE (x, "b"));
x = "b";
g_assert (NM_IN_STRSET (x, "b"));
g_assert (NM_IN_STRSET_ASCII_CASE (x, "b"));
g_assert (!NM_IN_STRSET (x, "B"));
g_assert (NM_IN_STRSET_ASCII_CASE (x, "B"));
}
/*****************************************************************************/
NMTST_DEFINE ();
int main (int argc, char **argv)
@ -913,6 +932,7 @@ int main (int argc, char **argv)
g_test_add_func ("/general/test_nm_utils_get_next_realloc_size", test_nm_utils_get_next_realloc_size);
g_test_add_func ("/general/test_nm_str_buf", test_nm_str_buf);
g_test_add_func ("/general/test_nm_utils_parse_next_line", test_nm_utils_parse_next_line);
g_test_add_func ("/general/test_in_strset_ascii_case", test_in_strset_ascii_case);
return g_test_run ();
}