diff options
author | Mikhail Redko <ovitnez@gmail.com> | 2021-04-11 20:41:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-11 19:41:44 +0200 |
commit | 1539bed3db86f2153f2d0d5fbf24bf9ee4af1d92 (patch) | |
tree | ed25236f21145d23d6e3a3fc9d7ff62675a13ba9 /src/common/Utilities/Util.cpp | |
parent | 6bdfa91fa795b24bfba6a4497784b693f6216638 (diff) |
Core/Misc: Fixed utf8 encoding in console input/output. (#26352)
* Core/Misc: Fixed utf8 encoding in console input/output.
* Fix gcc build
* Fixed that weird 'a' with circle above it and other similar letters. Also fixed encoding in AppenderConsole which sometimes did not work as it should
* Fix build on Linux
* Probably better to do it like this
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r-- | src/common/Utilities/Util.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index b1cb2824305..bf724629676 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -600,6 +600,40 @@ bool Utf8ToUpperOnlyLatin(std::string& utf8String) return WStrToUtf8(wstr, utf8String); } +#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS +bool ReadWinConsole(std::string& str, size_t size /*= 256*/) +{ + wchar_t* commandbuf = new wchar_t[size + 1]; + HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE); + DWORD read; + + if (!ReadConsoleW(hConsole, commandbuf, size, &read, NULL)) + { + delete[] commandbuf; + return false; + } + + commandbuf[read] = 0; + + bool ok = WStrToUtf8(commandbuf, wcslen(commandbuf), str); + delete[] commandbuf; + return ok; +} + +bool WriteWinConsole(std::string_view str, bool error /*= false*/) +{ + std::wstring wstr; + if (!Utf8toWStr(str, wstr)) + return false; + + HANDLE hConsole = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE); + DWORD toWrite = wstr.size(); + DWORD write; + + return WriteConsoleW(hConsole, wstr.c_str(), wstr.size(), &write, NULL); +} +#endif + std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */) { int32 init = 0; |