diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-09-19 07:54:28 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-09-19 07:54:28 +0000 |
commit | f1bb1f584899eeec1227a6d7fcf4b7730a485821 (patch) | |
tree | 0e2fa33a858e6237dd6e9b81d83c8a9b2b9c632a /lib/jcode.rb | |
parent | 053140491c5594ee81064ef3dc19d32b3e907794 (diff) |
000919
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/jcode.rb')
-rw-r--r-- | lib/jcode.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/jcode.rb b/lib/jcode.rb index 923153a637..77aedaa3bc 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -4,6 +4,11 @@ $vsave, $VERBOSE = $VERBOSE, false class String printf STDERR, "feel free for some warnings:\n" if $VERBOSE + def _regex_quote(str) + a = str.gsub(/\W/){|s| if s == "-" then s else "\\\\#{s}" end} + end + private :_regex_quote + PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]' PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]' PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' @@ -118,7 +123,7 @@ class String def tr!(from, to) return self.delete!(from) if to.length == 0 - pattern = TrPatternCache[from] ||= /[#{Regexp::quote(from)}]/ + pattern = TrPatternCache[from] ||= /[#{_regex_quote(from)}]/ if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) @@ -133,7 +138,7 @@ class String end def delete!(del) - self.gsub!(DeletePatternCache[del] ||= /[#{Regexp::quote(del)}]+/, '') + self.gsub!(DeletePatternCache[del] ||= /[#{_regex_quote(del)}]+/, '') end def delete(del) @@ -143,7 +148,7 @@ class String def squeeze!(del=nil) pattern = if del - SqueezePatternCache[del] ||= /([#{Regexp::quote(del)}])\1+/ + SqueezePatternCache[del] ||= /([#{_regex_quote(del)}])\1+/ else /(.|\n)\1+/ end @@ -157,7 +162,7 @@ class String def tr_s!(from, to) return self.delete!(from) if to.length == 0 - pattern = SqueezePatternCache[from] ||= /([#{Regexp::quote(from)}])\1+"/ #" + pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+"/ if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) |