From a9ea2ab4bad5e5044e95e1037ea8f676b75a4db8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 28 Mar 2017 23:17:19 +0200 Subject: [PATCH] conf: cheap replacement for g_strchug() --- src/conf.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 496dcab..ae362f1 100644 --- a/src/conf.c +++ b/src/conf.c @@ -84,6 +84,28 @@ #define CONF_CHAT_PREFIX "chat-prefix" #define CONF_SECOND_COLUMN "second-column" +gcc_const +static bool +is_space_not_null(char ch) +{ + unsigned char uch = (unsigned char)ch; + return uch <= 0x20 && uch > 0; +} + +/** + * Returns the first non-space character (or a pointer to the null + * terminator). Similar to g_strchug(), but just moves the pointer + * forward without modifying the string contents. + */ +gcc_pure +static char * +skip_spaces(char *p) +{ + while (is_space_not_null(*p)) + ++p; + return p; +} + static bool str2bool(char *str) { @@ -206,7 +228,7 @@ separate_value(char *p) *value++ = 0; g_strchomp(p); - return g_strchug(value); + return skip_spaces(value); } static bool @@ -231,7 +253,7 @@ after_comma(char *p) if (comma != NULL) { *comma++ = 0; - comma = g_strchug(comma); + comma = skip_spaces(comma); } else comma = p + strlen(p); @@ -569,7 +591,7 @@ read_rc_file(char *filename) char line[MAX_LINE_LENGTH]; while (fgets(line, sizeof(line), file) != NULL) { - char *p = g_strchug(line); + char *p = skip_spaces(line); if (*p != 0 && *p != COMMENT_TOKEN) parse_line(g_strchomp(p)); -- 2.30.2