mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (tr_setup_table): initialize negating table when
negating string is given. [ruby-core:31851] * string.c (tr_find): add a sentence for the time when target characters include negating one. * string.c (rb_str_count): move definition. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
96ebf3bdd9
commit
1a02ec9170
3 changed files with 27 additions and 9 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Mon Aug 30 15:00:13 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (tr_setup_table): initialize negating table when
|
||||||
|
negating string is given. [ruby-core:31851]
|
||||||
|
|
||||||
|
* string.c (tr_find): add a sentence for the time when
|
||||||
|
target characters include negating one.
|
||||||
|
|
||||||
|
* string.c (rb_str_count): move definition.
|
||||||
|
|
||||||
Mon Aug 30 07:32:41 2010 Tanaka Akira <akr@fsij.org>
|
Mon Aug 30 07:32:41 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/pathname/pathname.c (path_.executable_p): Pathname#.executable?
|
* ext/pathname/pathname.c (path_.executable_p): Pathname#.executable?
|
||||||
|
|
21
string.c
21
string.c
|
@ -5090,6 +5090,10 @@ tr_setup_table(VALUE str, char stable[256], int first,
|
||||||
if (RSTRING_LEN(str) > 1 && rb_enc_ascget(tr.p, tr.pend, &l, enc) == '^') {
|
if (RSTRING_LEN(str) > 1 && rb_enc_ascget(tr.p, tr.pend, &l, enc) == '^') {
|
||||||
cflag = 1;
|
cflag = 1;
|
||||||
tr.p += l;
|
tr.p += l;
|
||||||
|
|
||||||
|
table = rb_hash_new();
|
||||||
|
ptable = *ctablep;
|
||||||
|
*ctablep = table;
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
for (i=0; i<256; i++) {
|
for (i=0; i<256; i++) {
|
||||||
|
@ -5109,11 +5113,7 @@ tr_setup_table(VALUE str, char stable[256], int first,
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
table = rb_hash_new();
|
table = rb_hash_new();
|
||||||
if (cflag) {
|
if (!cflag) {
|
||||||
ptable = *ctablep;
|
|
||||||
*ctablep = table;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptable = *tablep;
|
ptable = *tablep;
|
||||||
*tablep = table;
|
*tablep = table;
|
||||||
}
|
}
|
||||||
|
@ -5138,11 +5138,15 @@ tr_find(unsigned int c, char table[256], VALUE del, VALUE nodel)
|
||||||
else {
|
else {
|
||||||
VALUE v = UINT2NUM(c);
|
VALUE v = UINT2NUM(c);
|
||||||
|
|
||||||
if (del && !NIL_P(rb_hash_lookup(del, v))) {
|
if (del) {
|
||||||
if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
|
if (!NIL_P(rb_hash_lookup(del, v)) &&
|
||||||
|
(!nodel || NIL_P(rb_hash_lookup(nodel, v)))) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5443,16 +5447,15 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
|
||||||
i = 0;
|
i = 0;
|
||||||
while (s < send) {
|
while (s < send) {
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
int clen;
|
|
||||||
|
|
||||||
if (ascompat && (c = *(unsigned char*)s) < 0x80) {
|
if (ascompat && (c = *(unsigned char*)s) < 0x80) {
|
||||||
clen = 1;
|
|
||||||
if (table[c]) {
|
if (table[c]) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
int clen;
|
||||||
c = rb_enc_codepoint_len(s, send, &clen, enc);
|
c = rb_enc_codepoint_len(s, send, &clen, enc);
|
||||||
if (tr_find(c, table, del, nodel)) {
|
if (tr_find(c, table, del, nodel)) {
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -479,6 +479,8 @@ class TestString < Test::Unit::TestCase
|
||||||
assert_equal(4, a.count(S("hello"), S("^l")))
|
assert_equal(4, a.count(S("hello"), S("^l")))
|
||||||
assert_equal(4, a.count(S("ej-m")))
|
assert_equal(4, a.count(S("ej-m")))
|
||||||
assert_equal(0, S("y").count(S("a\\-z")))
|
assert_equal(0, S("y").count(S("a\\-z")))
|
||||||
|
assert_equal(5, "abc\u{3042 3044 3046}".count("^a"))
|
||||||
|
assert_equal(5, "abc\u{3042 3044 3046}".count("^\u3042"))
|
||||||
|
|
||||||
assert_raise(ArgumentError) { "foo".count }
|
assert_raise(ArgumentError) { "foo".count }
|
||||||
end
|
end
|
||||||
|
@ -498,6 +500,9 @@ class TestString < Test::Unit::TestCase
|
||||||
assert_equal(true, "a\u0101".delete("\u0101").ascii_only?)
|
assert_equal(true, "a\u0101".delete("\u0101").ascii_only?)
|
||||||
assert_equal(true, "a\u3041".delete("\u3041").ascii_only?)
|
assert_equal(true, "a\u3041".delete("\u3041").ascii_only?)
|
||||||
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("\u3042", "abc\u{3042 3044 3046}".delete("^\u3042"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete!
|
def test_delete!
|
||||||
|
|
Loading…
Reference in a new issue