Improve utf-8 detection

This commit is contained in:
Victor Zverovich 2024-05-11 18:58:40 -07:00
parent b7809f91e2
commit 3460b30fd5
2 changed files with 11 additions and 9 deletions

View File

@ -420,7 +420,7 @@ struct is_std_string_like<T, void_t<decltype(std::declval<T>().find_first_of(
typename T::value_type(), 0))>>
: std::true_type {};
FMT_CONSTEXPR inline auto is_utf8() -> bool {
FMT_CONSTEXPR inline auto is_utf8_enabled() -> bool {
FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char section[] = "\u00A7";
// Avoid an MSVC sign extension bug: https://github.com/fmtlib/fmt/pull/2297.
using uchar = unsigned char;
@ -428,7 +428,11 @@ FMT_CONSTEXPR inline auto is_utf8() -> bool {
uchar(section[1]) == 0xA7;
static_assert(utf8 || !FMT_MSC_VERSION,
"Unicode support requires compiling with /utf-8");
return FMT_UNICODE || utf8;
return utf8;
}
FMT_CONSTEXPR inline auto is_utf8() -> bool {
return FMT_UNICODE || is_utf8_enabled();
}
template <typename Char> FMT_CONSTEXPR auto length(const Char* s) -> size_t {

View File

@ -23,12 +23,6 @@
FMT_BEGIN_NAMESPACE
namespace detail {
#ifdef __cpp_char8_t
using char8_type = char8_t;
#else
enum char8_type : unsigned char {};
#endif
template <typename T>
using is_exotic_char = bool_constant<!std::is_same<T, char>::value>;
@ -83,10 +77,14 @@ inline auto runtime(wstring_view s) -> runtime_format_string<wchar_t> {
#endif
template <> struct is_char<wchar_t> : std::true_type {};
template <> struct is_char<detail::char8_type> : std::true_type {};
template <> struct is_char<char16_t> : std::true_type {};
template <> struct is_char<char32_t> : std::true_type {};
#ifdef __cpp_char8_t
template <>
struct is_char<char8_t> : bool_constant<detail::is_utf8_enabled()> {};
#endif
template <typename... T>
constexpr auto make_wformat_args(T&... args)
-> decltype(fmt::make_format_args<wformat_context>(args...)) {