aboutsummaryrefslogtreecommitdiffstats
path: root/common/stringop.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2019-01-08 10:05:37 +0100
committerLibravatar GitHub <noreply@github.com>2019-01-08 10:05:37 +0100
commit140bc2dd5b81205df58bf06e695788e689fae397 (patch)
tree6a88913630734736763b12ec0b10da68ef413256 /common/stringop.c
parentMerge pull request #3337 from RedSoxFan/fix-seat-cmd-cursor (diff)
parentfixup! stringop.c: rewrite strip_whitespace (diff)
downloadsway-140bc2dd5b81205df58bf06e695788e689fae397.tar.gz
sway-140bc2dd5b81205df58bf06e695788e689fae397.tar.zst
sway-140bc2dd5b81205df58bf06e695788e689fae397.zip
Merge pull request #3275 from ianyfan/remove-readline
Rewrite strip_whitespace and remove readline.c
Diffstat (limited to 'common/stringop.c')
-rw-r--r--common/stringop.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/common/stringop.c b/common/stringop.c
index 4b8c9a38..8af0d60f 100644
--- a/common/stringop.c
+++ b/common/stringop.c
@@ -9,24 +9,17 @@
9#include "string.h" 9#include "string.h"
10#include "list.h" 10#include "list.h"
11 11
12const char whitespace[] = " \f\n\r\t\v"; 12static const char whitespace[] = " \f\n\r\t\v";
13 13
14char *strip_whitespace(char *_str) { 14void strip_whitespace(char *str) {
15 if (*_str == '\0') 15 size_t len = strlen(str);
16 return _str; 16 size_t start = strspn(str, whitespace);
17 char *strold = _str; 17 memmove(str, &str[start], len + 1 - start);
18 while (*_str == ' ' || *_str == '\t') { 18
19 _str++; 19 if (*str) {
20 for (len -= start + 1; isspace(str[len]); --len) {}
21 str[len + 1] = '\0';
20 } 22 }
21 char *str = strdup(_str);
22 free(strold);
23 int i;
24 for (i = 0; str[i] != '\0'; ++i);
25 do {
26 i--;
27 } while (i >= 0 && (str[i] == ' ' || str[i] == '\t'));
28 str[i + 1] = '\0';
29 return str;
30} 23}
31 24
32void strip_quotes(char *str) { 25void strip_quotes(char *str) {