mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Convert integer argument like printf does.
This commit is contained in:
parent
406c6123fb
commit
be00d8b272
@ -974,6 +974,7 @@ void fmt::internal::PrintfFormatter<Char>::format(
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
--s;
|
--s;
|
||||||
|
ArgConverter<int>(arg, *s).visit(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse type.
|
// Parse type.
|
||||||
|
@ -165,12 +165,13 @@ TEST(PrintfTest, SpaceFlag) {
|
|||||||
|
|
||||||
TEST(PrintfTest, HashFlag) {
|
TEST(PrintfTest, HashFlag) {
|
||||||
EXPECT_PRINTF("042", "%#o", 042);
|
EXPECT_PRINTF("042", "%#o", 042);
|
||||||
EXPECT_PRINTF("-042", "%#o", -042);
|
EXPECT_PRINTF(fmt::format("0{:o}", static_cast<unsigned>(-042)), "%#o", -042);
|
||||||
EXPECT_PRINTF("0", "%#o", 0);
|
EXPECT_PRINTF("0", "%#o", 0);
|
||||||
|
|
||||||
EXPECT_PRINTF("0x42", "%#x", 0x42);
|
EXPECT_PRINTF("0x42", "%#x", 0x42);
|
||||||
EXPECT_PRINTF("0X42", "%#X", 0x42);
|
EXPECT_PRINTF("0X42", "%#X", 0x42);
|
||||||
EXPECT_PRINTF("-0x42", "%#x", -0x42);
|
EXPECT_PRINTF(
|
||||||
|
fmt::format("0x{:x}", static_cast<unsigned>(-0x42)), "%#x", -0x42);
|
||||||
EXPECT_PRINTF("0", "%#x", 0);
|
EXPECT_PRINTF("0", "%#x", 0);
|
||||||
|
|
||||||
EXPECT_PRINTF("0x0042", "%#06x", 0x42);
|
EXPECT_PRINTF("0x0042", "%#06x", 0x42);
|
||||||
@ -370,6 +371,16 @@ TEST(PrintfTest, Length) {
|
|||||||
EXPECT_PRINTF(fmt::format("{}", max), "%Lg", max);
|
EXPECT_PRINTF(fmt::format("{}", max), "%Lg", max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PrintfTest, Int) {
|
||||||
|
EXPECT_PRINTF("-42", "%d", -42);
|
||||||
|
EXPECT_PRINTF("-42", "%i", -42);
|
||||||
|
unsigned u = -42;
|
||||||
|
EXPECT_PRINTF(fmt::format("{}", u), "%u", -42);
|
||||||
|
EXPECT_PRINTF(fmt::format("{:o}", u), "%o", -42);
|
||||||
|
EXPECT_PRINTF(fmt::format("{:x}", u), "%x", -42);
|
||||||
|
EXPECT_PRINTF(fmt::format("{:X}", u), "%X", -42);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(PrintfTest, Char) {
|
TEST(PrintfTest, Char) {
|
||||||
EXPECT_PRINTF("x", "%c", 'x');
|
EXPECT_PRINTF("x", "%c", 'x');
|
||||||
int max = std::numeric_limits<int>::max();
|
int max = std::numeric_limits<int>::max();
|
||||||
|
Loading…
Reference in New Issue
Block a user