diff --git a/include/common/string-helpers.h b/include/common/string-helpers.h index e49fa110..0509d33c 100644 --- a/include/common/string-helpers.h +++ b/include/common/string-helpers.h @@ -9,6 +9,12 @@ */ bool string_null_or_empty(const char *s); +/** + * str_space_only - Check if the string only contains white-space characters + * @s: string to check + */ +bool str_space_only(const char *s); + /** * trim_last_field() - Trim last field of string splitting on provided delim * @buf: string to trim diff --git a/src/common/string-helpers.c b/src/common/string-helpers.c index 2d8f8de3..a0d73034 100644 --- a/src/common/string-helpers.c +++ b/src/common/string-helpers.c @@ -204,3 +204,14 @@ str_equal(const char *a, const char *b) { return a == b || (a && b && !strcmp(a, b)); } + +bool +str_space_only(const char *s) +{ + for (; *s; s++) { + if (!isspace(*s)) { + return false; + } + } + return true; +}