Пример #1
0
 public final RubyRegexp getRegexp(Ruby runtime, int index, String pattern, int options) {
   RubyRegexp regexp = regexps[index];
   if (regexp == null || runtime.getKCode() != regexp.getKCode()) {
     regexp = RubyRegexp.newRegexp(runtime, pattern, options);
     regexp.setLiteral();
     regexps[index] = regexp;
   }
   return regexp;
 }
Пример #2
0
  @Override
  public Object retrieve(InterpreterContext interp) {
    RubyRegexp reg =
        RubyRegexp.newRegexp(
            interp.getRuntime(), ((RubyString) regexp.retrieve(interp)).getByteList(), options);

    reg.setLiteral();

    return reg;
  }
  @Override
  public Object interpret(
      ThreadContext context,
      StaticScope currScope,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp) {
    // FIXME (from RegexpNode.java): 1.9 should care about internal or external encoding and not
    // kcode.
    // If we have a constant regexp string or if the regexp patterns asks for caching, cache the
    // regexp
    if (rubyRegexp == null
        || !options.isOnce()
        || context.runtime.getKCode() != rubyRegexp.getKCode()) {
      RubyString[] pieces = retrievePieces(context, self, currScope, currDynScope, temp);
      RubyString pattern = RubyRegexp.preprocessDRegexp(context.runtime, pieces, options);
      RubyRegexp re = RubyRegexp.newDRegexp(context.runtime, pattern, options);
      re.setLiteral();
      rubyRegexp = re;
    }

    return rubyRegexp;
  }