From 47ff0006975a2fcab2178b729deec675c2283363 Mon Sep 17 00:00:00 2001 From: taiyu Date: Mon, 7 Sep 2015 14:40:23 -0700 Subject: [PATCH] put strip_whitespace back --- sway/config.c | 1 + sway/stringop.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/sway/config.c b/sway/config.c index 119730ca..95cd8b0d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -230,6 +230,7 @@ bool read_config(FILE *file, bool is_active) { char *line; while (!feof(file)) { line = read_line(file); + line = strip_whitespace(line); line = strip_comments(line); if (line[0] == '\0') { goto _continue; diff --git a/sway/stringop.c b/sway/stringop.c index d2b74655..77faf3f1 100644 --- a/sway/stringop.c +++ b/sway/stringop.c @@ -11,16 +11,21 @@ const char *whitespace = " \f\n\r\t\v"; /* Note: This returns 8 characters for trimmed_start per tab character. */ char *strip_whitespace(char *_str) { - int ws = strspn(_str, whitespace); - int len = strlen(_str) - ws + 1; - sway_log(L_DEBUG,"%d, %d..",ws,len); - char *str = malloc(len); - strcpy(str, _str+ws); - free(_str); + if (*_str == '\0') + return _str; + char *strold = _str; + while (*_str == ' ' || *_str == '\t') { + _str++; + } + char *str = malloc(strlen(_str) + 1); + strcpy(str, _str); + free(strold); + int i; + for (i = 0; str[i] != '\0'; ++i); do { - len--; - } while (len >= 0 && (str[len] == ' ' || str[len] == '\t')); - str[len + 1] = '\0'; + i--; + } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); + str[i + 1] = '\0'; return str; }