From fecd3dd69b48b85772dfb5a23ca1549c54974dc7 Mon Sep 17 00:00:00 2001 From: Abraham Bachrach Date: Mon, 10 Feb 2014 12:09:13 -0800 Subject: [PATCH] Fix the formatting of octal integers. {0:#o}.format(42) as being formatted as: "052" instead of "0o52" --- format.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/format.h b/format.h index eb7b5c8e155e..2a042cbcf6e4 100644 --- a/format.h +++ b/format.h @@ -856,7 +856,7 @@ void BasicWriter::FormatInt(T value, const Spec &spec) { case 'o': { UnsignedType n = abs_value; bool print_prefix = spec.hash_flag(); - if (print_prefix) ++size; + if (print_prefix) size+=2; do { ++size; } while ((n >>= 3) != 0); @@ -865,8 +865,10 @@ void BasicWriter::FormatInt(T value, const Spec &spec) { do { *p-- = '0' + (n & 7); } while ((n >>= 3) != 0); - if (print_prefix) + if (print_prefix){ + *p-- = spec.type(); *p = '0'; + } break; } default: @@ -1292,7 +1294,7 @@ class FormatInt { *--buffer_end = internal::DIGITS[index]; return buffer_end; } - + void FormatSigned(int64_t value) { uint64_t abs_value = value; bool negative = value < 0;