Commit 611cf0b3 authored by Victor Zverovich's avatar Victor Zverovich

Format octal 0 as 0

parent 58a8f2f5
......@@ -1441,7 +1441,7 @@ template <typename Range> class basic_writer {
void on_oct() {
int num_digits = internal::count_digits<3>(abs_value);
if (specs.alt && specs.precision <= num_digits) {
if (specs.alt && specs.precision <= num_digits && abs_value != 0) {
// Octal prefix '0' is counted as a digit, so only add it if precision
// is not greater than the number of digits.
prefix[prefix_size++] = '0';
......
......@@ -1001,6 +1001,7 @@ TEST(FormatterTest, HashFlag) {
EXPECT_EQ("0x42", format("{0:#x}", 0x42));
EXPECT_EQ("0X42", format("{0:#X}", 0x42));
EXPECT_EQ("-0x42", format("{0:#x}", -0x42));
EXPECT_EQ("0", format("{0:#o}", 0));
EXPECT_EQ("042", format("{0:#o}", 042));
EXPECT_EQ("-042", format("{0:#o}", -042));
EXPECT_EQ("42", format("{0:#}", 42u));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment