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:
@ -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):"
|
||||
|
@ -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"']
|
||||
|
||||
|
@ -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)-")
|
||||
|
Reference in New Issue
Block a user