From fa9066fe3e0f0116474bf751012c6effc86afdfd Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 22 Apr 2018 09:16:32 -0700 Subject: [PATCH] context_base::begin -> out --- include/fmt/core.h | 3 ++- include/fmt/format.h | 18 +++++++++--------- include/fmt/ostream.h | 4 ++-- include/fmt/printf.h | 10 +++++----- include/fmt/time.h | 6 +++--- test/format-test.cc | 12 ++++++------ test/util-test.cc | 4 ++-- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index df9a5242..c70e0b98 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -840,7 +840,8 @@ class context_base { void on_error(const char *message) { parse_context_.on_error(message); } // Returns an iterator to the beginning of the output range. - iterator begin() { return out_; } + iterator out() { return out_; } + iterator begin() { return out_; } // deprecated // Advances the begin iterator to ``it``. void advance_to(iterator it) { out_ = it; } diff --git a/include/fmt/format.h b/include/fmt/format.h index e735d7ae..346b1ac0 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2216,7 +2216,7 @@ class arg_formatter: \endrst */ arg_formatter(context_type &ctx, format_specs &spec) - : base(Range(ctx.begin()), spec), ctx_(ctx) {} + : base(Range(ctx.out()), spec), ctx_(ctx) {} using base::operator(); @@ -3096,7 +3096,7 @@ struct formatter< } template - auto format(const T &val, FormatContext &ctx) -> decltype(ctx.begin()) { + auto format(const T &val, FormatContext &ctx) -> decltype(ctx.out()) { internal::handle_dynamic_spec( specs_.width_, specs_.width_ref, ctx); internal::handle_dynamic_spec( @@ -3105,7 +3105,7 @@ struct formatter< typename FormatContext::char_type> range; visit(arg_formatter(ctx, specs_), internal::make_arg(val)); - return ctx.begin(); + return ctx.out(); } private: @@ -3154,7 +3154,7 @@ class dynamic_formatter { } template - auto format(const T &val, FormatContext &ctx) -> decltype(ctx.begin()) { + auto format(const T &val, FormatContext &ctx) -> decltype(ctx.out()) { handle_specs(ctx); internal::specs_checker checker(null_handler(), internal::get_type::value); @@ -3177,7 +3177,7 @@ class dynamic_formatter { typename FormatContext::char_type> range; visit(arg_formatter(ctx, specs_), internal::make_arg(val)); - return ctx.begin(); + return ctx.out(); } private: @@ -3213,7 +3213,7 @@ struct format_handler : internal::error_handler { void on_text(iterator begin, iterator end) { size_t size = end - begin; - auto out = context.begin(); + auto out = context.out(); auto &&it = internal::reserve(out, size); it = std::copy_n(begin, size, it); context.advance_to(out); @@ -3265,7 +3265,7 @@ typename Context::iterator vformat_to(typename ArgFormatter::range out, typedef internal::null_terminating_iterator iterator; format_handler h(out, format_str, args); parse_format_string(iterator(format_str.begin(), format_str.end()), h); - return h.context.begin(); + return h.context.out(); } // Casts ``p`` to ``const void*`` for pointer formatting. @@ -3289,10 +3289,10 @@ struct formatter, Char>: formatter::value_type, Char> { template auto format(const arg_join &value, FormatContext &ctx) - -> decltype(ctx.begin()) { + -> decltype(ctx.out()) { typedef formatter::value_type, Char> base; auto it = value.begin; - auto out = ctx.begin(); + auto out = ctx.out(); if (it != value.end) { out = base::format(*it++, ctx); while (it != value.end) { diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 42455559..b8a75b3a 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -112,12 +112,12 @@ struct formatter, Char> { template - auto format(const T &value, Context &ctx) -> decltype(ctx.begin()) { + auto format(const T &value, Context &ctx) -> decltype(ctx.out()) { basic_memory_buffer buffer; internal::format_value(buffer, value); basic_string_view str(buffer.data(), buffer.size()); formatter, Char>::format(str, ctx); - return ctx.begin(); + return ctx.out(); } }; diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 20f79de1..49586ef9 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -298,9 +298,9 @@ struct printf_formatter { auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { return ctx.begin(); } template - auto format(const T &value, FormatContext &ctx) -> decltype(ctx.begin()) { - internal::format_value(internal::get_container(ctx.begin()), value); - return ctx.begin(); + auto format(const T &value, FormatContext &ctx) -> decltype(ctx.out()) { + internal::format_value(internal::get_container(ctx.out()), value); + return ctx.out(); } }; @@ -346,7 +346,7 @@ class basic_printf_context : : base(out, format_str, args) {} using base::parse_context; - using base::begin; + using base::out; using base::advance_to; /** Formats stored arguments and writes the output to the range. */ @@ -429,7 +429,7 @@ unsigned basic_printf_context::parse_header( template void basic_printf_context::format() { - auto &buffer = internal::get_container(this->begin()); + auto &buffer = internal::get_container(this->out()); auto start = iterator(this->parse_context()); auto it = start; using internal::pointer_from; diff --git a/include/fmt/time.h b/include/fmt/time.h index 9cfa3152..e562e96c 100644 --- a/include/fmt/time.h +++ b/include/fmt/time.h @@ -121,8 +121,8 @@ struct formatter { } template - auto format(const std::tm &tm, FormatContext &ctx) -> decltype(ctx.begin()) { - internal::basic_buffer &buf = internal::get_container(ctx.begin()); + auto format(const std::tm &tm, FormatContext &ctx) -> decltype(ctx.out()) { + internal::basic_buffer &buf = internal::get_container(ctx.out()); std::size_t start = buf.size(); for (;;) { std::size_t size = buf.capacity() - start; @@ -141,7 +141,7 @@ struct formatter { const std::size_t MIN_GROWTH = 10; buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH)); } - return ctx.begin(); + return ctx.out(); } basic_memory_buffer tm_format; diff --git a/test/format-test.cc b/test/format-test.cc index c139d260..1612c667 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1101,9 +1101,9 @@ struct formatter { return it; } - auto format(const Date &d, format_context &ctx) -> decltype(ctx.begin()) { - format_to(ctx.begin(), "{}-{}-{}", d.year(), d.month(), d.day()); - return ctx.begin(); + auto format(const Date &d, format_context &ctx) -> decltype(ctx.out()) { + format_to(ctx.out(), "{}-{}-{}", d.year(), d.month(), d.day()); + return ctx.out(); } }; } @@ -1119,7 +1119,7 @@ class Answer {}; namespace fmt { template <> struct formatter : formatter { - auto format(Answer, fmt::format_context &ctx) -> decltype(ctx.begin()) { + auto format(Answer, fmt::format_context &ctx) -> decltype(ctx.out()) { return formatter::format(42, ctx); } }; @@ -1410,7 +1410,7 @@ class mock_arg_formatter: typedef buffer_range range; mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s) - : base(fmt::internal::get_container(ctx.begin()), s) { + : base(fmt::internal::get_container(ctx.out()), s) { EXPECT_CALL(*this, call(42)); } @@ -1454,7 +1454,7 @@ struct variant { namespace fmt { template <> struct formatter : dynamic_formatter<> { - auto format(variant value, format_context& ctx) -> decltype(ctx.begin()) { + auto format(variant value, format_context& ctx) -> decltype(ctx.out()) { if (value.type == variant::INT) return dynamic_formatter<>::format(42, ctx); return dynamic_formatter<>::format("foo", ctx); diff --git a/test/util-test.cc b/test/util-test.cc index 9cf3c1ad..d192a6bb 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -65,9 +65,9 @@ struct formatter { typedef std::back_insert_iterator> iterator; auto format(Test, basic_format_context &ctx) - -> decltype(ctx.begin()) { + -> decltype(ctx.out()) { const Char *test = "test"; - return std::copy_n(test, std::strlen(test), ctx.begin()); + return std::copy_n(test, std::strlen(test), ctx.out()); } }; }