1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (tr_setup_table): fix bug in r29146.

Initialize table even if cflag is 0; tr_find see whether
  del is empty or not.

* string.c (tr_find): nodel can't be NULL; if NULL, it means
  it is not specified.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-08-30 19:45:30 +00:00
parent 16ceba0396
commit d074ef4d60
6 changed files with 22 additions and 9 deletions

View file

@ -1,3 +1,12 @@
Tue Aug 31 03:42:14 2010 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (tr_setup_table): fix bug in r29146.
Initialize table even if cflag is 0; tr_find see whether
del is empty or not.
* string.c (tr_find): nodel can't be NULL; if NULL, it means
it is not specified.
Mon Aug 30 21:29:21 2010 Tanaka Akira <akr@fsij.org>
* ext/pathname/pathname.c (path_executable_real_p):

View file

@ -205,7 +205,7 @@ module Psych
quote = false
style = Nodes::Scalar::ANY
if o.index("\x00") || o.count("^ -~\t\r\n").fdiv(o.length) > 0.3
if o.index("\x00") || o.count("\x00-\x7F", "^ -~\t\r\n").fdiv(o.length) > 0.3
str = [o].pack('m').chomp
tag = '!binary' # FIXME: change to below when syck is removed
#tag = 'tag:yaml.org,2002:binary'

View file

@ -148,7 +148,7 @@ class String
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
end
def is_binary_data?
self.count("^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
self.count("\x00-\x7F", "^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
end
def String.yaml_new( klass, tag, val )
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"

View file

@ -76,9 +76,9 @@ class RDoc::Parser
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
true
elsif 0.respond_to? :fdiv then
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
else # HACK 1.8.6
(s.count("^ -~\t\r\n").to_f / s.size) > 0.3
(s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
end
end

View file

@ -5095,6 +5095,11 @@ tr_setup_table(VALUE str, char stable[256], int first,
ptable = *ctablep;
*ctablep = table;
}
else {
table = rb_hash_new();
ptable = *tablep;
*tablep = table;
}
if (first) {
for (i=0; i<256; i++) {
stable[i] = 1;
@ -5113,10 +5118,8 @@ tr_setup_table(VALUE str, char stable[256], int first,
if (!table) {
table = rb_hash_new();
if (!cflag) {
ptable = *tablep;
*tablep = table;
}
ptable = *tablep;
*tablep = table;
}
if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
rb_hash_aset(table, key, Qtrue);
@ -5144,7 +5147,7 @@ tr_find(unsigned int c, char table[256], VALUE del, VALUE nodel)
return TRUE;
}
}
else if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
else if (nodel && NIL_P(rb_hash_lookup(nodel, v))) {
return TRUE;
}
return FALSE;

View file

@ -502,6 +502,7 @@ class TestString < Test::Unit::TestCase
assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
assert_equal("a", "abc\u{3042 3044 3046}".delete("^a"))
assert_equal("bc\u{3042 3044 3046}", "abc\u{3042 3044 3046}".delete("a"))
assert_equal("\u3042", "abc\u{3042 3044 3046}".delete("^\u3042"))
end