summaryrefslogtreecommitdiff
path: root/lib/jcode.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/jcode.rb')
-rw-r--r--lib/jcode.rb16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/jcode.rb b/lib/jcode.rb
index a7606d04ce..49262857a8 100644
--- a/lib/jcode.rb
+++ b/lib/jcode.rb
@@ -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