зеркало из https://github.com/github/ruby.git
Revert "* sprintf.c (rb_str_format): fix: sprintf with hex format and"
This reverts commit a160986d90
.
Revert wrong commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
6a443e2eb2
Коммит
8a0cd16de1
|
@ -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
|
||||
|
|
12
sprintf.c
12
sprintf.c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче