glib-aux: add nm_ascii_is_{whitespace,newline}() helper

This commit is contained in:
Thomas Haller 2022-04-08 18:56:32 +02:00
parent 4b9ea28cd4
commit 7df494bc9a
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1053,6 +1053,24 @@ nm_g_variant_equal(GVariant *a, GVariant *b)
* the kernel command line. */
#define NM_ASCII_WHITESPACES " \n\t\r"
static inline gboolean
nm_ascii_is_whitespace(char ch)
{
/* Checks whether @ch is in NM_ASCII_WHITESPACES.
* Similar to g_ascii_isspace(), however this one does not accept '\f'.
* This is the same as systemd's strchr(WHITESPACE, ch). */
return NM_IN_SET(ch, ' ', '\n', '\t', '\r');
}
#define NM_ASCII_NEWLINE "\n\r"
static inline gboolean
nm_ascii_is_newline(char ch)
{
/* This is the same as systemd's (!!strchr(NEWLINE, ch)). */
return NM_IN_SET(ch, '\n', '\t');
}
#define nm_str_skip_leading_spaces(str) \
({ \
typeof(*(str)) *_str_sls = (str); \