From 98b3775297afc10ea054ac3514d6977b263275d3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 May 2019 10:03:10 -0700 Subject: [PATCH] Add support for exotic string_view iterators (#1156) --- include/fmt/format-inl.h | 2 +- include/fmt/format.h | 14 ++++++++++---- include/fmt/prepare.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 2a3d9c8c..29667beb 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -684,7 +684,7 @@ template struct grisu_shortest_handler { template FMT_API bool grisu_format(Double value, buffer& buf, int precision, - unsigned options, int& exp) { + unsigned options, int& exp) { FMT_ASSERT(value >= 0, "value is negative"); bool fixed = (options & grisu_options::fixed) != 0; if (value <= 0) { // <= instead of == to silence a warning. diff --git a/include/fmt/format.h b/include/fmt/format.h index 977310b6..b082b456 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2207,7 +2207,7 @@ class format_string_checker { FMT_CONSTEXPR void on_replacement_field(const Char*) {} FMT_CONSTEXPR const Char* on_format_specs(const Char* begin, const Char*) { - context_.advance_to(begin); + advance_to(context_, begin); return arg_id_ < NUM_ARGS ? parse_funcs_[arg_id_](context_) : begin; } @@ -3215,6 +3215,12 @@ basic_format_context::arg(basic_string_view name) { return arg; } +template +FMT_CONSTEXPR void advance_to(basic_parse_context& ctx, + const Char* p) { + ctx.advance_to(ctx.begin() + (p - &*ctx.begin())); +} + template struct format_handler : internal::error_handler { typedef typename ArgFormatter::range range; @@ -3242,7 +3248,7 @@ struct format_handler : internal::error_handler { void on_arg_id(basic_string_view id) { arg = context.arg(id); } void on_replacement_field(const Char* p) { - parse_context.advance_to(p); + advance_to(parse_context, p); internal::custom_formatter f(parse_context, context); if (!visit_format_arg(f, arg)) context.advance_to( @@ -3250,7 +3256,7 @@ struct format_handler : internal::error_handler { } const Char* on_format_specs(const Char* begin, const Char* end) { - parse_context.advance_to(begin); + advance_to(parse_context, begin); internal::custom_formatter f(parse_context, context); if (visit_format_arg(f, arg)) return parse_context.begin(); basic_format_specs specs; @@ -3261,7 +3267,7 @@ struct format_handler : internal::error_handler { arg.type()); begin = parse_format_specs(begin, end, handler); if (begin == end || *begin != '}') on_error("missing '}' in format string"); - parse_context.advance_to(begin); + advance_to(parse_context, begin); context.advance_to( visit_format_arg(ArgFormatter(context, &parse_context, &specs), arg)); return begin; diff --git a/include/fmt/prepare.h b/include/fmt/prepare.h index bfa7d816..6435fb77 100644 --- a/include/fmt/prepare.h +++ b/include/fmt/prepare.h @@ -310,7 +310,7 @@ class prepared_format { const format_part_t& part) const { const auto view = to_string_view(format_); const auto specification_begin = view.data() + part.end_of_argument_id; - parse_ctx.advance_to(specification_begin); + advance_to(parse_ctx, specification_begin); } template