mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-11 09:30:44 +01:00
shared: add NM_IN_STRSET_ASCII_CASE() macro
This commit is contained in:
parent
b16b42266d
commit
3b64d88a93
2 changed files with 30 additions and 0 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue