diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-02-20 11:32:48 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-02-20 13:45:32 +0100 |
commit | 8950d1836245f2ddc0a63b4ef49050a47246c3ec (patch) | |
tree | 52a166aa7f3b65ce4053e88f6236de5271a656da | |
parent | 4d3ec516bd39aea4daadd5d1f45097897d4618f1 (diff) | |
download | NetworkManager-8950d1836245f2ddc0a63b4ef49050a47246c3ec.tar.gz |
libnm-core: add _nm_utils_enum_to_str_full()
Unfortunately nm_utils_enum_to_str() doesn't allow to specify the
separator between enum values. Since the function is public API and
can't be modified now, add a new internal function which accepts the
separator as argument.
-rw-r--r-- | libnm-core/nm-core-internal.h | 2 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 41 |
2 files changed, 27 insertions, 16 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 5dd777b0ab..f5b4184234 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -183,6 +183,8 @@ gboolean _nm_utils_check_module_file (const char *name, gpointer user_data, GError **error); +char *_nm_utils_enum_to_str_full (GType type, int value, const char *sep); + #define NM_UTILS_UUID_TYPE_LEGACY 0 #define NM_UTILS_UUID_TYPE_VARIANT3 1 diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 8a40727483..75581699ab 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4249,25 +4249,14 @@ int _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option) return -1; } -/** - * nm_utils_enum_to_str: - * @type: the %GType of the enum - * @value: the value to be translated - * - * Converts an enum value to its string representation. If the enum is a - * %G_TYPE_FLAGS the function returns a comma-separated list of matching values. - * If the enum is a %G_TYPE_ENUM and the given value is not valid the - * function returns %NULL. - * - * Returns: a newly allocated string or %NULL - * - * Since: 1.2 - */ -char *nm_utils_enum_to_str (GType type, int value) +char * +_nm_utils_enum_to_str_full (GType type, int value, const char *sep) { GTypeClass *class; char *ret; + g_return_val_if_fail (sep, NULL); + class = g_type_class_ref (type); if (G_IS_ENUM_CLASS (class)) { @@ -4286,7 +4275,7 @@ char *nm_utils_enum_to_str (GType type, int value) break; if (!first) - g_string_append (str, ", "); + g_string_append (str, sep); g_string_append (str, flags_value->value_nick); value &= ~flags_value->value; @@ -4301,6 +4290,26 @@ char *nm_utils_enum_to_str (GType type, int value) } /** + * nm_utils_enum_to_str: + * @type: the %GType of the enum + * @value: the value to be translated + * + * Converts an enum value to its string representation. If the enum is a + * %G_TYPE_FLAGS the function returns a comma-separated list of matching values. + * If the enum is a %G_TYPE_ENUM and the given value is not valid the + * function returns %NULL. + * + * Returns: a newly allocated string or %NULL + * + * Since: 1.2 + */ +char * +nm_utils_enum_to_str (GType type, int value) +{ + return _nm_utils_enum_to_str_full (type, value, ", "); +} + +/** * nm_utils_enum_from_str: * @type: the %GType of the enum * @str: the input string |