Skip to content

Commit

Permalink
Printf get container (#1982)
Browse files Browse the repository at this point in the history
* eliminate one case where basic_print_context would copy a string into a fmt::basic_memory_buffer character by character instead of using fmt::basic_memory_buffer::append

* use detail::write instead of re-implementing it

* use to_unsigned to avoid signedness conversion warnings
  • Loading branch information
rimathia authored Nov 12, 2020
1 parent 7abc3c0 commit 986fa00
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
}
char_type c = *it++;
if (it != end && *it == c) {
out = std::copy(start, it, out);
out = detail::write(
out, basic_string_view<Char>(start, detail::to_unsigned(it - start)));
start = ++it;
continue;
}
out = std::copy(start, it - 1, out);
out = detail::write(out, basic_string_view<Char>(
start, detail::to_unsigned(it - 1 - start)));

format_specs specs;
specs.align = align::right;
Expand Down Expand Up @@ -596,7 +598,8 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
// Format argument.
out = visit_format_arg(ArgFormatter(out, specs, *this), arg);
}
return std::copy(start, it, out);
return detail::write(
out, basic_string_view<Char>(start, detail::to_unsigned(it - start)));
}

template <typename Char>
Expand Down

0 comments on commit 986fa00

Please sign in to comment.