mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 03:17:53 +00:00
Implement formatting of objects with (s)printf.
This commit is contained in:
parent
59155abbf3
commit
79d8f59906
@ -523,6 +523,12 @@ class PrintfArgFormatter :
|
||||
}
|
||||
*out = static_cast<Char>(value);
|
||||
}
|
||||
|
||||
void visit_custom(Arg::CustomValue c) {
|
||||
BasicFormatter<Char> formatter(ArgList(), this->writer());
|
||||
const char *format = "}";
|
||||
c.format(&formatter, c.value, &format);
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
} // namespace fmt
|
||||
|
@ -148,19 +148,6 @@ TEST(CStringRefTest, Ctor) {
|
||||
EXPECT_STREQ("defg", CStringRef(std::string("defg")).c_str());
|
||||
}
|
||||
|
||||
class TestString {
|
||||
private:
|
||||
std::string value_;
|
||||
|
||||
public:
|
||||
explicit TestString(const char *value = "") : value_(value) {}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const TestString &s) {
|
||||
os << s.value_;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
#if FMT_USE_TYPE_TRAITS
|
||||
TEST(WriterTest, NotCopyConstructible) {
|
||||
EXPECT_FALSE(std::is_copy_constructible<BasicWriter<char> >::value);
|
||||
|
@ -426,6 +426,10 @@ TEST(PrintfTest, Pointer) {
|
||||
EXPECT_PRINTF(fmt::format("{}", p), "%p", p);
|
||||
}
|
||||
|
||||
TEST(PrintfTest, Custom) {
|
||||
EXPECT_PRINTF("abc", "%s", TestString("abc"));
|
||||
}
|
||||
|
||||
TEST(PrintfTest, Location) {
|
||||
// TODO: test %n
|
||||
}
|
||||
|
13
test/util.h
13
test/util.h
@ -67,3 +67,16 @@ inline FILE *safe_fopen(const char *filename, const char *mode) {
|
||||
return std::fopen(filename, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
class TestString {
|
||||
private:
|
||||
std::string value_;
|
||||
|
||||
public:
|
||||
explicit TestString(const char *value = "") : value_(value) {}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const TestString &s) {
|
||||
os << s.value_;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user