summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-30 19:14:24 +0200
committerThomas Haller <thaller@redhat.com>2020-08-05 10:22:10 +0200
commit3b64d88a935718ae9813641bbac440fc8eb34441 (patch)
treebe30c5ebf8cab5f95b5b9b53ff7b927f30899fb0
parentb16b42266d9964e63f3caaac788f06e323dc4c20 (diff)
downloadNetworkManager-3b64d88a935718ae9813641bbac440fc8eb34441.tar.gz
shared: add NM_IN_STRSET_ASCII_CASE() macro
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h10
-rw-r--r--shared/nm-glib-aux/tests/test-shared-general.c20
2 files changed, 30 insertions, 0 deletions
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 ();
}