diff options
author | Nicolas Williams <nico@cryptonector.com> | 2015-01-13 18:56:53 -0600 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2015-01-14 01:32:11 -0600 |
commit | 8b5ff40402ab2d0f16f42207b0f475636483d288 (patch) | |
tree | 7a31c39aee0a722b4ffa9936d195abb11df4f5ab /jv.c | |
parent | d630597e870b9e1c14dfbc6a076f6f1c342b250f (diff) |
Split on empty sep: fix #552 moar
Diffstat (limited to 'jv.c')
-rw-r--r-- | jv.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -656,14 +656,20 @@ jv jv_string_split(jv j, jv sep) { assert(jv_get_refcnt(a) == 1); - for (p = jstr; p < jend; p = s + seplen) { - s = _jq_memmem(p, jend - p, sepstr, seplen); - if (s == NULL) - s = jend; - a = jv_array_append(a, jv_string_sized(p, s - p)); - // Add an empty string to denote that j ends on a sep - if (s + seplen == jend) - a = jv_array_append(a, jv_string("")); + if (seplen == 0) { + int c; + while ((jstr = jvp_utf8_next(jstr, jend, &c))) + a = jv_array_append(a, jv_string_append_codepoint(jv_string(""), c)); + } else { + for (p = jstr; p < jend; p = s + seplen) { + s = _jq_memmem(p, jend - p, sepstr, seplen); + if (s == NULL) + s = jend; + a = jv_array_append(a, jv_string_sized(p, s - p)); + // Add an empty string to denote that j ends on a sep + if (s + seplen == jend && seplen != 0) + a = jv_array_append(a, jv_string("")); + } } jv_free(j); jv_free(sep); |