mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 06:21:00 +00:00
Improve UTF-8 handling on Windows
This commit is contained in:
parent
3ca9533f38
commit
dac9a7f99d
@ -208,6 +208,13 @@
|
|||||||
# define FMT_USE_EXPERIMENTAL_STRING_VIEW
|
# define FMT_USE_EXPERIMENTAL_STRING_VIEW
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FMT_UNICODE
|
||||||
|
# define FMT_UNICODE 0
|
||||||
|
#endif
|
||||||
|
#if FMT_UNICODE
|
||||||
|
# pragma execution_character_set("utf-8")
|
||||||
|
#endif
|
||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// Implementations of enable_if_t and other metafunctions for pre-C++14 systems.
|
// Implementations of enable_if_t and other metafunctions for pre-C++14 systems.
|
||||||
|
@ -21,6 +21,11 @@
|
|||||||
# include <locale>
|
# include <locale>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FMT_UNICODE
|
||||||
|
#include <windows.h>
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning(push)
|
# pragma warning(push)
|
||||||
# pragma warning(disable : 4702) // unreachable code
|
# pragma warning(disable : 4702) // unreachable code
|
||||||
@ -1336,20 +1341,24 @@ FMT_FUNC void report_system_error(int error_code,
|
|||||||
report_error(format_system_error, error_code, message);
|
report_error(format_system_error, error_code, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FMT_UNICODE
|
|
||||||
# define FMT_UNICODE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
|
FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
|
||||||
memory_buffer buffer;
|
memory_buffer buffer;
|
||||||
internal::vformat_to(buffer, format_str,
|
internal::vformat_to(buffer, format_str,
|
||||||
basic_format_args<buffer_context<char>>(args));
|
basic_format_args<buffer_context<char>>(args));
|
||||||
#if FMT_UNICODE
|
#if defined(_WIN32) && FMT_UNICODE
|
||||||
internal::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
|
auto fd = _fileno(f);
|
||||||
std::fputws(u16.c_str(), f);
|
if (_isatty(fd)) {
|
||||||
#else
|
internal::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
|
||||||
internal::fwrite_fully(buffer.data(), 1, buffer.size(), f);
|
auto written = DWORD();
|
||||||
|
if (!WriteConsoleW(
|
||||||
|
reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
|
||||||
|
u16.c_str(), u16.size(), &written, nullptr)) {
|
||||||
|
throw format_error("failed to write to console");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
internal::fwrite_fully(buffer.data(), 1, buffer.size(), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_FUNC void vprint(string_view format_str, format_args args) {
|
FMT_FUNC void vprint(string_view format_str, format_args args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user