From bfedba5a0a8d563458a42f4150ba3056ff71fee6 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 30 Jan 2014 08:02:06 -0800 Subject: [PATCH] Add support for int64_t in FormatInt. --- format-test.cc | 3 +++ format.h | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/format-test.cc b/format-test.cc index 947cd69a..3f867f0e 100644 --- a/format-test.cc +++ b/format-test.cc @@ -1411,6 +1411,9 @@ TEST(FormatterTest, Examples) { TEST(FormatIntTest, FormatInt) { EXPECT_EQ("42", fmt::FormatInt(42).str()); EXPECT_EQ("-42", fmt::FormatInt(-42).str()); + std::ostringstream os; + os << std::numeric_limits::max(); + EXPECT_EQ(os.str(), fmt::FormatInt(std::numeric_limits::max()).str()); } template diff --git a/format.h b/format.h index 03661d2e..eb7b5c8e 100644 --- a/format.h +++ b/format.h @@ -1292,10 +1292,9 @@ class FormatInt { *--buffer_end = internal::DIGITS[index]; return buffer_end; } - - public: - explicit FormatInt(int value) { - unsigned abs_value = value; + + void FormatSigned(int64_t value) { + uint64_t abs_value = value; bool negative = value < 0; if (negative) abs_value = 0 - value; @@ -1303,6 +1302,10 @@ class FormatInt { if (negative) *--str_ = '-'; } + + public: + explicit FormatInt(int value) { FormatSigned(value); } + explicit FormatInt(int64_t value) { FormatSigned(value); } explicit FormatInt(unsigned value) : str_(FormatDecimal(value)) {} explicit FormatInt(uint64_t value) : str_(FormatDecimal(value)) {}