aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Util.cpp
diff options
context:
space:
mode:
authorMikhail Redko <ovitnez@gmail.com>2021-05-11 10:55:57 +0300
committerShauren <shauren.trinity@gmail.com>2022-03-09 14:55:18 +0100
commit9e6def8ae2119f2ab040698fb944f60b100410f8 (patch)
tree948f9c0ac2def8cdd0db8744a75fc82948b48656 /src/common/Utilities/Util.cpp
parentba51fb9ccb767a0b0996eb42e63e0d11742b4f2d (diff)
Core/Console: Improve ReadWinConsole logic and cosmetic changes (#26402)
* Core/Console: Improve ReadWinConsole logic and cosmetic changes * Core/Console: Fixed possible appearance of weird characters in the console when printing the output of child processes * Fix codestyle * Removed auto * Core/Misc: Explicit casting Difficulty values to uint8 before outputting to console * Core/Misc: Cast Difficulty to uint32 for output to console Co-authored-by: jackpoz <giacomopoz@gmail.com> (cherry picked from commit 6c12f45f3b7d7eab32ed29860d2261fc8a512f0e)
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r--src/common/Utilities/Util.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index 42cab23d9d4..c03159babec 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -792,7 +792,7 @@ bool ReadWinConsole(std::string& str, size_t size /*= 256*/)
HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
DWORD read = 0;
- if (!ReadConsoleW(hConsole, commandbuf, size, &read, nullptr))
+ if (!ReadConsoleW(hConsole, commandbuf, size, &read, nullptr) || read == 0)
{
delete[] commandbuf;
return false;
@@ -812,13 +812,22 @@ bool WriteWinConsole(std::string_view str, bool error /*= false*/)
return false;
HANDLE hConsole = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
- DWORD toWrite = wstr.size();
- DWORD write;
+ DWORD write = 0;
return WriteConsoleW(hConsole, wstr.c_str(), wstr.size(), &write, nullptr);
}
#endif
+TC_COMMON_API Optional<std::size_t> RemoveCRLF(std::string & str)
+{
+ std::size_t nextLineIndex = str.find_first_of("\r\n");
+ if (nextLineIndex == std::string::npos)
+ return std::nullopt;
+
+ str.erase(nextLineIndex);
+ return nextLineIndex;
+}
+
std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */)
{
int32 init = 0;