From 69de5ee4e9929159954a5b6ecadd0eb9a5a287ae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Oct 2019 09:08:10 +0200 Subject: [PATCH] shared: move nm_utils_parse_debug_string() from core to shared --- shared/nm-glib-aux/nm-shared-utils.c | 60 ++++++++++++++++++++++++++++ shared/nm-glib-aux/nm-shared-utils.h | 4 ++ src/nm-core-utils.c | 60 ---------------------------- src/nm-core-utils.h | 4 -- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index f48401264c..34d5de1201 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -3318,3 +3318,63 @@ nm_utils_gvariant_vardict_filter_drop_one (GVariant *src, _gvariant_vardict_filter_drop_one, (gpointer) key); } + +/*****************************************************************************/ + +static gboolean +debug_key_matches (const char *key, + const char *token, + guint length) +{ + /* may not call GLib functions: see note in g_parse_debug_string() */ + for (; length; length--, key++, token++) { + char k = (*key == '_') ? '-' : g_ascii_tolower (*key ); + char t = (*token == '_') ? '-' : g_ascii_tolower (*token); + + if (k != t) + return FALSE; + } + + return *key == '\0'; +} + +/** + * nm_utils_parse_debug_string: + * @string: the string to parse + * @keys: the debug keys + * @nkeys: number of entries in @keys + * + * Similar to g_parse_debug_string(), but does not special + * case "help" or "all". + * + * Returns: the flags + */ +guint +nm_utils_parse_debug_string (const char *string, + const GDebugKey *keys, + guint nkeys) +{ + guint i; + guint result = 0; + const char *q; + + if (string == NULL) + return 0; + + while (*string) { + q = strpbrk (string, ":;, \t"); + if (!q) + q = string + strlen (string); + + for (i = 0; i < nkeys; i++) { + if (debug_key_matches (keys[i].key, string, q - string)) + result |= keys[i].value; + } + + string = q; + if (*string) + string++; + } + + return result; +} diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 1252ffe443..ff1ea17e20 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -1289,4 +1289,8 @@ nm_g_task_is_valid (gpointer task, && g_task_get_source_tag (task) == source_tag; } +guint nm_utils_parse_debug_string (const char *string, + const GDebugKey *keys, + guint nkeys); + #endif /* __NM_SHARED_UTILS_H__ */ diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 8a494e6102..7e614577fc 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -3744,66 +3744,6 @@ nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings) /*****************************************************************************/ -static gboolean -debug_key_matches (const char *key, - const char *token, - guint length) -{ - /* may not call GLib functions: see note in g_parse_debug_string() */ - for (; length; length--, key++, token++) { - char k = (*key == '_') ? '-' : g_ascii_tolower (*key ); - char t = (*token == '_') ? '-' : g_ascii_tolower (*token); - - if (k != t) - return FALSE; - } - - return *key == '\0'; -} - -/** - * nm_utils_parse_debug_string: - * @string: the string to parse - * @keys: the debug keys - * @nkeys: number of entries in @keys - * - * Similar to g_parse_debug_string(), but does not special - * case "help" or "all". - * - * Returns: the flags - */ -guint -nm_utils_parse_debug_string (const char *string, - const GDebugKey *keys, - guint nkeys) -{ - guint i; - guint result = 0; - const char *q; - - if (string == NULL) - return 0; - - while (*string) { - q = strpbrk (string, ":;, \t"); - if (!q) - q = string + strlen (string); - - for (i = 0; i < nkeys; i++) { - if (debug_key_matches (keys[i].key, string, q - string)) - result |= keys[i].value; - } - - string = q; - if (*string) - string++; - } - - return result; -} - -/*****************************************************************************/ - void nm_utils_ifname_cpy (char *dst, const char *name) { diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index fa5659f640..b20db7a1c0 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -425,10 +425,6 @@ void _nm_utils_set_testing (NMUtilsTestFlags flags); void nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings); -guint nm_utils_parse_debug_string (const char *string, - const GDebugKey *keys, - guint nkeys); - void nm_utils_ifname_cpy (char *dst, const char *name); guint32 nm_utils_lifetime_rebase_relative_time_on_now (guint32 timestamp,