diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-17 17:30:27 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-04-18 17:53:09 +0200 |
commit | 304eab8703dc1c77211d0c7f32a76932b725bd86 (patch) | |
tree | 837ffcd5b20dc73756c9e0c840a8a47933a4ec96 | |
parent | 941f27d350f8d086d3dbdda7ae19f6e4fa2856cf (diff) | |
download | NetworkManager-304eab8703dc1c77211d0c7f32a76932b725bd86.tar.gz |
shared: remove unused _nm_utils_escape_plain()/_nm_utils_escape_spaces() API
... and the "unescape" variants.
This is replaced by nm_utils_escaped_tokens_split()
and nm_utils_escaped_tokens_escape*() API.
-rw-r--r-- | libnm-core/tests/test-general.c | 98 | ||||
-rw-r--r-- | shared/nm-utils/nm-shared-utils.c | 75 | ||||
-rw-r--r-- | shared/nm-utils/nm-shared-utils.h | 17 |
3 files changed, 0 insertions, 190 deletions
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index d3743e0ede..64f937cbcf 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -8074,102 +8074,6 @@ test_ethtool_offload (void) g_assert_cmpstr (d->optname, ==, NM_ETHTOOL_OPTNAME_FEATURE_RXHASH); } -static void -test_nm_utils_escape_spaces (void) -{ - char *to_free; - - g_assert_cmpstr (_nm_utils_escape_spaces (NULL, &to_free), ==, NULL); - g_free (to_free); - - g_assert_cmpstr (_nm_utils_escape_spaces ("", &to_free), ==, ""); - g_free (to_free); - - g_assert_cmpstr (_nm_utils_escape_spaces (" ", &to_free), ==, "\\ "); - g_free (to_free); - - g_assert_cmpstr (_nm_utils_escape_spaces ("\t ", &to_free), ==, "\\\t\\ "); - g_free (to_free); - - g_assert_cmpstr (_nm_utils_escape_spaces ("abc", &to_free), ==, "abc"); - g_free (to_free); - - g_assert_cmpstr (_nm_utils_escape_spaces ("abc def", &to_free), ==, "abc\\ def"); - g_free (to_free); - - g_assert_cmpstr (_nm_utils_escape_spaces ("abc\tdef", &to_free), ==, "abc\\\tdef"); - g_free (to_free); -} - -static void -_do_test_unescape_spaces (const char *in, const char *out) -{ - nm_auto_free_gstring GString *str_out = g_string_new (NULL); - nm_auto_free_gstring GString *str_in = g_string_new (NULL); - guint i; - - for (i = 0; i < 10; i++) { - - g_string_set_size (str_in, 0); - - g_string_append (str_in, in); - - if (i == 0) - g_assert_cmpstr (_nm_utils_unescape_spaces (str_in->str, FALSE), ==, out); - else if (i == 1) - g_assert_cmpstr (_nm_utils_unescape_spaces (str_in->str, TRUE), ==, out); - else { - bool do_strip = nmtst_get_rand_bool (); - guint n = nmtst_get_rand_int () % 20; - guint j; - - g_string_set_size (str_out, 0); - if (!do_strip) - g_string_append (str_out, out); - - for (j = 0; j < n; j++) { - gboolean append = nmtst_get_rand_bool (); - char ch = nmtst_rand_select (' ', '\t'); - - if (append && out[0] && out[strlen (out) - 1] == '\\') - append = FALSE; - - g_string_insert_c (str_in, append ? -1 : 0, ch); - if (!do_strip) - g_string_insert_c (str_out, append ? -1 : 0, ch); - } - - if (do_strip) - g_assert_cmpstr (_nm_utils_unescape_spaces (str_in->str, TRUE), ==, out); - else - g_assert_cmpstr (_nm_utils_unescape_spaces (str_in->str, FALSE), ==, str_out->str); - } - } -} - -static void -test_nm_utils_unescape_spaces (void) -{ - _do_test_unescape_spaces ("", ""); - _do_test_unescape_spaces ("\\", "\\"); - _do_test_unescape_spaces ("\\ ", " "); - _do_test_unescape_spaces ("\\\t", "\t"); - _do_test_unescape_spaces ("a", "a"); - _do_test_unescape_spaces ("\\a", "\\a"); - _do_test_unescape_spaces ("foobar", "foobar"); - _do_test_unescape_spaces ("foo bar", "foo bar"); - _do_test_unescape_spaces ("foo\\ bar", "foo bar"); - _do_test_unescape_spaces ("foo\\", "foo\\"); - _do_test_unescape_spaces ("\\\\", "\\\\"); - _do_test_unescape_spaces ("foo bar", "foo bar"); - _do_test_unescape_spaces ("\\ foo bar", " foo bar"); - _do_test_unescape_spaces ("\\ foo bar\\ ", " foo bar "); - _do_test_unescape_spaces ("\\\tfoo bar\\\t", "\tfoo bar\t"); - _do_test_unescape_spaces ("\\\tfoo bar \\\t", "\tfoo bar \t"); - _do_test_unescape_spaces ("\\\t", "\t"); - _do_test_unescape_spaces ("\\\t \\ ", "\t "); -} - /*****************************************************************************/ NMTST_DEFINE (); @@ -8323,8 +8227,6 @@ int main (int argc, char **argv) g_test_add_func ("/core/general/_nm_utils_dns_option_find_idx", test_nm_utils_dns_option_find_idx); g_test_add_func ("/core/general/_nm_utils_validate_json", test_nm_utils_check_valid_json); g_test_add_func ("/core/general/_nm_utils_team_config_equal", test_nm_utils_team_config_equal); - g_test_add_func ("/core/general/_nm_utils_escape_spaces", test_nm_utils_escape_spaces); - g_test_add_func ("/core/general/_nm_utils_unescape_spaces", test_nm_utils_unescape_spaces); g_test_add_func ("/core/general/test_nm_utils_enum", test_nm_utils_enum); g_test_add_func ("/core/general/nm-set-out", test_nm_set_out); g_test_add_func ("/core/general/route_attributes/parse", test_route_attributes_parse); diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 06cd481ebb..cf08a77fde 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -2618,81 +2618,6 @@ _nm_utils_user_data_unpack (gpointer user_data, int nargs, ...) /*****************************************************************************/ -const char * -_nm_utils_escape_plain (const char *str, const char *candidates, char **to_free) -{ - const char *ptr = str; - char *ret, *r; - guint8 ch_lookup[256]; - - *to_free = NULL; - - if (!str) - return NULL; - - _char_lookup_table_init (ch_lookup, candidates ?: NM_ASCII_SPACES); - - while (TRUE) { - if (!*ptr) - return str; - if (_char_lookup_has (ch_lookup, *ptr)) - break; - ptr++; - } - - ptr = str; - ret = g_new (char, strlen (str) * 2 + 1); - r = ret; - *to_free = ret; - while (*ptr) { - if (_char_lookup_has (ch_lookup, *ptr)) - *r++ = '\\'; - *r++ = *ptr++; - } - *r = '\0'; - - return ret; -} - -char * -_nm_utils_unescape_plain (char *str, const char *candidates, gboolean do_strip) -{ - gsize i = 0; - gsize j = 0; - gsize preserve_space_at = 0; - guint8 ch_lookup[256]; - - if (!str) - return NULL; - - _char_lookup_table_init (ch_lookup, candidates ?: NM_ASCII_SPACES); - - if (do_strip) { - while (str[i] && _char_lookup_has (ch_lookup, str[i])) - i++; - } - - for (; str[i]; i++) { - if ( str[i] == '\\' - && _char_lookup_has (ch_lookup, str[i+1])) { - preserve_space_at = j; - i++; - } - str[j++] = str[i]; - } - str[j] = '\0'; - - if (do_strip && j > 0) { - while ( --j > preserve_space_at - && _char_lookup_has (ch_lookup, str[j])) - str[j] = '\0'; - } - - return str; -} - -/*****************************************************************************/ - typedef struct { gpointer callback_user_data; GCancellable *cancellable; diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index 6bfc37acbf..af3c2f830b 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -1110,23 +1110,6 @@ void _nm_utils_user_data_unpack (gpointer user_data, int nargs, ...); /*****************************************************************************/ -const char *_nm_utils_escape_plain (const char *str, const char *candidates, char **to_free); -char *_nm_utils_unescape_plain (char *str, const char *candidates, gboolean do_strip); - -static inline const char * -_nm_utils_escape_spaces (const char *str, char **to_free) -{ - return _nm_utils_escape_plain (str, NM_ASCII_SPACES, to_free); -} - -static inline char * -_nm_utils_unescape_spaces (char *str, gboolean do_strip) -{ - return _nm_utils_unescape_plain (str, NM_ASCII_SPACES, do_strip); -} - -/*****************************************************************************/ - typedef void (*NMUtilsInvokeOnIdleCallback) (gpointer callback_user_data, GCancellable *cancellable); |