Detect /utf-8 in MSVC

This commit is contained in:
Victor Zverovich 2020-03-22 07:57:56 -07:00
parent dd97f4920c
commit 08ca40ea91

View File

@ -240,9 +240,9 @@
#endif #endif
#ifndef FMT_UNICODE #ifndef FMT_UNICODE
# define FMT_UNICODE 0 # define FMT_UNICODE !FMT_MSC_VER
#endif #endif
#if FMT_UNICODE #if FMT_UNICODE && FMT_MSC_VER
# pragma execution_character_set("utf-8") # pragma execution_character_set("utf-8")
#endif #endif
@ -324,6 +324,13 @@ FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
return static_cast<typename std::make_unsigned<Int>::type>(value); return static_cast<typename std::make_unsigned<Int>::type>(value);
} }
constexpr unsigned char micro[] = "\u00B5";
constexpr bool is_utf8() {
return FMT_UNICODE ||
(sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
}
#ifdef __cpp_char8_t #ifdef __cpp_char8_t
using char8_type = char8_t; using char8_type = char8_t;
#else #else
@ -1648,6 +1655,10 @@ typename buffer_context<Char>::iterator vformat_to(
basic_format_args<buffer_context<type_identity_t<Char>>> args); basic_format_args<buffer_context<type_identity_t<Char>>> args);
FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
#ifndef _WIN32
inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
#endif
} // namespace internal } // namespace internal
/** /**
@ -1738,14 +1749,12 @@ FMT_API void vprint(std::FILE*, string_view, format_args);
template <typename S, typename... Args, template <typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value)> FMT_ENABLE_IF(internal::is_string<S>::value)>
inline void print(std::FILE* f, const S& format_str, Args&&... args) { inline void print(std::FILE* f, const S& format_str, Args&&... args) {
#if !defined(_WIN32) || FMT_UNICODE return internal::is_utf8()
vprint(f, to_string_view(format_str), ? vprint(f, to_string_view(format_str),
internal::make_args_checked<Args...>(format_str, args...)); internal::make_args_checked<Args...>(format_str, args...))
#else : internal::vprint_mojibake(
internal::vprint_mojibake( f, to_string_view(format_str),
f, to_string_view(format_str), internal::make_args_checked<Args...>(format_str, args...));
internal::make_args_checked<Args...>(format_str, args...));
#endif
} }
/** /**
@ -1762,14 +1771,12 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) {
template <typename S, typename... Args, template <typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value)> FMT_ENABLE_IF(internal::is_string<S>::value)>
inline void print(const S& format_str, Args&&... args) { inline void print(const S& format_str, Args&&... args) {
#if !defined(_WIN32) || FMT_UNICODE return internal::is_utf8()
vprint(to_string_view(format_str), ? vprint(to_string_view(format_str),
internal::make_args_checked<Args...>(format_str, args...)); internal::make_args_checked<Args...>(format_str, args...))
#else : internal::vprint_mojibake(
internal::vprint_mojibake( stdout, to_string_view(format_str),
stdout, to_string_view(format_str), internal::make_args_checked<Args...>(format_str, args...));
internal::make_args_checked<Args...>(format_str, args...));
#endif
} }
FMT_END_NAMESPACE FMT_END_NAMESPACE