Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Aug 11, 2024
1 parent 993f56c commit 81de3c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
8 changes: 3 additions & 5 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,8 @@ template <typename T> class buffer {

/// Appends data to the end of the buffer.
template <typename U>
// Workaround for Visual Studio 2019 to fix error C2893: Failed to specialize
// function template 'void fmt::v11::detail::buffer<T>::append(const U *,const
// U *)'
// Workaround for MSVC2019 to fix error C2893: Failed to specialize function
// template 'void fmt::v11::detail::buffer<T>::append(const U *,const U *)'.
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1930
FMT_CONSTEXPR20
#endif
Expand Down Expand Up @@ -2880,8 +2879,7 @@ inline void report_truncation(bool truncated) {
if (truncated) report_error("output is truncated");
}

// Use vformat_args and avoid type_identity to keep symbols short and workaround
// a GCC <= 4.8 bug.
// Use vformat_args and avoid type_identity to keep symbols short.
template <typename Char = char> struct vformat_args {
using type = basic_format_args<buffered_context<Char>>;
};
Expand Down
20 changes: 9 additions & 11 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2264,26 +2264,24 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
auto size = s.size();
if (specs.precision >= 0 && to_unsigned(specs.precision) < size)
size = code_point_index(s, to_unsigned(specs.precision));
bool is_debug = specs.type() == presentation_type::debug;
size_t width = 0;

bool is_debug = specs.type() == presentation_type::debug;
if (is_debug) {
auto buf = counting_buffer<Char>();
write_escaped_string(basic_appender<Char>(buf), s);
size = buf.count();
}

size_t width = 0;
if (specs.width != 0) {
if (is_debug)
width = size;
else
width = compute_width(basic_string_view<Char>(data, size));
width =
is_debug ? size : compute_width(basic_string_view<Char>(data, size));
}
return write_padded<Char>(out, specs, size, width,
[=](reserve_iterator<OutputIt> it) {
if (is_debug) return write_escaped_string(it, s);
return copy<Char>(data, data + size, it);
});
return write_padded<Char>(
out, specs, size, width, [=](reserve_iterator<OutputIt> it) {
return is_debug ? write_escaped_string(it, s)
: copy<Char>(data, data + size, it);
});
}
template <typename Char, typename OutputIt>
FMT_CONSTEXPR auto write(OutputIt out,
Expand Down

0 comments on commit 81de3c3

Please sign in to comment.