Skip to content
Myr

Split on empty sep: fix #552 moar

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nicolas Williams · committed by Nicolas Williams · parent d630597 · Browse files · 2 files+18 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+18 added−8 removed

  • tests:+4 added−0 removed
  • other:+14 added−8 removed

2 files+18 added−8 removed

modified:tests/all.test+4 added
898 unmodified lines
899[.[] | split(", ")]900["a,b, c, d, e,f",", a,b, c, d, e,f, "]901[["a,b","c","d","e,f"],["","a,b","c","d","e,f",""]]902903split("")904"abc"905["a","b","c"]906907########################908[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")]]]909["a,b, c, d, e,f",", a,b, c, d, e,f, "]910[[["a:b, c, d, e,f"],["a:b:c:d:e:f"],[",",", ",", ",", ",","]],[[":a,b, c, d, e,f, "],[":a:b:c:d:e:f:"],[", ",",",", ",", ",", ",",",", "]]]
245 unmodified lines
modified:jv.c+14 added-8 removed
654 unmodified lines
655 jv a = jv_array();656657 assert(jv_get_refcnt(a) == 1);658659 if (seplen == 0) {660 int c;661 while ((jstr = jvp_utf8_next(jstr, jend, &c)))662 a = jv_array_append(a, jv_string_append_codepoint(jv_string(""), c));663 } else {659 for (p = jstr; p < jend; p = s + seplen) {660 s = _jq_memmem(p, jend - p, sepstr, seplen);661 if (s == NULL)662 s = jend;663 a = jv_array_append(a, jv_string_sized(p, s - p));664 // Add an empty string to denote that j ends on a sep665 if (s + seplen == jend)666 a = jv_array_append(a, jv_string(""));664 for (p = jstr; p < jend; p = s + seplen) {665 s = _jq_memmem(p, jend - p, sepstr, seplen);666 if (s == NULL)667 s = jend;668 a = jv_array_append(a, jv_string_sized(p, s - p));669 // Add an empty string to denote that j ends on a sep670 if (s + seplen == jend && seplen != 0)671 a = jv_array_append(a, jv_string(""));672 }673 }674 jv_free(j);675 jv_free(sep);676 return a;
621 unmodified lines