mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Make precision computation consistent with width
This commit is contained in:
@ -680,8 +680,8 @@ FMT_CONSTEXPR inline size_t compute_width(string_view s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline auto compute_width(basic_string_view<char8_type> s) -> size_t {
|
inline auto compute_width(basic_string_view<char8_type> s) -> size_t {
|
||||||
return compute_width(basic_string_view<char>(
|
return compute_width(
|
||||||
reinterpret_cast<const char*>(s.data()), s.size()));
|
string_view(reinterpret_cast<const char*>(s.data()), s.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
@ -691,9 +691,8 @@ inline auto code_point_index(basic_string_view<Char> s, size_t n) -> size_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculates the index of the nth code point in a UTF-8 string.
|
// Calculates the index of the nth code point in a UTF-8 string.
|
||||||
inline auto code_point_index(basic_string_view<char8_type> s, size_t n)
|
inline auto code_point_index(string_view s, size_t n) -> size_t {
|
||||||
-> size_t {
|
const char* data = s.data();
|
||||||
const char8_type* data = s.data();
|
|
||||||
size_t num_code_points = 0;
|
size_t num_code_points = 0;
|
||||||
for (size_t i = 0, size = s.size(); i != size; ++i) {
|
for (size_t i = 0, size = s.size(); i != size; ++i) {
|
||||||
if ((data[i] & 0xc0) != 0x80 && ++num_code_points > n) return i;
|
if ((data[i] & 0xc0) != 0x80 && ++num_code_points > n) return i;
|
||||||
@ -701,6 +700,12 @@ inline auto code_point_index(basic_string_view<char8_type> s, size_t n)
|
|||||||
return s.size();
|
return s.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline auto code_point_index(basic_string_view<char8_type> s, size_t n)
|
||||||
|
-> size_t {
|
||||||
|
return code_point_index(
|
||||||
|
string_view(reinterpret_cast<const char*>(s.data()), s.size()), n);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef FMT_USE_FLOAT128
|
#ifndef FMT_USE_FLOAT128
|
||||||
# ifdef __SIZEOF_FLOAT128__
|
# ifdef __SIZEOF_FLOAT128__
|
||||||
# define FMT_USE_FLOAT128 1
|
# define FMT_USE_FLOAT128 1
|
||||||
|
@ -1035,6 +1035,7 @@ TEST(format_test, precision) {
|
|||||||
format_error, "number is too big");
|
format_error, "number is too big");
|
||||||
|
|
||||||
EXPECT_EQ("st", fmt::format("{0:.2}", "str"));
|
EXPECT_EQ("st", fmt::format("{0:.2}", "str"));
|
||||||
|
EXPECT_EQ("вожык", fmt::format("{0:.5}", "вожыкі"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(format_test, runtime_precision) {
|
TEST(format_test, runtime_precision) {
|
||||||
|
Reference in New Issue
Block a user