From 73a184cc3a4ead8a3242a8f04c4e65fa99026eef Mon Sep 17 00:00:00 2001 From: naruse Date: Sun, 25 Mar 2012 09:20:04 +0000 Subject: * string.c (tr_setup_table): fix multiple non latin argument for non latin (over 256 characters) tr-like methods. [ruby-core:43371] [Bug #6167] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 7fd2d94e59..7d865d669a 100644 --- a/string.c +++ b/string.c @@ -5332,18 +5332,19 @@ tr_setup_table(VALUE str, char stable[TR_TABLE_SIZE], int first, else { VALUE key = UINT2NUM(c); - if (!table) { - table = rb_hash_new(); + if (!table && (first || *tablep || stable[256])) { if (cflag) { ptable = *ctablep; + table = ptable ? ptable : rb_hash_new(); *ctablep = table; } else { + table = rb_hash_new(); ptable = *tablep; *tablep = table; } } - if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) { + if (table && (!ptable || (cflag ^ !NIL_P(rb_hash_aref(ptable, key))))) { rb_hash_aset(table, key, Qtrue); } } @@ -5351,6 +5352,9 @@ tr_setup_table(VALUE str, char stable[TR_TABLE_SIZE], int first, for (i=0; i<256; i++) { stable[i] = stable[i] && buf[i]; } + if (!table && !cflag) { + *tablep = 0; + } } -- cgit v1.2.3