diff options
-rw-r--r-- | common/stringop.c | 27 | ||||
-rw-r--r-- | include/stringop.h | 5 | ||||
-rw-r--r-- | sway/commands.c | 6 | ||||
-rw-r--r-- | sway/config.c | 4 | ||||
-rw-r--r-- | sway/input/input-manager.c | 2 |
5 files changed, 17 insertions, 27 deletions
diff --git a/common/stringop.c b/common/stringop.c index 4b8c9a38..f8b7aaec 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 | ||
12 | const char whitespace[] = " \f\n\r\t\v"; | 12 | static const char whitespace[] = " \f\n\r\t\v"; |
13 | 13 | ||
14 | char *strip_whitespace(char *_str) { | 14 | void 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) return; |
20 | } | 20 | |
21 | char *str = strdup(_str); | 21 | for (len -= start + 1; isspace(str[len]); --len) {} |
22 | free(strold); | 22 | str[len + 1] = '\0'; |
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 | ||
32 | void strip_quotes(char *str) { | 25 | void strip_quotes(char *str) { |
diff --git a/include/stringop.h b/include/stringop.h index d1bfa29d..f7ca60a5 100644 --- a/include/stringop.h +++ b/include/stringop.h | |||
@@ -3,10 +3,7 @@ | |||
3 | 3 | ||
4 | #include "list.h" | 4 | #include "list.h" |
5 | 5 | ||
6 | // array of whitespace characters to use for delims | 6 | void strip_whitespace(char *str); |
7 | extern const char whitespace[]; | ||
8 | |||
9 | char *strip_whitespace(char *str); | ||
10 | char *strip_comments(char *str); | 7 | char *strip_comments(char *str); |
11 | void strip_quotes(char *str); | 8 | void strip_quotes(char *str); |
12 | 9 | ||
diff --git a/sway/commands.c b/sway/commands.c index 927434bc..cd595b03 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -236,15 +236,15 @@ list_t *execute_command(char *_exec, struct sway_seat *seat, | |||
236 | criteria_destroy(criteria); | 236 | criteria_destroy(criteria); |
237 | config->handler_context.using_criteria = true; | 237 | config->handler_context.using_criteria = true; |
238 | // Skip leading whitespace | 238 | // Skip leading whitespace |
239 | head += strspn(head, whitespace); | 239 | for (; isspace(*head); ++head) {} |
240 | } | 240 | } |
241 | // Split command list | 241 | // Split command list |
242 | cmdlist = argsep(&head, ";"); | 242 | cmdlist = argsep(&head, ";"); |
243 | cmdlist += strspn(cmdlist, whitespace); | 243 | for (; isspace(*cmdlist); ++cmdlist) {} |
244 | do { | 244 | do { |
245 | // Split commands | 245 | // Split commands |
246 | cmd = argsep(&cmdlist, ","); | 246 | cmd = argsep(&cmdlist, ","); |
247 | cmd += strspn(cmd, whitespace); | 247 | for (; isspace(*cmd); ++cmd) {} |
248 | if (strcmp(cmd, "") == 0) { | 248 | if (strcmp(cmd, "") == 0) { |
249 | wlr_log(WLR_INFO, "Ignoring empty command."); | 249 | wlr_log(WLR_INFO, "Ignoring empty command."); |
250 | continue; | 250 | continue; |
diff --git a/sway/config.c b/sway/config.c index bb7f796d..c71f315a 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -580,7 +580,7 @@ static int detect_brace_on_following_line(FILE *file, char *line, | |||
580 | free(peeked); | 580 | free(peeked); |
581 | peeked = peek_line(file, lines, &position); | 581 | peeked = peek_line(file, lines, &position); |
582 | if (peeked) { | 582 | if (peeked) { |
583 | peeked = strip_whitespace(peeked); | 583 | strip_whitespace(peeked); |
584 | } | 584 | } |
585 | lines++; | 585 | lines++; |
586 | } while (peeked && strlen(peeked) == 0); | 586 | } while (peeked && strlen(peeked) == 0); |
@@ -663,7 +663,7 @@ bool read_config(FILE *file, struct sway_config *config, | |||
663 | read += length + 1; | 663 | read += length + 1; |
664 | } | 664 | } |
665 | 665 | ||
666 | line = strip_whitespace(line); | 666 | strip_whitespace(line); |
667 | if (line[0] == '#') { | 667 | if (line[0] == '#') { |
668 | free(line); | 668 | free(line); |
669 | continue; | 669 | continue; |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 61087733..04e14355 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -49,7 +49,7 @@ char *input_device_get_identifier(struct wlr_input_device *device) { | |||
49 | int vendor = device->vendor; | 49 | int vendor = device->vendor; |
50 | int product = device->product; | 50 | int product = device->product; |
51 | char *name = strdup(device->name); | 51 | char *name = strdup(device->name); |
52 | name = strip_whitespace(name); | 52 | strip_whitespace(name); |
53 | 53 | ||
54 | char *p = name; | 54 | char *p = name; |
55 | for (; *p; ++p) { | 55 | for (; *p; ++p) { |