mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: string: Add helper to check whether string is empty
The helper checks whether a string contains only whitespace or is NULL. This will be helpful to skip cases where a user string is optional, but may be provided empty with the same meaning.
This commit is contained in:
parent
5de9e082c3
commit
0eeafeedeb
@ -1999,6 +1999,7 @@ virStrdup;
|
|||||||
virStringArrayHasString;
|
virStringArrayHasString;
|
||||||
virStringFreeList;
|
virStringFreeList;
|
||||||
virStringFreeListCount;
|
virStringFreeListCount;
|
||||||
|
virStringIsEmpty;
|
||||||
virStringJoin;
|
virStringJoin;
|
||||||
virStringListLength;
|
virStringListLength;
|
||||||
virStringReplace;
|
virStringReplace;
|
||||||
|
@ -633,6 +633,22 @@ virSkipSpacesBackwards(const char *str, char **endp)
|
|||||||
*endp = NULL;
|
*endp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virStringIsEmpty:
|
||||||
|
* @str: string to check
|
||||||
|
*
|
||||||
|
* Returns true if string is empty (may contain only whitespace) or NULL.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
virStringIsEmpty(const char *str)
|
||||||
|
{
|
||||||
|
if (!str)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
virSkipSpaces(&str);
|
||||||
|
return str[0] == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virArgvToString(const char *const *argv)
|
virArgvToString(const char *const *argv)
|
||||||
{
|
{
|
||||||
|
@ -107,6 +107,8 @@ void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
|
|||||||
void virSkipSpacesBackwards(const char *str, char **endp)
|
void virSkipSpacesBackwards(const char *str, char **endp)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
|
bool virStringIsEmpty(const char *str);
|
||||||
|
|
||||||
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
||||||
ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user