From 1796a716eaebb12caa0cb3441a1e50a180f5f754 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Fri, 3 Oct 2014 17:52:11 -0500 Subject: [PATCH] Restore `split/1`; don't use regexp (fix #576) --- builtin.c | 1 - docs/content/3.manual/manual.yml | 7 ++----- tests/all.test | 10 +++++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/builtin.c b/builtin.c index 4dc34a59..6f668942 100644 --- a/builtin.c +++ b/builtin.c @@ -1046,7 +1046,6 @@ static const char* const jq_builtins[] = { // // split emits an array for backward compatibility "def split($re; flags): [ splits($re; flags) ];", - "def split($re): [ splits($re; null) ];", // // If s contains capture variables, then create a capture object and pipe it to s "def sub($re; s):" diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index a6dfd81d..16bee1eb 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -1736,7 +1736,7 @@ sections: input: ("", "") output: ['[]', '[]'] - - title: "`split(regex)`, `split(regex; flags)`" + - title: "`split(regex; flags)`" body: | For backwards compatibility, `split` emits an array of the strings @@ -1746,11 +1746,8 @@ sections: themselves are excluded. If regex is the empty string, then the first match will be the empty string. - `split(regex)` can be thought of as a wrapper around `splits(regex)`, - and similarly for `split(regex; flags)`. - example: - - program: 'split(", *")' + - program: 'split(", *"; null)' input: '"ab,cd, ef"' output: ['"ab","cd","ef"'] diff --git a/tests/all.test b/tests/all.test index d1cdc2ca..18078909 100644 --- a/tests/all.test +++ b/tests/all.test @@ -869,16 +869,16 @@ capture("(?[a-z]+)-(?[0-9]+)") [.[] | 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"]] ######################## -[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")], split(", *")]] +[.[]|[[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"],[",",", ",", ",", ",","],["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(", +")], split(", +")]] +[.[]|[[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"],[", ",", ",", "],["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:"],[", ",", ",", ",", ",", "]]] # reference to named captures gsub("(?.)[^a]*"; "+\(.x)-")