summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-23 10:02:41 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-23 10:02:41 +0000
commitd9cd722638146ace80396e32a0d74a42893a8015 (patch)
tree654afbcd7c3b15c6da71d32d40efe031aa8cf6b4 /string.c
parent0d069bd2df3ea467efb1d9d3a64ae2334b5cc241 (diff)
merges r29146 and r29148 from trunk into ruby_1_9_2.
-- * 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. -- * 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/branches/ruby_1_9_2@29569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/string.c b/string.c
index 1b06370bb7..cd0103f8d5 100644
--- a/string.c
+++ b/string.c
@@ -5035,6 +5035,15 @@ tr_setup_table(VALUE str, char stable[256], int first,
if (RSTRING_LEN(str) > 1 && rb_enc_ascget(tr.p, tr.pend, &l, enc) == '^') {
cflag = 1;
tr.p += l;
+
+ table = rb_hash_new();
+ ptable = *ctablep;
+ *ctablep = table;
+ }
+ else {
+ table = rb_hash_new();
+ ptable = *tablep;
+ *tablep = table;
}
if (first) {
for (i=0; i<256; i++) {
@@ -5054,14 +5063,8 @@ tr_setup_table(VALUE str, char stable[256], int first,
if (!table) {
table = rb_hash_new();
- if (cflag) {
- ptable = *ctablep;
- *ctablep = table;
- }
- else {
- ptable = *tablep;
- *tablep = table;
- }
+ ptable = *tablep;
+ *tablep = table;
}
if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
rb_hash_aset(table, key, Qtrue);
@@ -5083,11 +5086,15 @@ tr_find(unsigned int c, char table[256], VALUE del, VALUE nodel)
else {
VALUE v = UINT2NUM(c);
- if (del && !NIL_P(rb_hash_lookup(del, v))) {
- if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
+ if (del) {
+ if (!NIL_P(rb_hash_lookup(del, v)) &&
+ (!nodel || NIL_P(rb_hash_lookup(nodel, v)))) {
return TRUE;
}
}
+ else if (nodel && NIL_P(rb_hash_lookup(nodel, v))) {
+ return TRUE;
+ }
return FALSE;
}
}
@@ -5388,16 +5395,15 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
i = 0;
while (s < send) {
unsigned int c;
- int clen;
if (ascompat && (c = *(unsigned char*)s) < 0x80) {
- clen = 1;
if (table[c]) {
i++;
}
s++;
}
else {
+ int clen;
c = rb_enc_codepoint_len(s, send, &clen, enc);
if (tr_find(c, table, del, nodel)) {
i++;