From d878585e5f3bc9d23df7704a817a7a10f7427e7f Mon Sep 17 00:00:00 2001 From: eban Date: Thu, 6 Sep 2001 04:34:36 +0000 Subject: [PATCH] * 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 --- ChangeLog | 4 ++++ lib/jcode.rb | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c087967bf..95d3a3df6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Sep 6 13:28:51 2001 WATANABE Hirofumi + + * lib/jcode.rb (_regexp_quote): fix quote handling, again. + Thu Sep 6 07:28:56 2001 Nobuyoshi Nakada * file.c (rb_find_file_ext): add const qualifiers to ext. 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