Skip to content

Commit

Permalink
[Truffle] Implemented String#[Regexp].
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Feb 9, 2015
1 parent 1027a1e commit b40c330
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/element_reference_tags.txt
Expand Up @@ -7,12 +7,9 @@ fails:String#[] with Range always taints resulting strings when self is tainted
fails:String#[] with Range returns subclass instances
fails:String#[] with Range calls to_int on range arguments
fails:String#[] with Range works with Range subclasses
fails:String#[] with Regexp returns the matching portion of self
fails:String#[] with Regexp returns nil if there is no match
fails:String#[] with Regexp always taints resulting strings when self or regexp is tainted
fails:String#[] with Regexp returns an untrusted string if the regexp is untrusted
fails:String#[] with Regexp returns subclass instances
fails:String#[] with Regexp sets $~ to MatchData when there is a match and nil when there's none
fails:String#[] with Regexp, index returns the capture for the given index
fails:String#[] with Regexp, index always taints resulting strings when self or regexp is tainted
fails:String#[] with Regexp, index returns an untrusted string if the regexp is untrusted
Expand Down
Expand Up @@ -313,6 +313,19 @@ public Object slice(RubyString string, int start, int length) {
}
}

@Specialization
public Object slice(RubyString string, RubyRegexp regexp, UndefinedPlaceholder capture) {
notDesignedForCompilation();

final Object matchData = regexp.matchCommon(string.getBytes(), false, false);

if (matchData == getContext().getCoreLibrary().getNilObject()) {
return matchData;
}

return ((RubyMatchData) matchData).getValues()[0];
}

}

@CoreMethod(names = "[]=", required = 2, lowerFixnumParameters = 0)
Expand Down

0 comments on commit b40c330

Please sign in to comment.