Fix #552
This commit is contained in:
1 parent
d927a2c185
commit
60d1ecb58a
2 files changed
+8
-5
No files matched your search
@@ -648,19 +648,22 @@ jv jv_string_split(jv j, jv sep) {
|
|||||||
assert(jv_get_kind(j) == JV_KIND_STRING);
|
assert(jv_get_kind(j) == JV_KIND_STRING);
|
||||||
assert(jv_get_kind(sep) == JV_KIND_STRING);
|
assert(jv_get_kind(sep) == JV_KIND_STRING);
|
||||||
const char *jstr = jv_string_value(j);
|
const char *jstr = jv_string_value(j);
|
||||||
|
const char *jend = jstr + jv_string_length_bytes(jv_copy(j));
|
||||||
const char *sepstr = jv_string_value(sep);
|
const char *sepstr = jv_string_value(sep);
|
||||||
const char *p, *s;
|
const char *p, *s;
|
||||||
int jlen = jv_string_length_bytes(jv_copy(j));
|
|
||||||
int seplen = jv_string_length_bytes(jv_copy(sep));
|
int seplen = jv_string_length_bytes(jv_copy(sep));
|
||||||
jv a = jv_array();
|
jv a = jv_array();
|
||||||
|
|
||||||
assert(jv_get_refcnt(a) == 1);
|
assert(jv_get_refcnt(a) == 1);
|
||||||
|
|
||||||
for (p = jstr; p < jstr + jlen; p = s + seplen) {
|
for (p = jstr; p < jend; p = s + seplen) {
|
||||||
s = _jq_memmem(p, (jstr + jlen) - p, sepstr, seplen);
|
s = _jq_memmem(p, jend - p, sepstr, seplen);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
s = jstr + jlen;
|
s = jend;
|
||||||
a = jv_array_append(a, jv_string_sized(p, s - p));
|
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(""));
|
||||||
}
|
}
|
||||||
jv_free(j);
|
jv_free(j);
|
||||||
jv_free(sep);
|
jv_free(sep);
|
||||||
|
|||||||
+1
-1
@@ -898,7 +898,7 @@ sub("^(?<head>.)"; "Head=\(.head) Tail=")
|
|||||||
|
|
||||||
[.[] | split(", ")]
|
[.[] | split(", ")]
|
||||||
["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",""]]
|
||||||
|
|
||||||
########################
|
########################
|
||||||
[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")]]]
|
[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")]]]
|
||||||
|
|||||||
Reference in new issue
Block a user