diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 551cd92f16..c9862be423 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -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) diff --git a/shared/nm-glib-aux/tests/test-shared-general.c b/shared/nm-glib-aux/tests/test-shared-general.c index 37d6618ad8..afccb969f0 100644 --- a/shared/nm-glib-aux/tests/test-shared-general.c +++ b/shared/nm-glib-aux/tests/test-shared-general.c @@ -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 (); }