mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Minor cleanup
This commit is contained in:
@ -2109,41 +2109,24 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
|
|||||||
return write_int<Char>(out, make_write_int_arg(value, specs.sign()), specs);
|
return write_int<Char>(out, make_write_int_arg(value, specs.sign()), specs);
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_INLINE auto count_code_points_with_display_width_precision(
|
inline auto convert_precision_to_size(string_view s, size_t precision)
|
||||||
string_view s, size_t display_width_precision) -> size_t {
|
-> size_t {
|
||||||
size_t display_width = 0;
|
size_t display_width = 0;
|
||||||
size_t code_points = 0;
|
size_t num_code_points = 0;
|
||||||
|
|
||||||
// Iterate through the string to compute display width
|
|
||||||
for_each_codepoint(s, [&](uint32_t, string_view sv) {
|
for_each_codepoint(s, [&](uint32_t, string_view sv) {
|
||||||
// Compute the display width of the current code point
|
display_width += compute_width(sv);
|
||||||
size_t cp_width = compute_width(sv);
|
// Stop when display width exceeds precision.
|
||||||
if (display_width + cp_width > display_width_precision) {
|
if (display_width > precision) return false;
|
||||||
return false; // Stop iteration when display width exceeds precision
|
++num_code_points;
|
||||||
}
|
|
||||||
|
|
||||||
display_width += cp_width;
|
|
||||||
code_points++;
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
return code_point_index(s, num_code_points);
|
||||||
return code_points;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char, FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
|
||||||
FMT_CONSTEXPR auto handle_precision(
|
auto convert_precision_to_size(basic_string_view<Char>, size_t precision)
|
||||||
basic_string_view<Char> s, const format_specs& specs,
|
-> size_t {
|
||||||
FMT_ENABLE_IF(std::is_same<Char, char>::value)) -> size_t {
|
return precision;
|
||||||
auto code_points = count_code_points_with_display_width_precision(
|
|
||||||
s, to_unsigned(specs.precision));
|
|
||||||
return code_point_index(s, code_points);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
FMT_CONSTEXPR auto handle_precision(
|
|
||||||
basic_string_view<Char> s, const format_specs&,
|
|
||||||
FMT_ENABLE_IF(!std::is_same<Char, char>::value)) -> size_t {
|
|
||||||
return code_point_index(s, s.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename OutputIt>
|
template <typename Char, typename OutputIt>
|
||||||
@ -2151,9 +2134,8 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
|
|||||||
const format_specs& specs) -> OutputIt {
|
const format_specs& specs) -> OutputIt {
|
||||||
auto data = s.data();
|
auto data = s.data();
|
||||||
auto size = s.size();
|
auto size = s.size();
|
||||||
if (specs.precision >= 0 && to_unsigned(specs.precision) < size) {
|
if (specs.precision >= 0 && to_unsigned(specs.precision) < size)
|
||||||
size = handle_precision(s, specs);
|
size = convert_precision_to_size(s, to_unsigned(specs.precision));
|
||||||
}
|
|
||||||
|
|
||||||
bool is_debug = specs.type() == presentation_type::debug;
|
bool is_debug = specs.type() == presentation_type::debug;
|
||||||
if (is_debug) {
|
if (is_debug) {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
// For the license information refer to format.h.
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
// Check if fmt/format.h compiles with windows.h included before it.
|
// Check if fmt/format.h compiles with windows.h included before it.
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user