1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

2000-06-12

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-06-12 07:48:31 +00:00
parent cfdf994071
commit 548b5143db
19 changed files with 500 additions and 98 deletions

View file

@ -108,10 +108,6 @@ class String
h
end
def bsquote(str)
str.gsub(/\\/, '\\\\\\\\')
end
HashCache = {}
TrPatternCache = {}
DeletePatternCache = {}
@ -122,7 +118,7 @@ class String
def tr!(from, to)
return self.delete!(from) if to.length == 0
pattern = TrPatternCache[from] ||= /[#{bsquote(from)}]/
pattern = TrPatternCache[from] ||= /[#{Regexp::quote(from)}]/
if from[0] == ?^
last = /.$/.match(to)[0]
self.gsub!(pattern, last)
@ -137,7 +133,7 @@ class String
end
def delete!(del)
self.gsub!(DeletePatternCache[del] ||= /[#{bsquote(del)}]+/, '')
self.gsub!(DeletePatternCache[del] ||= /[#{Regexp::quote(del)}]+/, '')
end
def delete(del)
@ -147,7 +143,7 @@ class String
def squeeze!(del=nil)
pattern =
if del
SqueezePatternCache[del] ||= /([#{bsquote(del)}])\1+/
SqueezePatternCache[del] ||= /([#{Regexp::quote(del)}])\1+/
else
/(.|\n)\1+/
end
@ -161,7 +157,7 @@ class String
def tr_s!(from, to)
return self.delete!(from) if to.length == 0
pattern = SqueezePatternCache[from] ||= /([#{bsquote(from)}])\1+"/ #"
pattern = SqueezePatternCache[from] ||= /([#{Regexp::quote(from)}])\1+"/ #"
if from[0] == ?^
last = /.$/.match(to)[0]
self.gsub!(pattern, last)
@ -194,11 +190,11 @@ class String
def each_char
if iterator?
scan(/./) do |x|
scan(/./m) do |x|
yield x
end
else
scan(/./)
scan(/./m)
end
end