From 33ae76a09c7e71863bdc147f16843ff12354a409 Mon Sep 17 00:00:00 2001 From: naruse Date: Fri, 25 Jan 2008 16:40:02 +0000 Subject: * string.c (rb_str_usascii_new{,2}: defined. (rb_str_new): set US-ASCII and ENC_CODERANGE_7BIT when empty string. * encoding.c (rb_usascii_encoding, rb_usascii_encindex): defined. (rb_enc_inspect, enc_name, rb_locale_charmap, rb_enc_name_list_i): use rb_str_ascii_new. * array.c (recursive_join, inspect_ary): ditto. * object.c (nil_to_s, nil_inspect, true_to_s, false_to_s, rb_mod_to_s): ditto. * hash.c (inspect_hash, rb_hash_inspect, rb_f_getenv, env_fetch, env_clear, env_to_s, env_inspect): ditto. * numeric.c (flo_to_s, int_chr, rb_fix2str): ditto. * bignum.c (rb_big2str): ditto. * file.c (rb_file_ftype, rb_file_s_dirname, rb_file_s_extname, file_inspect_join, Init_file): ditto. * test/ruby/test_ruby_m17n.rb: add checks for encoding of string. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index f6376c3e1..c3b169a70 100644 --- a/numeric.c +++ b/numeric.c @@ -504,9 +504,9 @@ flo_to_s(VALUE flt) char *p, *e; if (isinf(value)) - return rb_str_new2(value < 0 ? "-Infinity" : "Infinity"); + return rb_usascii_str_new2(value < 0 ? "-Infinity" : "Infinity"); else if(isnan(value)) - return rb_str_new2("NaN"); + return rb_usascii_str_new2("NaN"); sprintf(buf, "%#.15g", value); /* ensure to print decimal point */ if (!(e = strchr(buf, 'e'))) { @@ -522,7 +522,7 @@ flo_to_s(VALUE flt) while (p[-1]=='0' && ISDIGIT(p[-2])) p--; memmove(p, e, strlen(e)+1); - return rb_str_new2(buf); + return rb_usascii_str_new2(buf); } /* @@ -1851,7 +1851,12 @@ int_chr(int argc, VALUE *argv, VALUE num) rb_raise(rb_eRangeError, "%ld out of char range", i); } c = i; - return rb_str_new(&c, 1); + if (i < 0x80) { + return rb_usascii_str_new(&c, 1); + } + else { + return rb_str_new(&c, 1); + } case 1: break; default: @@ -1968,7 +1973,7 @@ rb_fix2str(VALUE x, int base) rb_raise(rb_eArgError, "invalid radix %d", base); } if (val == 0) { - return rb_str_new2("0"); + return rb_usascii_str_new2("0"); } if (val < 0) { val = -val; @@ -1982,7 +1987,7 @@ rb_fix2str(VALUE x, int base) *--b = '-'; } - return rb_str_new2(b); + return rb_usascii_str_new2(b); } /* -- cgit