mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
0530ceb2b9
commit
d878585e5f
2 changed files with 18 additions and 12 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Thu Sep 6 13:28:51 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/jcode.rb (_regexp_quote): fix quote handling, again.
|
||||||
|
|
||||||
Thu Sep 6 07:28:56 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
Thu Sep 6 07:28:56 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
* file.c (rb_find_file_ext): add const qualifiers to ext.
|
* file.c (rb_find_file_ext): add const qualifiers to ext.
|
||||||
|
|
26
lib/jcode.rb
26
lib/jcode.rb
|
@ -9,7 +9,9 @@ class String
|
||||||
printf STDERR, "feel free for some warnings:\n" if $VERBOSE
|
printf STDERR, "feel free for some warnings:\n" if $VERBOSE
|
||||||
|
|
||||||
def _regex_quote(str)
|
def _regex_quote(str)
|
||||||
str.gsub(/[][\\]/, '\\\\\&')
|
str.gsub(/(\\[-\\])|\\(.)|([][\\])/) do
|
||||||
|
$1 || $2 || '\\' + $3
|
||||||
|
end
|
||||||
end
|
end
|
||||||
private :_regex_quote
|
private :_regex_quote
|
||||||
|
|
||||||
|
@ -95,15 +97,15 @@ class String
|
||||||
|
|
||||||
def _expand_ch str
|
def _expand_ch str
|
||||||
a = []
|
a = []
|
||||||
str.scan(/(.)-(.)|(.)/m) do |r|
|
str.scan(/(?:\\([-\\]))|(.)-(.)|(.)/m) do
|
||||||
if $3
|
if s = $1 || $4
|
||||||
a.push $3
|
a.push s
|
||||||
elsif $1.length != $2.length
|
elsif $2.length != $3.length
|
||||||
next
|
next
|
||||||
elsif $1.length == 1
|
elsif $2.length == 1
|
||||||
$1[0].upto($2[0]) { |c| a.push c.chr }
|
$2[0].upto($3[0]) { |c| a.push c.chr }
|
||||||
else
|
else
|
||||||
$1.upto($2) { |c| a.push c }
|
$2.upto($3) { |c| a.push c }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
a
|
a
|
||||||
|
@ -132,7 +134,7 @@ class String
|
||||||
last = /.$/.match(to)[0]
|
last = /.$/.match(to)[0]
|
||||||
self.gsub!(pattern, last)
|
self.gsub!(pattern, last)
|
||||||
else
|
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
|
self.gsub!(pattern) do |c| h[c] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -166,12 +168,12 @@ class String
|
||||||
def tr_s!(from, to)
|
def tr_s!(from, to)
|
||||||
return self.delete!(from) if to.length == 0
|
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] == ?^
|
if from[0] == ?^
|
||||||
last = /.$/.match(to)[0]
|
last = /.$/.match(to)[0]
|
||||||
self.gsub!(pattern, last)
|
self.gsub!(pattern, last)
|
||||||
else
|
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
|
self.gsub!(pattern) do h[$1] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue