aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Util.cpp
diff options
context:
space:
mode:
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 6fa4825f06b..3fc026aaa74 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -607,7 +607,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;
@@ -627,13 +627,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;