Restore split/1; don't use regexp (fix #576)

This commit is contained in:
Nicolas Williams committed 2014-10-03 17:58:45 -05:00
1 parent 07d8d5c5ef
commit 1796a716ea
3 files changed
+7 -11

No files matched your search

-1
View File
@@ -1046,7 +1046,6 @@ static const char* const jq_builtins[] = {
// //
// split emits an array for backward compatibility // split emits an array for backward compatibility
"def split($re; flags): [ splits($re; flags) ];", "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 // If s contains capture variables, then create a capture object and pipe it to s
"def sub($re; s):" "def sub($re; s):"
+2 -5
View File
@@ -1736,7 +1736,7 @@ sections:
input: ("", "") input: ("", "")
output: ['[]', '[]'] output: ['[]', '[]']
- title: "`split(regex)`, `split(regex; flags)`" - title: "`split(regex; flags)`"
body: | body: |
For backwards compatibility, `split` emits an array of the strings 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 themselves are excluded. If regex is the empty string, then the first
match will be the empty string. 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: example:
- program: 'split(", *")' - program: 'split(", *"; null)'
input: '"ab,cd, ef"' input: '"ab,cd, ef"'
output: ['"ab","cd","ef"'] output: ['"ab","cd","ef"']
+5 -5
View File
@@ -869,16 +869,16 @@ capture("(?<a>[a-z]+)-(?<n>[0-9]+)")
[.[] | 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(", *")], 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"],[",",", ",", ",", ",","]],[[":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"],[", ",", ",", "]],[[":a,b, c, d, e,f, "],[":a,b:c:d:e,f:"],[", ",", ",", ",", ",", "]]]
# reference to named captures # reference to named captures
gsub("(?<x>.)[^a]*"; "+\(.x)-") gsub("(?<x>.)[^a]*"; "+\(.x)-")