mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
util: Introduce virStringListRemoveDuplicates
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f928eb5fc8
commit
0c6134f190
@ -3438,6 +3438,7 @@ virStringHasControlChars;
|
||||
virStringHasSuffix;
|
||||
virStringIsEmpty;
|
||||
virStringIsPrintable;
|
||||
virStringListRemoveDuplicates;
|
||||
virStringMatch;
|
||||
virStringMatchesNameSuffix;
|
||||
virStringParsePort;
|
||||
|
@ -1065,3 +1065,32 @@ virStringParseVersion(unsigned long long *version,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStringListRemoveDuplicates:
|
||||
* @list: pointer to a sorted NULL-terminated string list
|
||||
*
|
||||
* Replace the list pointed to by @list with a new list without duplicate
|
||||
* strings. The original list has to be sorted.
|
||||
*/
|
||||
void
|
||||
virStringListRemoveDuplicates(char ***list)
|
||||
{
|
||||
size_t len = g_strv_length(*list);
|
||||
char **unique;
|
||||
size_t n = 0;
|
||||
size_t i;
|
||||
|
||||
unique = g_malloc0_n(len + 1, sizeof(char *));
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (n > 0 && STREQ_NULLABLE(unique[n - 1], (*list)[i]))
|
||||
g_free((*list)[i]);
|
||||
else
|
||||
unique[n++] = (*list)[i];
|
||||
}
|
||||
|
||||
g_free(*list);
|
||||
*list = g_renew(char *, unique, n + 1);
|
||||
}
|
||||
|
@ -138,3 +138,5 @@ int virStringParseYesNo(const char *str,
|
||||
int virStringParseVersion(unsigned long long *version,
|
||||
const char *str,
|
||||
bool allowMissing);
|
||||
|
||||
void virStringListRemoveDuplicates(char ***list);
|
||||
|
Loading…
x
Reference in New Issue
Block a user