diff options
author | Thomas Haller <thaller@redhat.com> | 2020-03-27 10:10:27 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-04-04 19:51:34 +0200 |
commit | ab9dc9f6d4a425c28900c5ed4332df3e9aacc9fe (patch) | |
tree | 42820ef326942d9e6f44629e49daca4fe44b9a97 /shared | |
parent | 484d44fc87e752e5762ce8f2ebb7639c7211c363 (diff) | |
download | NetworkManager-ab9dc9f6d4a425c28900c5ed4332df3e9aacc9fe.tar.gz |
shared: refactor initializing character lookup tables for strsplit
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index 4ad2e43606..fffd761b7a 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -1497,12 +1497,27 @@ comp_l: /*****************************************************************************/ static void +_char_lookup_table_set_one (guint8 lookup[static 256], + char ch) +{ + lookup[(guint8) ch] = 1; +} + +static void +_char_lookup_table_set_all (guint8 lookup[static 256], + const char *candidates) +{ + while (candidates[0] != '\0') + _char_lookup_table_set_one (lookup, (candidates++)[0]); +} + +static void _char_lookup_table_init (guint8 lookup[static 256], const char *candidates) { memset (lookup, 0, 256); - while (candidates[0] != '\0') - lookup[(guint8) ((candidates++)[0])] = 1; + if (candidates) + _char_lookup_table_set_all (lookup, candidates); } static gboolean @@ -1717,11 +1732,9 @@ done2: /* We no longer need ch_lookup for its original purpose. Modify it, so it * can detect the delimiters, '\\', and (optionally) whitespaces. */ - ch_lookup[((guint8) '\\')] = 1; - if (f_strstrip) { - for (i = 0; NM_ASCII_SPACES[i]; i++) - ch_lookup[((guint8) (NM_ASCII_SPACES[i]))] = 1; - } + _char_lookup_table_set_one (ch_lookup, '\\'); + if (f_strstrip) + _char_lookup_table_set_all (ch_lookup, NM_ASCII_SPACES); for (i_token = 0; ptr[i_token]; i_token++) { s = (char *) ptr[i_token]; @@ -1767,7 +1780,7 @@ nm_utils_escaped_tokens_escape (const char *str, _char_lookup_table_init (ch_lookup, delimiters); /* also mark '\\' as requiring escaping. */ - ch_lookup[((guint8) '\\')] = 1; + _char_lookup_table_set_one (ch_lookup, '\\'); n_escapes = 0; for (i = 0; str[i] != '\0'; i++) { |