|
31 | 31 | import org.joni.Option;
|
32 | 32 | import org.joni.Regex;
|
33 | 33 | import org.joni.Region;
|
34 |
| -import org.jruby.Ruby; |
35 |
| -import org.jruby.RubyBoolean; |
36 |
| -import org.jruby.RubyClass; |
37 |
| -import org.jruby.RubyException; |
38 |
| -import org.jruby.RubyFixnum; |
39 |
| -import org.jruby.RubyMatchData; |
40 |
| -import org.jruby.RubyNumeric; |
41 |
| -import org.jruby.RubyObject; |
42 |
| -import org.jruby.RubyRegexp; |
43 |
| -import org.jruby.RubyString; |
44 |
| -import org.jruby.RubyThread; |
| 34 | +import org.jruby.*; |
45 | 35 | import org.jruby.anno.JRubyClass;
|
46 | 36 | import org.jruby.anno.JRubyMethod;
|
47 | 37 | import org.jruby.common.IRubyWarnings.ID;
|
@@ -626,4 +616,48 @@ private IRubyObject inspect2() {
|
626 | 616 | public static IRubyObject mustCversion(IRubyObject recv) {
|
627 | 617 | return recv;
|
628 | 618 | }
|
| 619 | + |
| 620 | + @JRubyMethod(name = "size") |
| 621 | + public IRubyObject size(ThreadContext context) { |
| 622 | + if (!isMatched()) return context.nil; |
| 623 | + return context.runtime.newFixnum(regs.numRegs); |
| 624 | + } |
| 625 | + |
| 626 | + @JRubyMethod(name = "captures") |
| 627 | + public IRubyObject captures(ThreadContext context) { |
| 628 | + int i, numRegs; |
| 629 | + RubyArray newAry; |
| 630 | + |
| 631 | + if (!isMatched()) return context.nil; |
| 632 | + |
| 633 | + Ruby runtime = context.runtime; |
| 634 | + |
| 635 | + numRegs = regs.numRegs; |
| 636 | + newAry = RubyArray.newArray(runtime, numRegs); |
| 637 | + |
| 638 | + for (i = 1; i < numRegs; i++) { |
| 639 | + IRubyObject str = extractRange(runtime, lastPos + regs.beg[i], |
| 640 | + lastPos + regs.end[i]); |
| 641 | + newAry.push(str); |
| 642 | + } |
| 643 | + |
| 644 | + return newAry; |
| 645 | + } |
| 646 | + |
| 647 | + @JRubyMethod(name = "values_at", rest = true) |
| 648 | + public IRubyObject values_at(ThreadContext context, IRubyObject[] args) { |
| 649 | + int i; |
| 650 | + RubyArray newAry; |
| 651 | + |
| 652 | + if (!isMatched()) return context.nil; |
| 653 | + |
| 654 | + Ruby runtime = context.runtime; |
| 655 | + |
| 656 | + newAry = RubyArray.newArray(runtime, args.length); |
| 657 | + for (i = 0; i < args.length; i++) { |
| 658 | + newAry.push(op_aref(context, args[i])); |
| 659 | + } |
| 660 | + |
| 661 | + return newAry; |
| 662 | + } |
629 | 663 | }
|
0 commit comments