ruby-changes:4158
From: ko1@a...
Date: Sat, 1 Mar 2008 09:38:48 +0900 (JST)
Subject: [ruby-changes:4158] matz - Ruby:r15648 (trunk): * sprintf.c (rb_str_format): "%#.0o" should keep prefix where
matz 2008-03-01 09:38:33 +0900 (Sat, 01 Mar 2008) New Revision: 15648 Modified files: trunk/ChangeLog trunk/sprintf.c trunk/test/ruby/test_sprintf_comb.rb Log: * sprintf.c (rb_str_format): "%#.0o" should keep prefix where "%#.0x" should not. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15648&r2=15647&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/sprintf.c?r1=15648&r2=15647&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_sprintf_comb.rb?r1=15648&r2=15647&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 15647) +++ ChangeLog (revision 15648) @@ -1,3 +1,8 @@ +Sat Mar 1 09:36:08 2008 Yukihiro Matsumoto <matz@r...> + + * sprintf.c (rb_str_format): "%#.0o" should keep prefix where + "%#.0x" should not. + Sat Mar 1 02:35:08 2008 Nobuyoshi Nakada <nobu@r...> * bignum.c (big2str_find_n1): check integer overflow. Index: sprintf.c =================================================================== --- sprintf.c (revision 15647) +++ sprintf.c (revision 15648) @@ -684,18 +684,21 @@ pp++; } } - if (prefix && !prefix[1]) { + if (prefix && !prefix[1]) { /* octal */ if (dots) { prefix = 0; } else if (len == 1 && *s == '0') { - if (flags & FPREC) len = 0; - prefix = 0; + len = 0; + if (flags & FPREC) prec--; } else if ((flags & FPREC) && (prec > len)) { prefix = 0; } } + else if (len == 1 && *s == '0') { + prefix = 0; + } if (prefix) { width -= strlen(prefix); } @@ -705,8 +708,8 @@ } else { if (prec < len) { - if ((flags & FPREC) && len == 1 && *s == '0') len = 0; - else prec = len; + if (!prefix && prec == 0 && len == 1 && *s == '0') len = 0; + prec = len; } width -= prec; } Index: test/ruby/test_sprintf_comb.rb =================================================================== --- test/ruby/test_sprintf_comb.rb (revision 15647) +++ test/ruby/test_sprintf_comb.rb (revision 15648) @@ -145,7 +145,7 @@ radix = 2 digitmap = {0 => '0', 1 => '1'} complement = !pl && !sp - prefix = '0b' if hs + prefix = '0b' if hs && v != 0 when 'd' radix = 10 digitmap = {} @@ -161,13 +161,13 @@ digitmap = {} 16.times {|i| digitmap[i] = i.to_s(16).upcase } complement = !pl && !sp - prefix = '0X' if hs + prefix = '0X' if hs && v != 0 when 'x' radix = 16 digitmap = {} 16.times {|i| digitmap[i] = i.to_s(16) } complement = !pl && !sp - prefix = '0x' if hs + prefix = '0x' if hs && v != 0 else raise "unexpected type: #{type.inspect}" end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/