mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-26 00:21:13 +00:00
Fix handling of octal prefix.
This commit is contained in:
parent
512ab9336b
commit
ca31c2b322
4
format.h
4
format.h
@ -1313,8 +1313,8 @@ typename fmt::BasicWriter<Char>::CharPtr
|
|||||||
if (spec.precision() > static_cast<int>(num_digits)) {
|
if (spec.precision() > static_cast<int>(num_digits)) {
|
||||||
// Octal prefix '0' is counted as a digit, so ignore it if precision
|
// Octal prefix '0' is counted as a digit, so ignore it if precision
|
||||||
// is specified.
|
// is specified.
|
||||||
if (prefix_size == 1)
|
if (prefix_size > 0 && prefix[prefix_size - 1] == '0')
|
||||||
prefix_size = 0;
|
--prefix_size;
|
||||||
unsigned number_size = prefix_size + spec.precision();
|
unsigned number_size = prefix_size + spec.precision();
|
||||||
if (number_size < width) {
|
if (number_size < width) {
|
||||||
buffer_.reserve(width);
|
buffer_.reserve(width);
|
||||||
|
@ -229,6 +229,7 @@ TEST(PrintfTest, DynamicWidth) {
|
|||||||
|
|
||||||
TEST(PrintfTest, Precision) {
|
TEST(PrintfTest, Precision) {
|
||||||
EXPECT_PRINTF("00042", "%.5d", 42);
|
EXPECT_PRINTF("00042", "%.5d", 42);
|
||||||
|
EXPECT_PRINTF("-00042", "%.5d", -42);
|
||||||
EXPECT_PRINTF("00042", "%.5x", 0x42);
|
EXPECT_PRINTF("00042", "%.5x", 0x42);
|
||||||
EXPECT_PRINTF("0x00042", "%#.5x", 0x42);
|
EXPECT_PRINTF("0x00042", "%#.5x", 0x42);
|
||||||
EXPECT_PRINTF("00042", "%.5o", 042);
|
EXPECT_PRINTF("00042", "%.5o", 042);
|
||||||
|
Loading…
Reference in New Issue
Block a user