Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Pulled in String#slice! from Rubinius.
  • Loading branch information
nirvdrum committed Feb 28, 2015
1 parent 0fbfcfc commit 6285100
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
15 changes: 1 addition & 14 deletions spec/truffle/tags/core/string/slice_tags.txt
Expand Up @@ -20,49 +20,36 @@ fails:String#slice with String taints resulting strings when other is tainted
fails:String#slice with String doesn't set $~
fails:String#slice with String returns nil if there is no match
fails:String#slice with String returns a subclass instance when given a subclass instance
fails:String#slice! with index deletes and return the char at the given position
fails:String#slice! with index returns nil if idx is outside of self
fails:String#slice! with index raises a RuntimeError if self is frozen
fails:String#slice! with index calls to_int on index
fails:String#slice! with index returns the character given by the character index
fails:String#slice! with index, length deletes and returns the substring at idx and the given length
fails:String#slice! with index, length always taints resulting strings when self is tainted
fails:String#slice! with index, length raises a RuntimeError if self is frozen
fails:String#slice! with index, length calls to_int on idx and length
fails:String#slice! with index, length returns subclass instances
fails:String#slice! with index, length returns the substring given by the character offsets
fails:String#slice! Range deletes and return the substring given by the offsets of the range
fails:String#slice! Range returns nil if the given range is out of self
fails:String#slice! Range always taints resulting strings when self is tainted
fails:String#slice! Range returns subclass instances
fails:String#slice! Range calls to_int on range arguments
fails:String#slice! Range works with Range subclasses
fails:String#slice! Range returns the substring given by the character offsets of the range
fails:String#slice! Range raises a RuntimeError on a frozen instance that is modified
fails:String#slice! Range raises a RuntimeError on a frozen instance that would not be modified
fails:String#slice! with Regexp deletes and returns the first match from self
fails:String#slice! with Regexp returns nil if there was no match
fails:String#slice! with Regexp always taints resulting strings when self or regexp is tainted
fails:String#slice! with Regexp doesn't taint self when regexp is tainted
fails:String#slice! with Regexp returns subclass instances
fails:String#slice! with Regexp sets $~ to MatchData when there is a match and nil when there's none
fails:String#slice! with Regexp raises a RuntimeError on a frozen instance that is modified
fails:String#slice! with Regexp raises a RuntimeError on a frozen instance that would not be modified
fails:String#slice! with Regexp, index deletes and returns the capture for idx from self
fails:String#slice! with Regexp, index always taints resulting strings when self or regexp is tainted
fails:String#slice! with Regexp, index doesn't taint self when regexp is tainted
fails:String#slice! with Regexp, index returns nil if there was no match
fails:String#slice! with Regexp, index returns nil if there is no capture for idx
fails:String#slice! with Regexp, index calls to_int on idx
fails:String#slice! with Regexp, index returns subclass instances
fails:String#slice! with Regexp, index returns the encoding aware capture for the given index
fails:String#slice! with Regexp, index raises a RuntimeError if self is frozen
fails:String#slice! with String removes and returns the first occurrence of other_str from self
fails:String#slice! with String taints resulting strings when other is tainted
fails:String#slice! with String doesn't set $~
fails:String#slice! with String returns nil if self does not contain other
fails:String#slice! with String doesn't call to_str on its argument
fails:String#slice! with String returns a subclass instance when given a subclass instance
fails:String#slice! with String raises a RuntimeError if self is frozen
fails:String#slice! with Regexp, index accepts a Float for capture index
fails:String#slice! with Regexp, index calls #to_int to convert an Object to capture index

31 changes: 31 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/string.rb
Expand Up @@ -47,6 +47,36 @@ def chomp(separator=$/)
str.chomp!(separator) || str
end

def slice!(one, two=undefined)
Rubinius.check_frozen
# This is un-DRY, but it's a simple manual argument splitting. Keeps
# the code fast and clean since the sequence are pretty short.
#
if undefined.equal?(two)
result = slice(one)

if one.kind_of? Regexp
lm = Regexp.last_match
self[one] = '' if result
Regexp.last_match = lm
else
self[one] = '' if result
end
else
result = slice(one, two)

if one.kind_of? Regexp
lm = Regexp.last_match
self[one, two] = '' if result
Regexp.last_match = lm
else
self[one, two] = '' if result
end
end

result
end

def each_line(sep=$/)
return to_enum(:each_line, sep) unless block_given?

Expand Down Expand Up @@ -351,6 +381,7 @@ def gsub!(pattern, replacement=undefined)
self
end


def to_sub_replacement(result, match)
index = 0
while index < @num_bytes
Expand Down

0 comments on commit 6285100

Please sign in to comment.