diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-16 08:11:01 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-16 08:11:01 -0400 |
commit | 51f935987c401bb85859bcedca03ee7ac588e96b (patch) | |
tree | cc8ffeb1d52d770548fd99a9d0b7bbef18f90ead /sway/stringop.c | |
parent | 76ec9422a66c4ff59dc0590d80f7f6e931fd8e1a (diff) | |
parent | ae536c21d3bcab7758f4a47cbf4556c518245a7b (diff) |
Merge pull request #39 from SirCmpwn/revert-38-master
Revert "get/set_userdata stores swayc_t *, fixed memory leak, minor c…
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) { list_t *split_string(const char *str, const char *delims) { list_t *res = create_list(); int i, j; - int len = strlen(str); - for (i = 0, j = 0; i < len + 1; ++i) { - if (strchr(delims, str[i]) || i == len) { + for (i = 0, j = 0; i < strlen(str) + 1; ++i) { + if (strchr(delims, str[i]) || i == strlen(str)) { if (i - j == 0) { continue; } @@ -64,7 +63,7 @@ list_t *split_string(const char *str, const char *delims) { left[i - j] = 0; list_add(res, left); j = i + 1; - while (j <= len && str[j] && strchr(delims, str[j])) { + while (j <= strlen(str) && str[j] && strchr(delims, str[j])) { j++; i++; } @@ -111,44 +110,40 @@ int unescape_string(char *string) { for (i = 0; string[i]; ++i) { if (string[i] == '\\') { --len; - int shift = 0; switch (string[++i]) { case '0': string[i - 1] = '\0'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 'a': string[i - 1] = '\a'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 'b': string[i - 1] = '\b'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 't': string[i - 1] = '\t'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 'n': string[i - 1] = '\n'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 'v': string[i - 1] = '\v'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 'f': string[i - 1] = '\f'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; case 'r': string[i - 1] = '\r'; - shift = 1; + memmove(string + i, string + i + 1, len - i); break; } - if (shift) { - memmove(string + i, string + i + shift, len - i); - } } } return len; |