From 3460b30fd5c13eaccb7bcb1d81195654ea17181f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 11 May 2024 18:58:40 -0700 Subject: [PATCH] Improve utf-8 detection --- include/fmt/base.h | 8 ++++++-- include/fmt/xchar.h | 12 +++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 2de369f5..aef46612 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -420,7 +420,7 @@ struct is_std_string_like().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 FMT_CONSTEXPR auto length(const Char* s) -> size_t { diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index a6bf47fe..aa695582 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -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 using is_exotic_char = bool_constant::value>; @@ -83,10 +77,14 @@ inline auto runtime(wstring_view s) -> runtime_format_string { #endif template <> struct is_char : std::true_type {}; -template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; +#ifdef __cpp_char8_t +template <> +struct is_char : bool_constant {}; +#endif + template constexpr auto make_wformat_args(T&... args) -> decltype(fmt::make_format_args(args...)) {