diff options
Diffstat (limited to 'sway/stringop.c')
-rw-r--r-- | sway/stringop.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/sway/stringop.c b/sway/stringop.c index 450d5cd0..bbc0bcdf 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -53,9 +53,8 @@ char *strip_comments(char *str) { | |||
53 | list_t *split_string(const char *str, const char *delims) { | 53 | list_t *split_string(const char *str, const char *delims) { |
54 | list_t *res = create_list(); | 54 | list_t *res = create_list(); |
55 | int i, j; | 55 | int i, j; |
56 | int len = strlen(str); | 56 | for (i = 0, j = 0; i < strlen(str) + 1; ++i) { |
57 | for (i = 0, j = 0; i < len + 1; ++i) { | 57 | if (strchr(delims, str[i]) || i == strlen(str)) { |
58 | if (strchr(delims, str[i]) || i == len) { | ||
59 | if (i - j == 0) { | 58 | if (i - j == 0) { |
60 | continue; | 59 | continue; |
61 | } | 60 | } |
@@ -64,7 +63,7 @@ list_t *split_string(const char *str, const char *delims) { | |||
64 | left[i - j] = 0; | 63 | left[i - j] = 0; |
65 | list_add(res, left); | 64 | list_add(res, left); |
66 | j = i + 1; | 65 | j = i + 1; |
67 | while (j <= len && str[j] && strchr(delims, str[j])) { | 66 | while (j <= strlen(str) && str[j] && strchr(delims, str[j])) { |
68 | j++; | 67 | j++; |
69 | i++; | 68 | i++; |
70 | } | 69 | } |
@@ -111,44 +110,40 @@ int unescape_string(char *string) { | |||
111 | for (i = 0; string[i]; ++i) { | 110 | for (i = 0; string[i]; ++i) { |
112 | if (string[i] == '\\') { | 111 | if (string[i] == '\\') { |
113 | --len; | 112 | --len; |
114 | int shift = 0; | ||
115 | switch (string[++i]) { | 113 | switch (string[++i]) { |
116 | case '0': | 114 | case '0': |
117 | string[i - 1] = '\0'; | 115 | string[i - 1] = '\0'; |
118 | shift = 1; | 116 | memmove(string + i, string + i + 1, len - i); |
119 | break; | 117 | break; |
120 | case 'a': | 118 | case 'a': |
121 | string[i - 1] = '\a'; | 119 | string[i - 1] = '\a'; |
122 | shift = 1; | 120 | memmove(string + i, string + i + 1, len - i); |
123 | break; | 121 | break; |
124 | case 'b': | 122 | case 'b': |
125 | string[i - 1] = '\b'; | 123 | string[i - 1] = '\b'; |
126 | shift = 1; | 124 | memmove(string + i, string + i + 1, len - i); |
127 | break; | 125 | break; |
128 | case 't': | 126 | case 't': |
129 | string[i - 1] = '\t'; | 127 | string[i - 1] = '\t'; |
130 | shift = 1; | 128 | memmove(string + i, string + i + 1, len - i); |
131 | break; | 129 | break; |
132 | case 'n': | 130 | case 'n': |
133 | string[i - 1] = '\n'; | 131 | string[i - 1] = '\n'; |
134 | shift = 1; | 132 | memmove(string + i, string + i + 1, len - i); |
135 | break; | 133 | break; |
136 | case 'v': | 134 | case 'v': |
137 | string[i - 1] = '\v'; | 135 | string[i - 1] = '\v'; |
138 | shift = 1; | 136 | memmove(string + i, string + i + 1, len - i); |
139 | break; | 137 | break; |
140 | case 'f': | 138 | case 'f': |
141 | string[i - 1] = '\f'; | 139 | string[i - 1] = '\f'; |
142 | shift = 1; | 140 | memmove(string + i, string + i + 1, len - i); |
143 | break; | 141 | break; |
144 | case 'r': | 142 | case 'r': |
145 | string[i - 1] = '\r'; | 143 | string[i - 1] = '\r'; |
146 | shift = 1; | 144 | memmove(string + i, string + i + 1, len - i); |
147 | break; | 145 | break; |
148 | } | 146 | } |
149 | if (shift) { | ||
150 | memmove(string + i, string + i + shift, len - i); | ||
151 | } | ||
152 | } | 147 | } |
153 | } | 148 | } |
154 | return len; | 149 | return len; |