forked from fmtlib/fmt
Improve utf-8 detection
This commit is contained in:
@@ -420,7 +420,7 @@ struct is_std_string_like<T, void_t<decltype(std::declval<T>().find_first_of(
|
|||||||
typename T::value_type(), 0))>>
|
typename T::value_type(), 0))>>
|
||||||
: std::true_type {};
|
: 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";
|
FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char section[] = "\u00A7";
|
||||||
// Avoid an MSVC sign extension bug: https://github.com/fmtlib/fmt/pull/2297.
|
// Avoid an MSVC sign extension bug: https://github.com/fmtlib/fmt/pull/2297.
|
||||||
using uchar = unsigned char;
|
using uchar = unsigned char;
|
||||||
@@ -428,7 +428,11 @@ FMT_CONSTEXPR inline auto is_utf8() -> bool {
|
|||||||
uchar(section[1]) == 0xA7;
|
uchar(section[1]) == 0xA7;
|
||||||
static_assert(utf8 || !FMT_MSC_VERSION,
|
static_assert(utf8 || !FMT_MSC_VERSION,
|
||||||
"Unicode support requires compiling with /utf-8");
|
"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 {
|
template <typename Char> FMT_CONSTEXPR auto length(const Char* s) -> size_t {
|
||||||
|
@@ -23,12 +23,6 @@
|
|||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
#ifdef __cpp_char8_t
|
|
||||||
using char8_type = char8_t;
|
|
||||||
#else
|
|
||||||
enum char8_type : unsigned char {};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using is_exotic_char = bool_constant<!std::is_same<T, char>::value>;
|
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
|
#endif
|
||||||
|
|
||||||
template <> struct is_char<wchar_t> : std::true_type {};
|
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<char16_t> : std::true_type {};
|
||||||
template <> struct is_char<char32_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>
|
template <typename... T>
|
||||||
constexpr auto make_wformat_args(T&... args)
|
constexpr auto make_wformat_args(T&... args)
|
||||||
-> decltype(fmt::make_format_args<wformat_context>(args...)) {
|
-> decltype(fmt::make_format_args<wformat_context>(args...)) {
|
||||||
|
Reference in New Issue
Block a user