Add function to find a needle in a string array

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Tested-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2013-04-12 16:55:45 -04:00 committed by Stefan Berger
parent ed1f031850
commit 069219577b
3 changed files with 17 additions and 0 deletions

View File

@ -1723,6 +1723,7 @@ virStorageFileResize;
# util/virstring.h # util/virstring.h
virStringArrayHasString;
virStringFreeList; virStringFreeList;
virStringJoin; virStringJoin;
virStringSplit; virStringSplit;

View File

@ -166,3 +166,17 @@ void virStringFreeList(char **strings)
} }
VIR_FREE(strings); VIR_FREE(strings);
} }
bool
virStringArrayHasString(char **strings, const char *needle)
{
size_t i = 0;
while (strings[i]) {
if (STREQ(strings[i++], needle))
return true;
}
return false;
}

View File

@ -35,4 +35,6 @@ char *virStringJoin(const char **strings,
void virStringFreeList(char **strings); void virStringFreeList(char **strings);
bool virStringArrayHasString(char **strings, const char *needle);
#endif /* __VIR_STRING_H__ */ #endif /* __VIR_STRING_H__ */