Commit f0c1efbf authored by Lubomir Rintel's avatar Lubomir Rintel 🥕

all: add and utilize nm_utils_is_separator()

It is meant to be rather similar in nature to isblank() or
g_ascii_isspace().

Sadly, isblank() is locale dependent while g_ascii_isspace() also considers
vertical whitespace as a space. That's no good for configuration files that
are strucutured into lines, which happens to be a pretty common case.
parent 1829126f
......@@ -5884,7 +5884,7 @@ _split_cmd (const char *cmd, char **out_arg0, const char **out_argr)
if (!cmd)
return;
while (NM_IN_SET (cmd[0], ' ', '\t'))
while (nm_utils_is_separator (cmd[0]))
cmd++;
if (!cmd[0])
return;
......@@ -5893,7 +5893,7 @@ _split_cmd (const char *cmd, char **out_arg0, const char **out_argr)
arg0 = g_strndup (cmd, l);
cmd += l;
if (cmd[0]) {
while (NM_IN_SET (cmd[0], ' ', '\t'))
while (nm_utils_is_separator (cmd[0]))
cmd++;
if (cmd[0])
argr = cmd;
......
......@@ -2157,7 +2157,7 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN)
password = path + strcspn (path, " \t"); \
if (password[0] != '\0') { \
password[0] = '\0'; \
while (NM_IN_SET (password[0], ' ', '\t')) \
while (nm_utils_is_separator (password[0])) \
password++; \
} else \
password = password_free = g_strdup (pwd_func (NM_SETTING_802_1X (setting))); \
......
......@@ -191,6 +191,12 @@ void nm_utils_strbuf_append_str (char **buf, gsize *len, const char *str);
const char *nm_strquote (char *buf, gsize buf_len, const char *str);
static inline gboolean
nm_utils_is_separator (const char c)
{
return NM_IN_SET (c, ' ', '\t');
}
/*****************************************************************************/
const char **nm_utils_strsplit_set (const char *str, const char *delimiters);
......
......@@ -502,7 +502,7 @@ parse_route_line_is_comment (const char *line)
*
* initscripts compares: "$line" =~ '^[[:space:]]*(\#.*)?$'
*/
while (NM_IN_SET (line[0], ' ', '\t'))
while (nm_utils_is_separator (line[0]))
line++;
if (NM_IN_SET (line[0], '\0', '#'))
return TRUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment