feat: (str) str_is_blank

This commit is contained in:
thetek 2023-02-15 09:40:29 +01:00
parent 30a978beca
commit dc1e58971f
2 changed files with 17 additions and 0 deletions

View File

@ -28,5 +28,6 @@ bool str_ends_with (const str_t *str, const char *find); /* check if a str_t str
bool str_ends_with_len (const str_t *str, const char *find, size_t len); /* check if a str_t string ends with a cstring of given length. */
char *str_find (const str_t *str, const char *find); /* find a substring in a str_t string as a pointer. */
ssize_t str_pos (const str_t *str, const char *find); /* find the index of a substring in a str_t string. */
bool str_is_blank (const str_t *str); /* check if a string only consists of whitespace characters. */
#endif // CUTILS_STR_H_

View File

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "cstr.h"
#define STR_MIN_ALLOC 64 /* minimum allocation size for string data */
@ -243,3 +244,18 @@ str_pos (const str_t *str, const char *find)
return pos - str->str;
return -1;
}
/**
* check if a string only consists of whitespace characters. whitespaces
* include the following characters: ' ', '\n', '\r', '\t', '\v', '\f'.
*
* @param str: the string to check
*
* @return true if the string only consists of whitespace characters, or false
* if other characters are present. false in case of error.
*/
inline bool
str_is_blank (const str_t *str)
{
return strisblank (str->str);
}