mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-27 06:35:37 +00:00
(w)context -> (w)format_context
This commit is contained in:
parent
26aa34f319
commit
fd0b07a75a
@ -911,8 +911,8 @@ struct buffer_context {
|
||||
typedef basic_format_context<
|
||||
std::back_insert_iterator<internal::basic_buffer<Char>>, Char> type;
|
||||
};
|
||||
typedef buffer_context<char>::type context;
|
||||
typedef buffer_context<wchar_t>::type wcontext;
|
||||
typedef buffer_context<char>::type format_context;
|
||||
typedef buffer_context<wchar_t>::type wformat_context;
|
||||
|
||||
namespace internal {
|
||||
template <typename Context, typename T>
|
||||
@ -1008,8 +1008,9 @@ inline format_arg_store<Context, Args...> make_args(const Args & ... args) {
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
inline format_arg_store<context, Args...> make_args(const Args & ... args) {
|
||||
return format_arg_store<context, Args...>(args...);
|
||||
inline format_arg_store<format_context, Args...>
|
||||
make_args(const Args & ... args) {
|
||||
return format_arg_store<format_context, Args...>(args...);
|
||||
}
|
||||
|
||||
/** Formatting arguments. */
|
||||
@ -1093,12 +1094,12 @@ class basic_format_args {
|
||||
|
||||
/** An alias to ``basic_format_args<context>``. */
|
||||
// It is a separate type rather than a typedef to make symbols readable.
|
||||
struct format_args: basic_format_args<context> {
|
||||
struct format_args: basic_format_args<format_context> {
|
||||
template <typename ...Args>
|
||||
format_args(Args && ... arg)
|
||||
: basic_format_args<context>(std::forward<Args>(arg)...) {}
|
||||
: basic_format_args<format_context>(std::forward<Args>(arg)...) {}
|
||||
};
|
||||
typedef basic_format_args<wcontext> wformat_args;
|
||||
typedef basic_format_args<wformat_context> wformat_args;
|
||||
|
||||
namespace internal {
|
||||
template <typename Char>
|
||||
@ -1106,7 +1107,7 @@ struct named_arg_base {
|
||||
basic_string_view<Char> name;
|
||||
|
||||
// Serialized value<context>.
|
||||
mutable char data[sizeof(basic_format_arg<context>)];
|
||||
mutable char data[sizeof(basic_format_arg<format_context>)];
|
||||
|
||||
named_arg_base(basic_string_view<Char> nm) : name(nm) {}
|
||||
|
||||
@ -1167,10 +1168,10 @@ inline void print_colored(color c, string_view format_str,
|
||||
vprint_colored(c, format_str, make_args(args...));
|
||||
}
|
||||
|
||||
context::iterator vformat_to(internal::buffer &buf, string_view format_str,
|
||||
format_args args);
|
||||
wcontext::iterator vformat_to(internal::wbuffer &buf, wstring_view format_str,
|
||||
wformat_args args);
|
||||
format_context::iterator vformat_to(
|
||||
internal::buffer &buf, string_view format_str, format_args args);
|
||||
wformat_context::iterator vformat_to(
|
||||
internal::wbuffer &buf, wstring_view format_str, wformat_args args);
|
||||
|
||||
template <typename Container>
|
||||
struct is_contiguous : std::false_type {};
|
||||
@ -1211,12 +1212,12 @@ inline std::string format(string_view format_str, const Args & ... args) {
|
||||
// This should be just
|
||||
// return vformat(format_str, make_args(args...));
|
||||
// but gcc has trouble optimizing the latter, so break it down.
|
||||
format_arg_store<context, Args...> as(args...);
|
||||
format_arg_store<format_context, Args...> as(args...);
|
||||
return vformat(format_str, as);
|
||||
}
|
||||
template <typename... Args>
|
||||
inline std::wstring format(wstring_view format_str, const Args & ... args) {
|
||||
format_arg_store<wcontext, Args...> as(args...);
|
||||
format_arg_store<wformat_context, Args...> as(args...);
|
||||
return vformat(format_str, as);
|
||||
}
|
||||
|
||||
@ -1233,7 +1234,7 @@ FMT_API void vprint(std::FILE *f, string_view format_str, format_args args);
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void print(std::FILE *f, string_view format_str, const Args & ... args) {
|
||||
format_arg_store<context, Args...> as(args...);
|
||||
format_arg_store<format_context, Args...> as(args...);
|
||||
vprint(f, format_str, as);
|
||||
}
|
||||
|
||||
@ -1250,7 +1251,7 @@ FMT_API void vprint(string_view format_str, format_args args);
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void print(string_view format_str, const Args & ... args) {
|
||||
format_arg_store<context, Args...> as(args...);
|
||||
format_arg_store<format_context, Args...> as(args...);
|
||||
vprint(format_str, as);
|
||||
}
|
||||
} // namespace fmt
|
||||
|
@ -3368,28 +3368,28 @@ std::basic_string<Char> to_string(const basic_memory_buffer<Char> &buffer) {
|
||||
return std::basic_string<Char>(buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
inline context::iterator vformat_to(
|
||||
inline format_context::iterator vformat_to(
|
||||
internal::buffer &buf, string_view format_str, format_args args) {
|
||||
typedef back_insert_range<internal::buffer> range;
|
||||
return vformat_to<arg_formatter<range>>(buf, format_str, args);
|
||||
}
|
||||
|
||||
inline wcontext::iterator vformat_to(
|
||||
inline wformat_context::iterator vformat_to(
|
||||
internal::wbuffer &buf, wstring_view format_str, wformat_args args) {
|
||||
typedef back_insert_range<internal::wbuffer> range;
|
||||
return vformat_to<arg_formatter<range>>(buf, format_str, args);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline context::iterator format_to(
|
||||
inline format_context::iterator format_to(
|
||||
memory_buffer &buf, string_view format_str, const Args & ... args) {
|
||||
return vformat_to(buf, format_str, make_args(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline wcontext::iterator format_to(
|
||||
inline wformat_context::iterator format_to(
|
||||
wmemory_buffer &buf, wstring_view format_str, const Args & ... args) {
|
||||
return vformat_to(buf, format_str, make_args<wcontext>(args...));
|
||||
return vformat_to(buf, format_str, make_args<wformat_context>(args...));
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Char = char>
|
||||
|
@ -110,7 +110,7 @@ struct formatter<std::tm> {
|
||||
return pointer_from(end);
|
||||
}
|
||||
|
||||
auto format(const std::tm &tm, context &ctx) -> decltype(ctx.begin()) {
|
||||
auto format(const std::tm &tm, format_context &ctx) -> decltype(ctx.begin()) {
|
||||
internal::buffer &buf = internal::get_container(ctx.begin());
|
||||
std::size_t start = buf.size();
|
||||
for (;;) {
|
||||
|
@ -17,8 +17,8 @@ template FMT_API char internal::thousands_sep(locale_provider *lp);
|
||||
|
||||
template void basic_fixed_buffer<char>::grow(std::size_t);
|
||||
|
||||
template void internal::arg_map<context>::init(
|
||||
const basic_format_args<context> &args);
|
||||
template void internal::arg_map<format_context>::init(
|
||||
const basic_format_args<format_context> &args);
|
||||
|
||||
template FMT_API int internal::char_traits<char>::format_float(
|
||||
char *buffer, std::size_t size, const char *format,
|
||||
@ -34,7 +34,7 @@ template FMT_API wchar_t internal::thousands_sep(locale_provider *lp);
|
||||
|
||||
template void basic_fixed_buffer<wchar_t>::grow(std::size_t);
|
||||
|
||||
template void internal::arg_map<wcontext>::init(const wformat_args &args);
|
||||
template void internal::arg_map<wformat_context>::init(const wformat_args &args);
|
||||
|
||||
template FMT_API int internal::char_traits<wchar_t>::format_float(
|
||||
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
||||
|
@ -16,7 +16,7 @@ class custom_arg_formatter :
|
||||
typedef fmt::back_insert_range<fmt::internal::buffer> range;
|
||||
typedef fmt::arg_formatter<range> base;
|
||||
|
||||
custom_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
|
||||
custom_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
|
||||
: base(ctx, s) {}
|
||||
|
||||
using base::operator();
|
||||
|
@ -38,8 +38,9 @@ struct ValueExtractor: fmt::internal::function<T> {
|
||||
|
||||
TEST(FormatTest, ArgConverter) {
|
||||
long long value = std::numeric_limits<long long>::max();
|
||||
auto arg = fmt::internal::make_arg<fmt::context>(value);
|
||||
visit(fmt::internal::arg_converter<long long, fmt::context>(arg, 'd'), arg);
|
||||
auto arg = fmt::internal::make_arg<fmt::format_context>(value);
|
||||
visit(fmt::internal::arg_converter<long long, fmt::format_context>(arg, 'd'),
|
||||
arg);
|
||||
EXPECT_EQ(value, visit(ValueExtractor<long long>(), arg));
|
||||
}
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ struct formatter<Date> {
|
||||
return it;
|
||||
}
|
||||
|
||||
auto format(const Date &d, context &ctx) -> decltype(ctx.begin()) {
|
||||
auto format(const Date &d, format_context &ctx) -> decltype(ctx.begin()) {
|
||||
format_to(ctx.begin(), "{}-{}-{}", d.year(), d.month(), d.day());
|
||||
return ctx.begin();
|
||||
}
|
||||
@ -1119,7 +1119,7 @@ class Answer {};
|
||||
namespace fmt {
|
||||
template <>
|
||||
struct formatter<Answer> : formatter<int> {
|
||||
auto format(Answer, fmt::context &ctx) -> decltype(ctx.begin()) {
|
||||
auto format(Answer, fmt::format_context &ctx) -> decltype(ctx.begin()) {
|
||||
return formatter<int>::format(42, ctx);
|
||||
}
|
||||
};
|
||||
@ -1409,7 +1409,7 @@ class mock_arg_formatter:
|
||||
typedef fmt::internal::arg_formatter_base<buffer_range> base;
|
||||
typedef buffer_range range;
|
||||
|
||||
mock_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
|
||||
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
|
||||
: base(fmt::internal::get_container(ctx.begin()), s) {
|
||||
EXPECT_CALL(*this, call(42));
|
||||
}
|
||||
@ -1421,7 +1421,7 @@ class mock_arg_formatter:
|
||||
return base::operator()(value);
|
||||
}
|
||||
|
||||
iterator operator()(fmt::basic_format_arg<fmt::context>::handle) {
|
||||
iterator operator()(fmt::basic_format_arg<fmt::format_context>::handle) {
|
||||
return base::operator()(fmt::monostate());
|
||||
}
|
||||
};
|
||||
@ -1454,7 +1454,7 @@ struct variant {
|
||||
namespace fmt {
|
||||
template <>
|
||||
struct formatter<variant> : dynamic_formatter<> {
|
||||
auto format(variant value, context& ctx) -> decltype(ctx.begin()) {
|
||||
auto format(variant value, format_context& ctx) -> decltype(ctx.begin()) {
|
||||
if (value.type == variant::INT)
|
||||
return dynamic_formatter<>::format(42, ctx);
|
||||
return dynamic_formatter<>::format("foo", ctx);
|
||||
|
@ -41,17 +41,17 @@ TEST(OStreamTest, Enum) {
|
||||
typedef fmt::back_insert_range<fmt::internal::buffer> range;
|
||||
|
||||
struct test_arg_formatter: fmt::arg_formatter<range> {
|
||||
test_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
|
||||
test_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
|
||||
: fmt::arg_formatter<range>(ctx, s) {}
|
||||
};
|
||||
|
||||
TEST(OStreamTest, CustomArg) {
|
||||
fmt::memory_buffer buffer;
|
||||
fmt::internal::buffer &base = buffer;
|
||||
fmt::context ctx(std::back_inserter(base), "", fmt::format_args());
|
||||
fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args());
|
||||
fmt::format_specs spec;
|
||||
test_arg_formatter af(ctx, spec);
|
||||
visit(af, fmt::internal::make_arg<fmt::context>(TestEnum()));
|
||||
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
|
||||
EXPECT_EQ("TestEnum", std::string(buffer.data(), buffer.size()));
|
||||
}
|
||||
|
||||
|
@ -580,10 +580,10 @@ TEST(UtilTest, PointerArg) {
|
||||
}
|
||||
|
||||
struct check_custom {
|
||||
Result operator()(fmt::basic_format_arg<fmt::context>::handle h) const {
|
||||
Result operator()(fmt::basic_format_arg<fmt::format_context>::handle h) const {
|
||||
fmt::memory_buffer buffer;
|
||||
fmt::internal::basic_buffer<char> &base = buffer;
|
||||
fmt::context ctx(std::back_inserter(base), "", fmt::format_args());
|
||||
fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args());
|
||||
h.format(ctx);
|
||||
EXPECT_EQ("test", std::string(buffer.data(), buffer.size()));
|
||||
return Result();
|
||||
@ -592,17 +592,18 @@ struct check_custom {
|
||||
|
||||
TEST(UtilTest, CustomArg) {
|
||||
::Test test;
|
||||
typedef MockVisitor<fmt::basic_format_arg<fmt::context>::handle> visitor;
|
||||
typedef MockVisitor<fmt::basic_format_arg<fmt::format_context>::handle>
|
||||
visitor;
|
||||
testing::StrictMock<visitor> v;
|
||||
EXPECT_CALL(v, visit(_)).WillOnce(testing::Invoke(check_custom()));
|
||||
fmt::visit(v, make_arg<fmt::context>(test));
|
||||
fmt::visit(v, make_arg<fmt::format_context>(test));
|
||||
}
|
||||
|
||||
TEST(ArgVisitorTest, VisitInvalidArg) {
|
||||
typedef MockVisitor<fmt::monostate> Visitor;
|
||||
testing::StrictMock<Visitor> visitor;
|
||||
EXPECT_CALL(visitor, visit(_));
|
||||
fmt::basic_format_arg<fmt::context> arg;
|
||||
fmt::basic_format_arg<fmt::format_context> arg;
|
||||
visit(visitor, arg);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user