diff options
Diffstat (limited to 'sway/stringop.c')
-rw-r--r-- | sway/stringop.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/sway/stringop.c b/sway/stringop.c index 624c8401..1dff97bf 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -1,38 +1,37 @@ | |||
1 | #include "stringop.h" | ||
1 | #include <stdlib.h> | 2 | #include <stdlib.h> |
2 | #include <stdio.h> | 3 | #include <stdio.h> |
3 | #include <strings.h> | ||
4 | #include <ctype.h> | ||
5 | #include "stringop.h" | ||
6 | #include "string.h" | 4 | #include "string.h" |
7 | #include "list.h" | 5 | #include "list.h" |
6 | #include <strings.h> | ||
8 | 7 | ||
9 | /* Note: This returns 8 characters for trimmed_start per tab character. */ | 8 | /* Note: This returns 8 characters for trimmed_start per tab character. */ |
10 | void strip_whitespace(char *str) { | 9 | char *strip_whitespace(char *_str, int *trimmed_start) { |
11 | int shift = 0; | 10 | *trimmed_start = 0; |
12 | int bpair = 1; | 11 | if (*_str == '\0') |
13 | int in_str = 0, in_ch = 0; | 12 | return _str; |
14 | while (*str) { | 13 | char *strold = _str; |
15 | str[-shift] = str[0]; | 14 | while (*_str == ' ' || *_str == '\t') { |
16 | if (*str == '"' && !in_ch) { | 15 | if (*_str == '\t') { |
17 | in_str = !in_str; | 16 | *trimmed_start += 8; |
18 | } else if (*str == '\'' && !in_str) { | 17 | } else { |
19 | in_ch = !in_ch; | 18 | *trimmed_start += 1; |
20 | } else if (!in_ch && !in_str) { | ||
21 | if (isblank(*str)) { | ||
22 | if (bpair) { | ||
23 | ++shift; | ||
24 | } | ||
25 | bpair=1; | ||
26 | } else { | ||
27 | bpair = 0; | ||
28 | } | ||
29 | } | 19 | } |
30 | ++str; | 20 | _str++; |
31 | } | 21 | } |
32 | str[-shift-bpair] = 0; | 22 | char *str = malloc(strlen(_str) + 1); |
23 | strcpy(str, _str); | ||
24 | free(strold); | ||
25 | int i; | ||
26 | for (i = 0; str[i] != '\0'; ++i); | ||
27 | do { | ||
28 | i--; | ||
29 | } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); | ||
30 | str[i + 1] = '\0'; | ||
31 | return str; | ||
33 | } | 32 | } |
34 | 33 | ||
35 | void strip_comments(char *str) { | 34 | char *strip_comments(char *str) { |
36 | int in_string = 0, in_character = 0; | 35 | int in_string = 0, in_character = 0; |
37 | int i = 0; | 36 | int i = 0; |
38 | while (str[i] != '\0') { | 37 | while (str[i] != '\0') { |
@@ -48,6 +47,7 @@ void strip_comments(char *str) { | |||
48 | } | 47 | } |
49 | ++i; | 48 | ++i; |
50 | } | 49 | } |
50 | return str; | ||
51 | } | 51 | } |
52 | 52 | ||
53 | list_t *split_string(const char *str, const char *delims) { | 53 | list_t *split_string(const char *str, const char *delims) { |