mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-08 10:20:30 +01:00
core/utils: extend nm_utils_flags2str() for multi-value flags and name for zero
Allow passing a pretty name for the zero flag 0, like "none". Also, don't require flags to be power-of-two. Instead, allow names for multiple flags. For example an "all" name. By specifying multi-value flags first, their nick will be supersede the more specific flags. Probably it doesn't make sense in usual cases, but nm_utils_flags2str() should prevent such use.
This commit is contained in:
parent
5dd6fcb970
commit
a2dcdbe042
1 changed files with 9 additions and 3 deletions
|
|
@ -1869,7 +1869,6 @@ nm_utils_flags2str (const NMUtilsFlags2StrDesc *descs,
|
|||
for (i = 0; i < n_descs; i++) {
|
||||
gsize j;
|
||||
|
||||
nm_assert (descs[i].flag && nm_utils_is_power_of_two (descs[i].flag));
|
||||
nm_assert (descs[i].name && descs[i].name[0]);
|
||||
for (j = 0; j < i; j++)
|
||||
nm_assert (descs[j].flag != descs[i].flag);
|
||||
|
|
@ -1882,13 +1881,20 @@ nm_utils_flags2str (const NMUtilsFlags2StrDesc *descs,
|
|||
return buf;
|
||||
|
||||
buf[0] = '\0';
|
||||
p = buf;
|
||||
if (!flags) {
|
||||
for (i = 0; i < n_descs; i++) {
|
||||
if (!descs[i].flag) {
|
||||
nm_utils_strbuf_append_str (&p, &len, descs[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
for (i = 0; flags && i < n_descs; i++) {
|
||||
if (NM_FLAGS_HAS (flags, descs[i].flag)) {
|
||||
if ( descs[i].flag
|
||||
&& NM_FLAGS_ALL (flags, descs[i].flag)) {
|
||||
flags &= ~descs[i].flag;
|
||||
|
||||
if (buf[0] != '\0')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue