1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* sprintf.c (rb_str_format): "%#.0o" should keep prefix where

"%#.0x" should not.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-03-01 00:38:33 +00:00
parent 4e6e5a4316
commit 18e70b266f
3 changed files with 16 additions and 8 deletions

View file

@ -1,3 +1,8 @@
Sat Mar 1 09:36:08 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_str_format): "%#.0o" should keep prefix where
"%#.0x" should not.
Sat Mar 1 02:35:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Sat Mar 1 02:35:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (big2str_find_n1): check integer overflow. * bignum.c (big2str_find_n1): check integer overflow.

View file

@ -684,18 +684,21 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
pp++; pp++;
} }
} }
if (prefix && !prefix[1]) { if (prefix && !prefix[1]) { /* octal */
if (dots) { if (dots) {
prefix = 0; prefix = 0;
} }
else if (len == 1 && *s == '0') { else if (len == 1 && *s == '0') {
if (flags & FPREC) len = 0; len = 0;
prefix = 0; if (flags & FPREC) prec--;
} }
else if ((flags & FPREC) && (prec > len)) { else if ((flags & FPREC) && (prec > len)) {
prefix = 0; prefix = 0;
} }
} }
else if (len == 1 && *s == '0') {
prefix = 0;
}
if (prefix) { if (prefix) {
width -= strlen(prefix); width -= strlen(prefix);
} }
@ -705,8 +708,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
} }
else { else {
if (prec < len) { if (prec < len) {
if ((flags & FPREC) && len == 1 && *s == '0') len = 0; if (!prefix && prec == 0 && len == 1 && *s == '0') len = 0;
else prec = len; prec = len;
} }
width -= prec; width -= prec;
} }

View file

@ -145,7 +145,7 @@ class TestSprintfComb < Test::Unit::TestCase
radix = 2 radix = 2
digitmap = {0 => '0', 1 => '1'} digitmap = {0 => '0', 1 => '1'}
complement = !pl && !sp complement = !pl && !sp
prefix = '0b' if hs prefix = '0b' if hs && v != 0
when 'd' when 'd'
radix = 10 radix = 10
digitmap = {} digitmap = {}
@ -161,13 +161,13 @@ class TestSprintfComb < Test::Unit::TestCase
digitmap = {} digitmap = {}
16.times {|i| digitmap[i] = i.to_s(16).upcase } 16.times {|i| digitmap[i] = i.to_s(16).upcase }
complement = !pl && !sp complement = !pl && !sp
prefix = '0X' if hs prefix = '0X' if hs && v != 0
when 'x' when 'x'
radix = 16 radix = 16
digitmap = {} digitmap = {}
16.times {|i| digitmap[i] = i.to_s(16) } 16.times {|i| digitmap[i] = i.to_s(16) }
complement = !pl && !sp complement = !pl && !sp
prefix = '0x' if hs prefix = '0x' if hs && v != 0
else else
raise "unexpected type: #{type.inspect}" raise "unexpected type: #{type.inspect}"
end end