summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-30 06:01:14 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-30 06:01:14 +0000
commit1a02ec9170db08c0574978a9d09478422ff261fa (patch)
treec5f97a74a1ad88099f171497ac2321c5f3de136a /string.c
parent96ebf3bdd9e41b9d500534a134a35070e2947e23 (diff)
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/string.c b/string.c
index a0d3b60188..5c80903ade 100644
--- a/string.c
+++ b/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) == '^') {
cflag = 1;
tr.p += l;
+
+ table = rb_hash_new();
+ ptable = *ctablep;
+ *ctablep = table;
}
if (first) {
for (i=0; i<256; i++) {
@@ -5109,11 +5113,7 @@ tr_setup_table(VALUE str, char stable[256], int first,
if (!table) {
table = rb_hash_new();
- if (cflag) {
- ptable = *ctablep;
- *ctablep = table;
- }
- else {
+ if (!cflag) {
ptable = *tablep;
*tablep = table;
}
@@ -5138,11 +5138,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;
}
}
@@ -5443,16 +5447,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++;