예제 #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
파일: Regexp.java 프로젝트: rsutphin/jruby
  @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;
  }