Example #1
0
 private RubyArray match_array(Ruby runtime, int start) {
   check();
   if (regs == null) {
     if (start != 0) return runtime.newEmptyArray();
     if (begin == -1) {
       return runtime.newArray(runtime.getNil());
     } else {
       RubyString ss = makeShared(runtime, str, begin, end - begin);
       if (isTaint()) ss.setTaint(true);
       return runtime.newArray(ss);
     }
   } else {
     RubyArray arr = runtime.newArray(regs.numRegs - start);
     for (int i = start; i < regs.numRegs; i++) {
       if (regs.beg[i] == -1) {
         arr.append(runtime.getNil());
       } else {
         RubyString ss = makeShared(runtime, str, regs.beg[i], regs.end[i] - regs.beg[i]);
         if (isTaint()) ss.setTaint(true);
         arr.append(ss);
       }
     }
     return arr;
   }
 }
Example #2
0
 @JRubyMethod(compat = CompatVersion.RUBY1_8)
 public IRubyObject select(ThreadContext context, Block block) {
   Ruby runtime = context.getRuntime();
   final RubyArray result;
   if (regs == null) {
     if (begin < 0) return runtime.newEmptyArray();
     IRubyObject s = str.substr(runtime, begin, end - begin);
     s.setTaint(isTaint());
     result = block.yield(context, s).isTrue() ? runtime.newArray(s) : runtime.newEmptyArray();
   } else {
     result = runtime.newArray();
     boolean taint = isTaint();
     for (int i = 0; i < regs.numRegs; i++) {
       IRubyObject s = str.substr(runtime, regs.beg[i], regs.end[i] - regs.beg[i]);
       if (taint) s.setTaint(true);
       if (block.yield(context, s).isTrue()) result.append(s);
     }
   }
   return result;
 }