From 7df494bc9a58120f924f0a07d7de07d46abf7496 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 8 Apr 2022 18:56:32 +0200 Subject: [PATCH] glib-aux: add nm_ascii_is_{whitespace,newline}() helper --- src/libnm-glib-aux/nm-macros-internal.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 7cc8ac9797..6f6aeff106 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -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); \