diff options
author | eban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-09-06 04:34:36 +0000 |
---|---|---|
committer | eban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-09-06 04:34:36 +0000 |
commit | d878585e5f3bc9d23df7704a817a7a10f7427e7f (patch) | |
tree | 5136972a68cfbb44092f248fea5e41192a48f064 /lib/jcode.rb | |
parent | 0530ceb2b964e974ad7e25dd041b54a3ef577677 (diff) |
* lib/jcode.rb (_regexp_quote): fix quote handling, again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/jcode.rb')
-rw-r--r-- | lib/jcode.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/jcode.rb b/lib/jcode.rb index e7cb967588..c3c3ad1001 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -9,7 +9,9 @@ class String printf STDERR, "feel free for some warnings:\n" if $VERBOSE def _regex_quote(str) - str.gsub(/[][\\]/, '\\\\\&') + str.gsub(/(\\[-\\])|\\(.)|([][\\])/) do + $1 || $2 || '\\' + $3 + end end private :_regex_quote @@ -95,15 +97,15 @@ class String def _expand_ch str a = [] - str.scan(/(.)-(.)|(.)/m) do |r| - if $3 - a.push $3 - elsif $1.length != $2.length - next - elsif $1.length == 1 - $1[0].upto($2[0]) { |c| a.push c.chr } + str.scan(/(?:\\([-\\]))|(.)-(.)|(.)/m) do + if s = $1 || $4 + a.push s + elsif $2.length != $3.length + next + elsif $2.length == 1 + $2[0].upto($3[0]) { |c| a.push c.chr } else - $1.upto($2) { |c| a.push c } + $2.upto($3) { |c| a.push c } end end a @@ -132,7 +134,7 @@ class String last = /.$/.match(to)[0] self.gsub!(pattern, last) else - h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to) + h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to) self.gsub!(pattern) do |c| h[c] end end end @@ -166,12 +168,12 @@ class String def tr_s!(from, to) return self.delete!(from) if to.length == 0 - pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+"/ + pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+/ if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) else - h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to) + h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to) self.gsub!(pattern) do h[$1] end end end |