Refactor
This commit is contained in:
parent
7a94e60988
commit
5fd371ebe1
@ -1479,7 +1479,7 @@ using dword = conditional_t<sizeof(long) == 4, unsigned long, unsigned>;
|
|||||||
extern "C" __declspec(dllimport) int __stdcall WriteConsoleW( //
|
extern "C" __declspec(dllimport) int __stdcall WriteConsoleW( //
|
||||||
void*, const void*, dword, dword*, void*);
|
void*, const void*, dword, dword*, void*);
|
||||||
|
|
||||||
FMT_FUNC bool write_console_on_windows(std::FILE* f, string_view text) {
|
FMT_FUNC bool write_console(std::FILE* f, string_view text) {
|
||||||
auto fd = _fileno(f);
|
auto fd = _fileno(f);
|
||||||
if (_isatty(fd)) {
|
if (_isatty(fd)) {
|
||||||
detail::utf8_to_utf16 u16(string_view(text.data(), text.size()));
|
detail::utf8_to_utf16 u16(string_view(text.data(), text.size()));
|
||||||
@ -1500,7 +1500,7 @@ FMT_FUNC bool write_console_on_windows(std::FILE* f, string_view text) {
|
|||||||
|
|
||||||
FMT_FUNC void print(std::FILE* f, string_view text) {
|
FMT_FUNC void print(std::FILE* f, string_view text) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (write_console_on_windows(f, text)) return;
|
if (write_console(f, text)) return;
|
||||||
#endif
|
#endif
|
||||||
detail::fwrite_fully(text.data(), 1, text.size(), f);
|
detail::fwrite_fully(text.data(), 1, text.size(), f);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -922,7 +922,7 @@ struct is_contiguous<basic_memory_buffer<T, SIZE, Allocator>> : std::true_type {
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
FMT_API bool write_console_on_windows(std::FILE* f, string_view text);
|
FMT_API bool write_console(std::FILE* f, string_view text);
|
||||||
#endif
|
#endif
|
||||||
FMT_API void print(std::FILE*, string_view);
|
FMT_API void print(std::FILE*, string_view);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,22 +85,11 @@ template class filebuf_access<filebuf_access_tag,
|
|||||||
decltype(&filebuf_type::_Myfile),
|
decltype(&filebuf_type::_Myfile),
|
||||||
&filebuf_type::_Myfile>;
|
&filebuf_type::_Myfile>;
|
||||||
|
|
||||||
inline bool write_ostream_msvc_unicode(std::ostream& os,
|
inline bool write_ostream_unicode(std::ostream& os, fmt::string_view data) {
|
||||||
fmt::string_view data) {
|
#if FMT_MSC_VERSION
|
||||||
#ifdef _WIN32
|
|
||||||
if (auto* buf = dynamic_cast<std::filebuf*>(os.rdbuf()))
|
if (auto* buf = dynamic_cast<std::filebuf*>(os.rdbuf()))
|
||||||
if (FILE* f = get_file(*buf)) return write_console_on_windows(f, data);
|
if (FILE* f = get_file(*buf)) return write_console(f, data);
|
||||||
#endif
|
#elif defined(_WIN32) && defined(__GLIBCXX__)
|
||||||
return false;
|
|
||||||
}
|
|
||||||
inline bool write_ostream_msvc_unicode(std::wostream&,
|
|
||||||
fmt::basic_string_view<wchar_t>) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(__GLIBCXX__)
|
|
||||||
inline bool write_ostream_gcc_mingw_unicode(std::ostream& os,
|
|
||||||
fmt::string_view data) {
|
|
||||||
auto* rdbuf = os.rdbuf();
|
auto* rdbuf = os.rdbuf();
|
||||||
FILE* c_file;
|
FILE* c_file;
|
||||||
if (auto* fbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char>*>(rdbuf))
|
if (auto* fbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char>*>(rdbuf))
|
||||||
@ -109,26 +98,23 @@ inline bool write_ostream_gcc_mingw_unicode(std::ostream& os,
|
|||||||
c_file = fbuf->file();
|
c_file = fbuf->file();
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
if (c_file) return write_console_on_windows(c_file, data);
|
if (c_file) return write_console(c_file, data);
|
||||||
return false;
|
#else
|
||||||
}
|
(void)os; // suppress warning
|
||||||
|
(void)data;
|
||||||
inline bool write_ostream_gcc_mingw_unicode(std::wostream&,
|
|
||||||
fmt::basic_string_view<wchar_t>) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inline bool write_ostream_unicode(std::wostream&,
|
||||||
|
fmt::basic_string_view<wchar_t>) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Write the content of buf to os.
|
// Write the content of buf to os.
|
||||||
// It is a separate function rather than a part of vprint to simplify testing.
|
// It is a separate function rather than a part of vprint to simplify testing.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void write_buffer(std::basic_ostream<Char>& os, buffer<Char>& buf) {
|
void write_buffer(std::basic_ostream<Char>& os, buffer<Char>& buf) {
|
||||||
// TODO: check detail::is_utf8(). Here or bellow in print or in vprint?
|
if (write_ostream_unicode(os, {buf.data(), buf.size()})) return;
|
||||||
#if FMT_MSC_VERSION
|
|
||||||
if (write_ostream_msvc_unicode(os, {buf.data(), buf.size()})) return;
|
|
||||||
#elif defined(_WIN32) && defined(__GLIBCXX__)
|
|
||||||
if (write_ostream_gcc_mingw_unicode(os, {buf.data(), buf.size()})) return;
|
|
||||||
#endif
|
|
||||||
const Char* buf_data = buf.data();
|
const Char* buf_data = buf.data();
|
||||||
using unsigned_streamsize = std::make_unsigned<std::streamsize>::type;
|
using unsigned_streamsize = std::make_unsigned<std::streamsize>::type;
|
||||||
unsigned_streamsize size = buf.size();
|
unsigned_streamsize size = buf.size();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user