Skip to content
Permalink
Browse files
[Truffle] Initial implementation of Regexp.{quote,escape}.
  • Loading branch information
nirvdrum committed Jan 16, 2015
1 parent 83f055a commit 715de4224b6ecd593724c1a423d669a0072dde77
Showing with 32 additions and 2 deletions.
  1. +32 −0 core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
  2. +0 −2 spec/truffle/tags/core/regexp/quote_tags.txt
@@ -25,8 +25,11 @@
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyRegexp;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.util.ByteList;

import static org.jruby.util.StringSupport.CR_7BIT;

@CoreClass(name = "Regexp")
public abstract class RegexpNodes {

@@ -342,6 +345,35 @@ public int options(RubyRegexp regexp) {

}

@CoreMethod(names = { "quote", "escape" }, needsSelf = false, onSingleton = true, required = 1)
public abstract static class QuoteNode extends CoreMethodNode {

public QuoteNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public QuoteNode(QuoteNode prev) {
super(prev);
}

@Specialization
public RubyString quote(RubyString raw) {
notDesignedForCompilation();

boolean isAsciiOnly = raw.getByteList().getEncoding().isAsciiCompatible() && raw.scanForCodeRange() == CR_7BIT;

return getContext().makeString(org.jruby.RubyRegexp.quote19(raw.getBytes(), isAsciiOnly));
}

@Specialization
public RubyString quote(RubySymbol raw) {
notDesignedForCompilation();

return quote(raw.toRubyString());
}

}

@CoreMethod(names = "source")
public abstract static class SourceNode extends CoreMethodNode {

@@ -1,5 +1,3 @@
fails:Regexp.quote escapes any characters with special meaning in a regular expression
fails:Regexp.quote works with symbols
fails:Regexp.quote sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String
fails:Regexp.quote sets the encoding of the result to the encoding of the String if any non-US-ASCII characters are present in an input String with valid encoding
fails:Regexp.quote sets the encoding of the result to ASCII-8BIT if any non-US-ASCII characters are present in an input String with invalid encoding

0 comments on commit 715de42

Please sign in to comment.