提交 1bcf7e10 编写于 作者: P Peter Krempa 提交者: Cole Robinson

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.

(cherry picked from commit 0eeafeed)
上级 5d02a123
......@@ -1991,6 +1991,7 @@ virStrdup;
virStringArrayHasString;
virStringFreeList;
virStringFreeListCount;
virStringIsEmpty;
virStringJoin;
virStringListLength;
virStringReplace;
......
......@@ -633,6 +633,22 @@ virSkipSpacesBackwards(const char *str, char **endp)
*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 *
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)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
bool virStringIsEmpty(const char *str);
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
ATTRIBUTE_RETURN_CHECK;
char *virStrcpy(char *dest, const char *src, size_t destbytes)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册