Skip to content

Commit

Permalink
Fix a regression in named argument handling introduced by prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jun 5, 2019
1 parent aa31028 commit a38b99a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 3 additions & 5 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1806,11 +1806,9 @@ struct string_view_metadata {
: offset_(view.data() - primary_string.data()), size_(view.size()) {}
FMT_CONSTEXPR string_view_metadata(std::size_t offset, std::size_t size)
: offset_(offset), size_(size) {}
template <typename S, typename Char = enable_if_t<
internal::is_string<S>::value, char_t<S>>>
FMT_CONSTEXPR basic_string_view<Char> to_view(S&& str) const {
const auto view = to_string_view(str);
return basic_string_view<Char>(view.data() + offset_, size_);
template <typename Char>
FMT_CONSTEXPR basic_string_view<Char> to_view(const Char* str) const {
return {str + offset_, size_};
}

std::size_t offset_;
Expand Down
15 changes: 8 additions & 7 deletions include/fmt/prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class prepared_format {

switch (part.which) {
case format_part_t::which_value::text: {
const auto text = value.text.to_view(format_view);
const auto text = value.text.to_view(format_view.data());
auto output = ctx.out();
auto&& it = internal::reserve(output, text.size());
it = std::copy_n(text.begin(), text.size(), it);
Expand All @@ -276,16 +276,17 @@ class prepared_format {

case format_part_t::which_value::named_argument_id: {
advance_parse_context_to_specification(parse_ctx, part);
const auto named_arg_id = value.named_arg_id.to_view(format_view);
const auto named_arg_id =
value.named_arg_id.to_view(format_view.data());
format_arg<Range>(parse_ctx, ctx, named_arg_id);
} break;
case format_part_t::which_value::specification: {
const auto& arg_id_value = value.spec.arg_id.val;
const auto arg =
value.spec.arg_id.which ==
format_part_t::argument_id::which_arg_id::index
? ctx.arg(arg_id_value.index)
: ctx.arg(arg_id_value.named_index.to_view(format_));
const auto arg = value.spec.arg_id.which ==
format_part_t::argument_id::which_arg_id::index
? ctx.arg(arg_id_value.index)
: ctx.arg(arg_id_value.named_index.to_view(
to_string_view(format_).data()));

auto specs = value.spec.parsed_specs;

Expand Down

0 comments on commit a38b99a

Please sign in to comment.