mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 20:32:49 +00:00
Add support for int64_t in FormatInt.
This commit is contained in:
parent
c3f5dce8d5
commit
bfedba5a0a
@ -1411,6 +1411,9 @@ TEST(FormatterTest, Examples) {
|
|||||||
TEST(FormatIntTest, FormatInt) {
|
TEST(FormatIntTest, FormatInt) {
|
||||||
EXPECT_EQ("42", fmt::FormatInt(42).str());
|
EXPECT_EQ("42", fmt::FormatInt(42).str());
|
||||||
EXPECT_EQ("-42", fmt::FormatInt(-42).str());
|
EXPECT_EQ("-42", fmt::FormatInt(-42).str());
|
||||||
|
std::ostringstream os;
|
||||||
|
os << std::numeric_limits<int64_t>::max();
|
||||||
|
EXPECT_EQ(os.str(), fmt::FormatInt(std::numeric_limits<int64_t>::max()).str());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
9
format.h
9
format.h
@ -1293,9 +1293,8 @@ class FormatInt {
|
|||||||
return buffer_end;
|
return buffer_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
void FormatSigned(int64_t value) {
|
||||||
explicit FormatInt(int value) {
|
uint64_t abs_value = value;
|
||||||
unsigned abs_value = value;
|
|
||||||
bool negative = value < 0;
|
bool negative = value < 0;
|
||||||
if (negative)
|
if (negative)
|
||||||
abs_value = 0 - value;
|
abs_value = 0 - value;
|
||||||
@ -1303,6 +1302,10 @@ class FormatInt {
|
|||||||
if (negative)
|
if (negative)
|
||||||
*--str_ = '-';
|
*--str_ = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit FormatInt(int value) { FormatSigned(value); }
|
||||||
|
explicit FormatInt(int64_t value) { FormatSigned(value); }
|
||||||
explicit FormatInt(unsigned value) : str_(FormatDecimal(value)) {}
|
explicit FormatInt(unsigned value) : str_(FormatDecimal(value)) {}
|
||||||
explicit FormatInt(uint64_t value) : str_(FormatDecimal(value)) {}
|
explicit FormatInt(uint64_t value) : str_(FormatDecimal(value)) {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user