Split on empty sep: fix #552 moar
This commit is contained in:
1 parent
d630597e87
commit
8b5ff40402
2 files changed
+18
-8
No files matched your search
@@ -656,14 +656,20 @@ jv jv_string_split(jv j, jv sep) {
|
|||||||
|
|
||||||
assert(jv_get_refcnt(a) == 1);
|
assert(jv_get_refcnt(a) == 1);
|
||||||
|
|
||||||
for (p = jstr; p < jend; p = s + seplen) {
|
if (seplen == 0) {
|
||||||
s = _jq_memmem(p, jend - p, sepstr, seplen);
|
int c;
|
||||||
if (s == NULL)
|
while ((jstr = jvp_utf8_next(jstr, jend, &c)))
|
||||||
s = jend;
|
a = jv_array_append(a, jv_string_append_codepoint(jv_string(""), c));
|
||||||
a = jv_array_append(a, jv_string_sized(p, s - p));
|
} else {
|
||||||
// Add an empty string to denote that j ends on a sep
|
for (p = jstr; p < jend; p = s + seplen) {
|
||||||
if (s + seplen == jend)
|
s = _jq_memmem(p, jend - p, sepstr, seplen);
|
||||||
a = jv_array_append(a, jv_string(""));
|
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(j);
|
||||||
jv_free(sep);
|
jv_free(sep);
|
||||||
|
|||||||
@@ -900,6 +900,10 @@ sub("^(?<head>.)"; "Head=\(.head) Tail=")
|
|||||||
["a,b, c, d, e,f",", a,b, c, d, e,f, "]
|
["a,b, c, d, e,f",", a,b, c, d, e,f, "]
|
||||||
[["a,b","c","d","e,f"],["","a,b","c","d","e,f",""]]
|
[["a,b","c","d","e,f"],["","a,b","c","d","e,f",""]]
|
||||||
|
|
||||||
|
split("")
|
||||||
|
"abc"
|
||||||
|
["a","b","c"]
|
||||||
|
|
||||||
########################
|
########################
|
||||||
[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")]]]
|
[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")]]]
|
||||||
["a,b, c, d, e,f",", a,b, c, d, e,f, "]
|
["a,b, c, d, e,f",", a,b, c, d, e,f, "]
|
||||||
|
|||||||
Reference in new issue
Block a user