diff options
author | dequis <dx@dxzone.com.ar> | 2015-11-09 06:46:40 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-11-09 06:46:40 -0300 |
commit | b054ade4b90a05d778a64c63c0c834a126884aaa (patch) | |
tree | 0666e3201c484d72b4c858d8ba6dd0eb8587502b /src/core/misc.c | |
parent | 8736c12fc95ca977f4fc4a947c760bac651cd3af (diff) | |
download | irssi-b054ade4b90a05d778a64c63c0c834a126884aaa.zip |
strsplit_len: make it look more like the original version
Diffstat (limited to 'src/core/misc.c')
-rw-r--r-- | src/core/misc.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/core/misc.c b/src/core/misc.c index 4e8322fa..490b5a8f 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -995,10 +995,10 @@ char **strsplit_len(const char *str, int len, gboolean onspace) { char **ret = g_new(char *, 1); int n; - int split_offset = 0; + int offset; - for (n = 0; *str != '\0'; n++) { - split_offset = MIN(len, strlen(str)); + for (n = 0; *str != '\0'; n++, str += offset) { + offset = MIN(len, strlen(str)); if (onspace && strlen(str) > len) { /* * Try to find a space to split on and leave @@ -1007,15 +1007,13 @@ char **strsplit_len(const char *str, int len, gboolean onspace) int i; for (i = len - 1; i > 0; i--) { if (str[i] == ' ') { - split_offset = i; + offset = i; break; } } } - ret[n] = g_strndup(str, split_offset); + ret[n] = g_strndup(str, offset); ret = g_renew(char *, ret, n + 2); - - str += split_offset; } ret[n] = NULL; |