Skip to content

Commit

Permalink
Restore split/1; don't use regexp (fix #576)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Oct 3, 2014
1 parent 07d8d5c commit 1796a71
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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):"
Expand Down
7 changes: 2 additions & 5 deletions docs/content/3.manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"']

Expand Down
10 changes: 5 additions & 5 deletions tests/all.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)-")
Expand Down

0 comments on commit 1796a71

Please sign in to comment.