Skip to content

Commit

Permalink
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 32 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Original file line number Diff line number Diff line change
@@ -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 {

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/regexp/quote_tags.txt
Original file line number Diff line number Diff line change
@@ -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.