1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

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

This commit is contained in:
Nicolas Williams
2014-10-03 17:52:11 -05:00
parent 07d8d5c5ef
commit 1796a716ea
3 changed files with 7 additions and 11 deletions

View File

@ -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):"

View File

@ -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"']

View File

@ -869,16 +869,16 @@ capture("(?<a>[a-z]+)-(?<n>[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("(?<x>.)[^a]*"; "+\(.x)-")