mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
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
(cherry picked from commit 1539bed3db)
This commit is contained in:
@@ -785,6 +785,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;
|
||||
|
||||
Reference in New Issue
Block a user