提交 1fe69c46 编写于 作者: M Martin Kletzander

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: NMartin Kletzander <mkletzan@redhat.com>
上级 ed4da646
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册