mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
util: Add virStringGetFirstWithPrefix
That function takes string list and returns first string in that list that starts with the @prefix parameter with that prefix being skipped as the caller knows what it starts with (also for easier manipulation in future). Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
ed4da64657
commit
1fe69c4656
@ -2177,6 +2177,7 @@ virStrdup;
|
||||
virStringArrayHasString;
|
||||
virStringFreeList;
|
||||
virStringFreeListCount;
|
||||
virStringGetFirstWithPrefix;
|
||||
virStringHasControlChars;
|
||||
virStringIsEmpty;
|
||||
virStringJoin;
|
||||
|
@ -238,6 +238,23 @@ virStringArrayHasString(char **strings, const char *needle)
|
||||
return false;
|
||||
}
|
||||
|
||||
char *
|
||||
virStringGetFirstWithPrefix(char **strings, const char *prefix)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
if (!strings)
|
||||
return NULL;
|
||||
|
||||
while (strings[i]) {
|
||||
if (STRPREFIX(strings[i], prefix))
|
||||
return strings[i] + strlen(prefix);
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Like strtol, but produce an "int" result, and check more carefully.
|
||||
Return 0 upon success; return -1 to indicate failure.
|
||||
When END_PTR is NULL, the byte after the final valid digit must be NUL.
|
||||
|
@ -47,6 +47,8 @@ void virStringFreeListCount(char **strings, size_t count);
|
||||
size_t virStringListLen(const char **strings);
|
||||
|
||||
bool virStringArrayHasString(char **strings, const char *needle);
|
||||
char *virStringGetFirstWithPrefix(char **strings, const char *prefix)
|
||||
ATTRIBUTE_NONNULL(2);
|
||||
|
||||
char *virArgvToString(const char *const *argv);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user