Skip to content
Myr

Two sub bugs fixed; two new gsub tests have been added.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

./jq --run-tests < tests/onig.test has been run successfully: ... Testing 'gsub("a";"b")' at line number 70 Testing 'gsub( "(.*)"; ""; "x")' at line number 74 ... 22 of 22 tests passed (0 malformed)

authored by pkoppstein · committed by Nicolas Williams · parent ec583de · Browse files · 2 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−4 removed

  • tests:+8 added−0 removed
  • other:+4 added−4 removed

2 files+12 added−4 removed

modified:src/builtin.jq+4 added-4 removed
123 unmodified lines
124 end ;125#126# If s contains capture variables, then create a capture object and pipe it to s127def sub($re; s; flags):128 def subg: explode | select(. != 103) | implode;129# "fla" should be flags with all occurrences of g removed; gs should be non-nil if flags has a g128 def subg: [explode[] | select(. != 103)] | implode;129 # "fla" should be flags with all occurrences of g removed; gs should be non-nil if flags has a g130 def sub1(fla; gs):131 def mysub:132 . as $in133 | [match($re; fla)]134 | if length == 0 then $in135 else .[0] as $edit136 | ($edit | .offset + .length) as $len137# # create the "capture" object:137 # create the "capture" object:138 | reduce ( $edit | .captures | .[] | select(.name != null) | { (.name) : .string } ) as $pair139 ({}; . + $pair)140 | $in[0:$edit.offset]141 + s142 + ($in[$len:] | if gs then mysub else . end)142 + ($in[$len:] | if length > 0 and gs then mysub else . end)143 end ;144 mysub ;145 (flags | index("g")) as $gs146 | (flags | if $gs then subg else . end) as $fla
143 unmodified lines
modified:tests/onig.test+8 added
65 unmodified lines
66gsub("(?<d>\\d)"; ":\(.d);")67"a1b2"68"a:1;b:2;"6970gsub("a";"b")71"aaaaa"72"bbbbb"7374gsub( "(.*)"; ""; "x")75""76""7778[.[] | scan(", ")]79["a,b, c, d, e,f",", a,b, c, d, e,f, "]80[", ",", ",", ",", ",", ",", ",", ",", "]81
17 unmodified lines