* 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:
parent
16ceba0396
commit
d074ef4d60
@ -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>
|
Mon Aug 30 21:29:21 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/pathname/pathname.c (path_executable_real_p):
|
* ext/pathname/pathname.c (path_executable_real_p):
|
||||||
|
@ -205,7 +205,7 @@ module Psych
|
|||||||
quote = false
|
quote = false
|
||||||
style = Nodes::Scalar::ANY
|
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
|
str = [o].pack('m').chomp
|
||||||
tag = '!binary' # FIXME: change to below when syck is removed
|
tag = '!binary' # FIXME: change to below when syck is removed
|
||||||
#tag = 'tag:yaml.org,2002:binary'
|
#tag = 'tag:yaml.org,2002:binary'
|
||||||
|
@ -148,7 +148,7 @@ class String
|
|||||||
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
|
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
|
||||||
end
|
end
|
||||||
def is_binary_data?
|
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
|
end
|
||||||
def String.yaml_new( klass, tag, val )
|
def String.yaml_new( klass, tag, val )
|
||||||
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
|
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
|
||||||
|
@ -76,9 +76,9 @@ class RDoc::Parser
|
|||||||
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
|
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
|
||||||
true
|
true
|
||||||
elsif 0.respond_to? :fdiv then
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
13
string.c
13
string.c
@ -5095,6 +5095,11 @@ tr_setup_table(VALUE str, char stable[256], int first,
|
|||||||
ptable = *ctablep;
|
ptable = *ctablep;
|
||||||
*ctablep = table;
|
*ctablep = table;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
table = rb_hash_new();
|
||||||
|
ptable = *tablep;
|
||||||
|
*tablep = table;
|
||||||
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
for (i=0; i<256; i++) {
|
for (i=0; i<256; i++) {
|
||||||
stable[i] = 1;
|
stable[i] = 1;
|
||||||
@ -5113,10 +5118,8 @@ tr_setup_table(VALUE str, char stable[256], int first,
|
|||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
table = rb_hash_new();
|
table = rb_hash_new();
|
||||||
if (!cflag) {
|
ptable = *tablep;
|
||||||
ptable = *tablep;
|
*tablep = table;
|
||||||
*tablep = table;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
|
if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
|
||||||
rb_hash_aset(table, key, Qtrue);
|
rb_hash_aset(table, key, Qtrue);
|
||||||
@ -5144,7 +5147,7 @@ tr_find(unsigned int c, char table[256], VALUE del, VALUE nodel)
|
|||||||
return TRUE;
|
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 TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -502,6 +502,7 @@ class TestString < Test::Unit::TestCase
|
|||||||
assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
|
assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
|
||||||
|
|
||||||
assert_equal("a", "abc\u{3042 3044 3046}".delete("^a"))
|
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"))
|
assert_equal("\u3042", "abc\u{3042 3044 3046}".delete("^\u3042"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user