From 5390e29d42316ac79aba2e3e10aa5adc1738b39f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 24 Dec 2019 08:20:54 -0800 Subject: [PATCH] Enable mojibake --- include/fmt/core.h | 16 ++++++++++------ include/fmt/format-inl.h | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 5812fca4..9862b85c 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1507,15 +1507,14 @@ inline std::basic_string format(const S& format_str, Args&&... args) { {internal::make_args_checked(format_str, args...)}); } -FMT_API void vprint(string_view format_str, format_args args); -FMT_API void vprint(std::FILE* f, string_view format_str, format_args args); -FMT_API void vprint_mojibake(std::FILE* f, string_view format_str, - format_args args); +FMT_API void vprint(string_view, format_args); +FMT_API void vprint(std::FILE*, string_view, format_args); +FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); /** \rst - Prints formatted data to the file *f*. For wide format strings, - *f* should be in wide-oriented mode set via ``fwide(f, 1)``. + Prints formatted data to the file *f*. For wide format strings *f* should be + in wide-oriented mode set via ``fwide(f, 1)``. **Example**:: @@ -1525,8 +1524,13 @@ FMT_API void vprint_mojibake(std::FILE* f, string_view format_str, template ::value)> inline void print(std::FILE* f, const S& format_str, Args&&... args) { +#if !defined(_WIN32) || FMT_UNICODE vprint(f, to_string_view(format_str), internal::make_args_checked(format_str, args...)); +#else + vprint_mojibake(f, to_string_view(format_str), + internal::make_args_checked(format_str, args...)); +#endif } /** diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 5e326d6d..1d9a9e74 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -21,7 +21,7 @@ # include #endif -#if FMT_UNICODE +#ifdef _WIN32 # include # include #endif @@ -1345,7 +1345,7 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { memory_buffer buffer; internal::vformat_to(buffer, format_str, basic_format_args>(args)); -#if defined(_WIN32) && FMT_UNICODE +#ifdef _WIN32 auto fd = _fileno(f); if (_isatty(fd)) { internal::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size())); @@ -1361,6 +1361,7 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { } #ifdef _WIN32 +// Print assuming legacy (non-Unicode) encoding. FMT_FUNC void vprint_mojibake(std::FILE* f, string_view format_str, format_args args) { memory_buffer buffer;