diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-02 08:06:46 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-02 08:06:46 +0000 |
commit | 230b8b524da27baaee1ded6bfc8bdef842940400 (patch) | |
tree | 5a1dfb3ad743ee6958bb43efc437ac0ed260a8fe /numeric.c | |
parent | 55eecb54e79260379480dacb13272b10699ec5a8 (diff) |
merges r29446 and r29448 from trunk into ruby_1_9_2.
--
* numeric.c (rb_enc_uint_chr): split from int_chr.
* numeric.c (int_chr): use rb_enc_uint_chr.
* include/ruby/encoding.h (rb_enc_uint_chr): added.
--
* io.c (rb_io_ungetc): use unsigned int for GB18030.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@30038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -2038,6 +2038,19 @@ int_pred(VALUE num) return rb_funcall(num, '-', 1, INT2FIX(1)); } +VALUE +rb_enc_uint_chr(unsigned int code, rb_encoding *enc) +{ + int n; + VALUE str; + if ((n = rb_enc_codelen(code, enc)) <= 0) { + rb_raise(rb_eRangeError, "%d out of char range", code); + } + str = rb_enc_str_new(0, n, enc); + rb_enc_mbcput(code, RSTRING_PTR(str), enc); + return str; +} + /* * call-seq: * int.chr([encoding]) -> string @@ -2054,16 +2067,14 @@ static VALUE int_chr(int argc, VALUE *argv, VALUE num) { char c; - int n; - uint32_t i = NUM2UINT(num); + unsigned int i = NUM2UINT(num); rb_encoding *enc; - VALUE str; switch (argc) { case 0: if (i < 0) { out_of_range: - rb_raise(rb_eRangeError, "%"PRIdVALUE " out of char range", i); + rb_raise(rb_eRangeError, "%d out of char range", i); } if (0xff < i) { enc = rb_default_internal_encoding(); @@ -2086,13 +2097,7 @@ int_chr(int argc, VALUE *argv, VALUE num) enc = rb_to_encoding(argv[0]); if (!enc) enc = rb_ascii8bit_encoding(); decode: -#if SIZEOF_INT < SIZEOF_VALUE - if (i > UINT_MAX) goto out_of_range; -#endif - if (i < 0 || (n = rb_enc_codelen(i, enc)) <= 0) goto out_of_range; - str = rb_enc_str_new(0, n, enc); - rb_enc_mbcput(i, RSTRING_PTR(str), enc); - return str; + return rb_enc_uint_chr(i, enc); } /* |