diff options
author | Thomas Haller <thaller@redhat.com> | 2019-03-20 10:43:54 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-03-25 09:12:33 +0100 |
commit | 5b8305c27c4b657c333f127373156591601d541b (patch) | |
tree | ca38087221ceb63ffc975d44ae2b2863fcc624cc | |
parent | 70bad5c74d079d365abbdad916f8cee4dad223ec (diff) | |
download | NetworkManager-5b8305c27c4b657c333f127373156591601d541b.tar.gz |
shared: add NM_ASCII_SPACES macro
-rw-r--r-- | libnm-core/tests/test-general.c | 24 | ||||
-rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 876e48388a..6d5eeb2810 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -80,6 +80,29 @@ G_STATIC_ASSERT (sizeof (bool) <= sizeof (int)); /*****************************************************************************/ +static void +test_nm_ascii_spaces (void) +{ + int i; + const char *const S = NM_ASCII_SPACES; + + for (i = 0; S[i]; i++) + g_assert (!strchr (&S[i + 1], S[i])); + + for (i = 0; S[i] != '\0'; i++) + g_assert (g_ascii_isspace (S[i])); + + g_assert (!g_ascii_isspace ((char) 0)); + for (i = 1; i < 0x100; i++) { + if (g_ascii_isspace ((char) i)) + g_assert (strchr (S, (char) i)); + else + g_assert (!strchr (S, (char) i)); + } +} + +/*****************************************************************************/ + typedef struct _nm_packed { int v0; char v1; @@ -7810,6 +7833,7 @@ int main (int argc, char **argv) { nmtst_init (&argc, &argv, TRUE); + g_test_add_func ("/core/general/test_nm_ascii_spaces", test_nm_ascii_spaces); g_test_add_func ("/core/general/test_nm_hash", test_nm_hash); g_test_add_func ("/core/general/test_nm_g_slice_free_fcn", test_nm_g_slice_free_fcn); g_test_add_func ("/core/general/test_c_list_sort", test_c_list_sort); diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 42299c9635..2f4fd86de7 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -1334,6 +1334,9 @@ _NM_BACKPORT_SYMBOL_IMPL(version, return_type, func, _##func##_##version, args_t /*****************************************************************************/ +/* mirrors g_ascii_isspace() and what we consider spaces in general. */ +#define NM_ASCII_SPACES "\t\n\f\r " + #define nm_str_skip_leading_spaces(str) \ ({ \ typeof (*(str)) *_str = (str); \ |