mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6913b2734a
commit
e960fffda1
3 changed files with 25 additions and 11 deletions
|
@ -1,3 +1,11 @@
|
|||
Tue Oct 12 15:10:31 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* numeric.c (int_chr): a codepoint of Ruby M17N must be 32bit
|
||||
|
|
|
@ -104,6 +104,7 @@ long rb_enc_strlen(const char*, const char*, rb_encoding*);
|
|||
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 *);
|
||||
|
|
27
numeric.c
27
numeric.c
|
@ -2057,6 +2057,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
|
||||
|
@ -2073,16 +2086,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();
|
||||
|
@ -2105,13 +2116,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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue