ruby-changes:17441
From: naruse <ko1@a...>
Date: Tue, 12 Oct 2010 15:18:16 +0900 (JST)
Subject: [ruby-changes:17441] Ruby:r29446 (trunk): * numeric.c (rb_enc_uint_chr): split from int_chr.
naruse 2010-10-12 15:18:08 +0900 (Tue, 12 Oct 2010) New Revision: 29446 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29446 Log: * 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. Modified files: trunk/ChangeLog trunk/include/ruby/encoding.h trunk/numeric.c Index: include/ruby/encoding.h =================================================================== --- include/ruby/encoding.h (revision 29445) +++ include/ruby/encoding.h (revision 29446) @@ -104,6 +104,7 @@ char* rb_enc_nth(const char*, const char*, long, rb_encoding*); VALUE rb_obj_encoding(VALUE); VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc); +VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc); VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *); VALUE rb_str_export_to_enc(VALUE, rb_encoding *); Index: ChangeLog =================================================================== --- ChangeLog (revision 29445) +++ ChangeLog (revision 29446) @@ -1,3 +1,11 @@ +Tue Oct 12 15:10:31 2010 NARUSE, Yui <naruse@r...> + + * 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. + Tue Oct 12 14:04:41 2010 NARUSE, Yui <naruse@r...> * numeric.c (int_chr): a codepoint of Ruby M17N must be 32bit Index: numeric.c =================================================================== --- numeric.c (revision 29445) +++ numeric.c (revision 29446) @@ -2057,6 +2057,19 @@ 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 @@ -2073,16 +2086,14 @@ 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(); @@ -2105,13 +2116,7 @@ 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); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/