Separate parsing and formatting

This commit is contained in:
Victor Zverovich
2017-08-13 13:09:02 -07:00
parent 1102d46508
commit 5e0562ab51
9 changed files with 449 additions and 270 deletions
+19 -5
View File
@@ -1227,8 +1227,18 @@ TEST(FormatterTest, FormatStringView) {
EXPECT_EQ("test", format("{0}", string_view("test")));
}
void format_value(fmt::buffer &buf, const Date &d, fmt::context &) {
fmt::format_to(buf, "{}-{}-{}", d.year(), d.month(), d.day());
namespace fmt {
template <>
struct formatter<Date> {
template <typename Range>
auto parse(Range format) -> decltype(begin(format)) {
return begin(format);
}
void format(buffer &buf, const Date &d, context &) {
format_to(buf, "{}-{}-{}", d.year(), d.month(), d.day());
}
};
}
TEST(FormatterTest, FormatCustom) {
@@ -1239,9 +1249,13 @@ TEST(FormatterTest, FormatCustom) {
class Answer {};
void format_value(fmt::buffer &buf, Answer, fmt::context &ctx) {
fmt::formatter<int> f(ctx);
f.format(buf, 42, ctx);
namespace fmt {
template <>
struct formatter<Answer> : formatter<int> {
void format(fmt::buffer &buf, Answer, fmt::context &ctx) {
formatter<int>::format(buf, 42, ctx);
}
};
}
TEST(FormatterTest, CustomFormat) {