diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-15 08:31:58 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-15 08:31:58 +0000 |
commit | 8a0cd16de1b523fa80ec0e02ae7f114d28fa41b7 (patch) | |
tree | 656aea4dc99e2783673a5d74e14fc64d78aee266 | |
parent | 6a443e2eb2ce6dcde4d01be4a48fd1158dc96356 (diff) | |
download | ruby-8a0cd16de1b523fa80ec0e02ae7f114d28fa41b7.tar.gz |
Revert "* sprintf.c (rb_str_format): fix: sprintf with hex format and"
This reverts commit a160986d90cf90a86e01d60eddb04ffe0e584c36.
Revert wrong commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | sprintf.c | 12 | ||||
-rw-r--r-- | test/ruby/test_sprintf.rb | 10 | ||||
-rw-r--r-- | test/ruby/test_sprintf_comb.rb | 6 |
4 files changed, 14 insertions, 19 deletions
@@ -5,11 +5,6 @@ Fri Oct 15 17:26:57 2010 NARUSE, Yui <naruse@ruby-lang.org> * pack.c (pack_unpack): ditto. -Thu Oct 14 09:46:28 2010 NARUSE, Yui <naruse@ruby-lang.org> - - * sprintf.c (rb_str_format): fix: sprintf with hex format and - precision includes wrong dots. - Fri Oct 15 16:40:37 2010 NARUSE, Yui <naruse@ruby-lang.org> * pack.c (pack_pack): fix more than one modifiers appear in the @@ -844,7 +844,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } else { s = nbuf; - if (v < 0 && !(flags & FPREC0)) { + if (v < 0) { dots = 1; } snprintf(fbuf, sizeof(fbuf), "%%l%c", *p == 'X' ? 'x' : *p); @@ -892,8 +892,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) tmp1 = tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val)); s = RSTRING_PTR(tmp); if (*s == '-') { - if (!(flags & FPREC0)) - dots = 1; + dots = 1; if (base == 10) { rb_warning("negative number for %%u specifier"); } @@ -926,11 +925,14 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } } if (prefix && !prefix[1]) { /* octal */ - if (len == 1 && *s == '0') { + if (dots) { + prefix = 0; + } + else if (len == 1 && *s == '0') { len = 0; if (flags & FPREC) prec--; } - else if ((flags & FPREC) && (prec > len) && v >= 0) { + else if ((flags & FPREC) && (prec > len)) { prefix = 0; } } diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb index 24b6a34b3a..96a1b62bb7 100644 --- a/test/ruby/test_sprintf.rb +++ b/test/ruby/test_sprintf.rb @@ -24,12 +24,12 @@ class TestSprintf < Test::Unit::TestCase assert_equal("0000", sprintf("%.4b", 0)) assert_equal("0001", sprintf("%.4b", 1)) assert_equal("0010", sprintf("%.4b", 2)) - assert_equal("1111", sprintf("%.4b", -1)) + assert_equal("..11", sprintf("%.4b", -1)) assert_equal(" 0000", sprintf("%6.4b", 0)) assert_equal(" 0001", sprintf("%6.4b", 1)) assert_equal(" 0010", sprintf("%6.4b", 2)) - assert_equal(" 1111", sprintf("%6.4b", -1)) + assert_equal(" ..11", sprintf("%6.4b", -1)) assert_equal(" 0", sprintf("%#4b", 0)) assert_equal(" 0b1", sprintf("%#4b", 1)) @@ -44,12 +44,12 @@ class TestSprintf < Test::Unit::TestCase assert_equal("0000", sprintf("%#.4b", 0)) assert_equal("0b0001", sprintf("%#.4b", 1)) assert_equal("0b0010", sprintf("%#.4b", 2)) - assert_equal("0b1111", sprintf("%#.4b", -1)) + assert_equal("0b..11", sprintf("%#.4b", -1)) assert_equal(" 0000", sprintf("%#6.4b", 0)) assert_equal("0b0001", sprintf("%#6.4b", 1)) assert_equal("0b0010", sprintf("%#6.4b", 2)) - assert_equal("0b1111", sprintf("%#6.4b", -1)) + assert_equal("0b..11", sprintf("%#6.4b", -1)) assert_equal("+0", sprintf("%+b", 0)) assert_equal("+1", sprintf("%+b", 1)) @@ -288,8 +288,6 @@ class TestSprintf < Test::Unit::TestCase b1 = (/\.\./ =~ s1) != nil b2 = (/\.\./ =~ s2) != nil assert(b1 == b2, "[ruby-dev:33224]") - - assert_equal("ffffffff", sprintf("%.8x", -1)) end def test_named diff --git a/test/ruby/test_sprintf_comb.rb b/test/ruby/test_sprintf_comb.rb index 3105127046..261732bcbc 100644 --- a/test/ruby/test_sprintf_comb.rb +++ b/test/ruby/test_sprintf_comb.rb @@ -190,7 +190,7 @@ class TestSprintfComb < Test::Unit::TestCase if digits.last != radix-1 digits << (radix-1) end - sign = '..' unless precision + sign = '..' else sign = '-' end @@ -222,8 +222,8 @@ class TestSprintfComb < Test::Unit::TestCase end end if type == 'o' && hs - if digits.empty? || digits.last != 0 - prefix = '0' + if digits.empty? || digits.last != d + digits << d end end |