diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-12 09:25:33 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-12 09:25:33 +0000 |
commit | 1e22306569e43251f946145ab49662ee6fe76151 (patch) | |
tree | 8f249cc195222582048d55e4ea661cdb30570330 | |
parent | 2d8612e9666a9fb0ddf240b2920dc4cf69632ad8 (diff) | |
download | ruby-1e22306569e43251f946145ab49662ee6fe76151.tar.gz |
* string.c (rb_str_concat): use unsigned int for GB18030.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | string.c | 23 | ||||
-rw-r--r-- | test/ruby/test_m17n_comb.rb | 3 |
3 files changed, 14 insertions, 16 deletions
@@ -1,3 +1,7 @@ +Tue Oct 12 18:25:04 2010 NARUSE, Yui <naruse@ruby-lang.org> + + * string.c (rb_str_concat): use unsigned int for GB18030. + Tue Oct 12 17:53:49 2010 NARUSE, Yui <naruse@ruby-lang.org> * numeric (check_uint): the mask must refer to VALUE. @@ -2021,37 +2021,28 @@ rb_str_append(VALUE str, VALUE str2) VALUE rb_str_concat(VALUE str1, VALUE str2) { - SIGNED_VALUE lc; + unsigned int lc; if (FIXNUM_P(str2)) { - lc = FIX2LONG(str2); - if (lc < 0) - rb_raise(rb_eRangeError, "negative argument"); + lc = FIX2UINT(str2); } else if (TYPE(str2) == T_BIGNUM) { - if (!RBIGNUM_SIGN(str2)) - rb_raise(rb_eRangeError, "negative argument"); - lc = rb_big2ulong(str2); + lc = NUM2UINT(str2); } else { return rb_str_append(str1, str2); } -#if SIZEOF_INT < SIZEOF_VALUE - if ((VALUE)lc > UINT_MAX) { - rb_raise(rb_eRangeError, "%"PRIuVALUE" out of char range", lc); - } -#endif { rb_encoding *enc = STR_ENC_GET(str1); long pos = RSTRING_LEN(str1); int cr = ENC_CODERANGE(str1); - int c, len; + int len; - if ((len = rb_enc_codelen(c = (int)lc, enc)) <= 0) { - rb_raise(rb_eRangeError, "%u invalid char", c); + if ((len = rb_enc_codelen(lc, enc)) <= 0) { + rb_raise(rb_eRangeError, "%u invalid char", lc); } rb_str_resize(str1, pos+len); - rb_enc_mbcput(c, RSTRING_PTR(str1)+pos, enc); + rb_enc_mbcput(lc, RSTRING_PTR(str1)+pos, enc); ENC_CODERANGE_SET(str1, cr); return str1; } diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb index cf80377172..e730f6f0e8 100644 --- a/test/ruby/test_m17n_comb.rb +++ b/test/ruby/test_m17n_comb.rb @@ -346,6 +346,9 @@ class TestM17NComb < Test::Unit::TestCase assert_raise(Encoding::CompatibilityError) { s << s2 } end } + + assert_equal("A\x84\x31\xA4\x39".force_encoding("GB18030"), + "A".force_encoding("GB18030") << 0x8431A439) end def test_str_aref |