forked from Public-Mirror/Textractor
make StringToWideString pure
This commit is contained in:
parent
49c4af8c2c
commit
c50e2992bf
@ -165,7 +165,7 @@ namespace
|
|||||||
case HOST_NOTIFICATION_TEXT:
|
case HOST_NOTIFICATION_TEXT:
|
||||||
{
|
{
|
||||||
auto info = *(ConsoleOutputNotif*)buffer;
|
auto info = *(ConsoleOutputNotif*)buffer;
|
||||||
Host::AddConsoleOutput(Util::StringToWideString(info.message));
|
Host::AddConsoleOutput(Util::StringToWideString(info.message).value());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -308,7 +308,7 @@ namespace Host
|
|||||||
std::wstring GetHookName(DWORD processId, uint64_t addr)
|
std::wstring GetHookName(DWORD processId, uint64_t addr)
|
||||||
{
|
{
|
||||||
LOCK(hostMutex);
|
LOCK(hostMutex);
|
||||||
return Util::StringToWideString(processRecordsByIds.at(processId)->GetHook(addr).hookName);
|
return Util::StringToWideString(processRecordsByIds.at(processId)->GetHook(addr).hookName).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TextThread> GetThread(ThreadParam tp)
|
std::shared_ptr<TextThread> GetThread(ThreadParam tp)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "textthread.h"
|
#include "textthread.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
#include "text.h"
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -38,9 +39,9 @@ void TextThread::Push(const BYTE* data, int len)
|
|||||||
{
|
{
|
||||||
if (len < 0) return;
|
if (len < 0) return;
|
||||||
LOCK(bufferMutex);
|
LOCK(bufferMutex);
|
||||||
buffer += hp.type & USING_UNICODE
|
if (hp.type & USING_UNICODE) buffer += std::wstring((wchar_t*)data, len / 2);
|
||||||
? std::wstring((wchar_t*)data, len / 2)
|
else if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : defaultCodepage)) buffer += converted.value();
|
||||||
: Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : defaultCodepage);
|
else Host::AddConsoleOutput(INVALID_CODEPAGE);
|
||||||
if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear();
|
if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear();
|
||||||
lastPushTime = GetTickCount();
|
lastPushTime = GetTickCount();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "text.h"
|
|
||||||
#include "host.h"
|
|
||||||
|
|
||||||
namespace Util
|
namespace Util
|
||||||
{
|
{
|
||||||
@ -20,19 +18,11 @@ namespace Util
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring StringToWideString(std::string text, UINT encoding)
|
std::optional<std::wstring> StringToWideString(std::string text, UINT encoding)
|
||||||
{
|
{
|
||||||
std::wstring ret(text.size() + 1, 0);
|
std::vector<wchar_t> buffer(text.size() + 1);
|
||||||
if (int len = MultiByteToWideChar(encoding, 0, text.c_str(), -1, ret.data(), ret.size()))
|
if (MultiByteToWideChar(encoding, 0, text.c_str(), -1, buffer.data(), buffer.size())) return buffer.data();
|
||||||
{
|
else return {};
|
||||||
ret.resize(len - 1);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Host::AddConsoleOutput(INVALID_CODEPAGE);
|
|
||||||
return L"";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RemoveRepetition(std::wstring& text)
|
bool RemoveRepetition(std::wstring& text)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
namespace Util
|
namespace Util
|
||||||
{
|
{
|
||||||
std::optional<std::wstring> GetClipboardText();
|
std::optional<std::wstring> GetClipboardText();
|
||||||
std::wstring StringToWideString(std::string text, UINT encoding = CP_UTF8);
|
std::optional<std::wstring> StringToWideString(std::string text, UINT encoding = CP_UTF8);
|
||||||
// return true if repetition found (see https://github.com/Artikash/Textractor/issues/40)
|
// return true if repetition found (see https://github.com/Artikash/Textractor/issues/40)
|
||||||
bool RemoveRepetition(std::wstring& text);
|
bool RemoveRepetition(std::wstring& text);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user