diff options
author | Thomas Haller <thaller@redhat.com> | 2018-11-14 16:42:27 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-11-19 11:22:46 +0100 |
commit | d4762ebf456415e1b328200c369feff996f56a13 (patch) | |
tree | 21a7e3564846be21f8c8e4266b673dd2a26183b1 | |
parent | 140337a219b30fc09fc4e753cfc2ebb8e0730e7e (diff) | |
download | NetworkManager-th/strbuf.tar.gz |
shared: use NMStrBuf in _nm_utils_enum_to_str_full()th/strbuf
Just for showcase and to hit the code from the unit-tests
that we have.
-rw-r--r-- | shared/nm-utils/nm-enum-utils.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/shared/nm-utils/nm-enum-utils.c b/shared/nm-utils/nm-enum-utils.c index a4f6e809da..036e6313e7 100644 --- a/shared/nm-utils/nm-enum-utils.c +++ b/shared/nm-utils/nm-enum-utils.c @@ -22,6 +22,7 @@ #include "nm-default.h" #include "nm-enum-utils.h" +#include "nm-str-buf.h" /*****************************************************************************/ @@ -158,12 +159,14 @@ _nm_utils_enum_to_str_full (GType type, else return g_strdup (enum_value->value_nick); } else if (G_IS_FLAGS_CLASS (klass)) { - GFlagsValue *flags_value; - GString *str = g_string_new (""); unsigned uvalue = (unsigned) value; + GFlagsValue *flags_value; + NMStrBuf strbuf; flags_separator = flags_separator ?: " "; + nm_str_buf_init (&strbuf, 16, FALSE); + for ( ; value_infos && value_infos->nick; value_infos++) { nm_assert (_enum_is_valid_flags_nick (value_infos->nick)); @@ -176,9 +179,9 @@ _nm_utils_enum_to_str_full (GType type, continue; } - if (str->len) - g_string_append (str, flags_separator); - g_string_append (str, value_infos->nick); + if (strbuf.len) + nm_str_buf_append (&strbuf, flags_separator); + nm_str_buf_append (&strbuf, value_infos->nick); uvalue &= ~((unsigned) value_infos->value); if (uvalue == 0) { /* we printed all flags. Done. */ @@ -188,20 +191,20 @@ _nm_utils_enum_to_str_full (GType type, do { flags_value = g_flags_get_first_value (G_FLAGS_CLASS (klass), uvalue); - if (str->len) - g_string_append (str, flags_separator); + if (strbuf.len) + nm_str_buf_append (&strbuf, flags_separator); if ( !flags_value || !_enum_is_valid_flags_nick (flags_value->value_nick)) { if (uvalue) - g_string_append_printf (str, "0x%x", uvalue); + nm_str_buf_append_printf (&strbuf, "0x%x", uvalue); break; } - g_string_append (str, flags_value->value_nick); + nm_str_buf_append (&strbuf, flags_value->value_nick); uvalue &= ~flags_value->value; } while (uvalue); flags_done: - return g_string_free (str, FALSE); + return nm_str_buf_finalize (&strbuf, NULL); } g_return_val_if_reached (NULL); |