mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-17 11:30:46 +02:00
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.
This commit is contained in:
parent
4d3ec516bd
commit
8950d18362
2 changed files with 27 additions and 16 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -4300,6 +4289,26 @@ char *nm_utils_enum_to_str (GType type, int value)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue