ignore extra parameters #947

This commit is contained in:
Akash Mozumdar 2023-04-21 19:42:43 -04:00
parent cfa11c5646
commit aa00d9e789
3 changed files with 10 additions and 7 deletions

View File

@ -174,12 +174,6 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
concurrency::concurrent_priority_queue<DWORD64, std::greater<DWORD64>> tokens; concurrency::concurrent_priority_queue<DWORD64, std::greater<DWORD64>> tokens;
} rateLimiter; } rateLimiter;
auto Trim = [](std::wstring& text)
{
text.erase(text.begin(), std::find_if_not(text.begin(), text.end(), iswspace));
text.erase(std::find_if_not(text.rbegin(), text.rend(), iswspace).base(), text.end());
};
bool cache = false; bool cache = false;
std::wstring translation; std::wstring translation;
if (useFilter) if (useFilter)

View File

@ -276,7 +276,9 @@ namespace HookCode
{ {
std::optional<HookParam> Parse(std::wstring code) std::optional<HookParam> Parse(std::wstring code)
{ {
if (code[0] == L'/') code.erase(0, 1); // legacy/AGTH compatibility if (code[0] == L'/') code.erase(0, 1);
code.erase(std::find(code.begin(), code.end(), L'/'), code.end()); // legacy/AGTH compatibility
Trim(code);
if (code[0] == L'R') return ParseRCode(code.erase(0, 1)); if (code[0] == L'R') return ParseRCode(code.erase(0, 1));
else if (code[0] == L'H') return ParseHCode(code.erase(0, 1)); else if (code[0] == L'H') return ParseHCode(code.erase(0, 1));
return {}; return {};
@ -292,6 +294,7 @@ namespace HookCode
assert(HexString(-12) == L"-C"), assert(HexString(-12) == L"-C"),
assert(HexString(12) == L"C"), assert(HexString(12) == L"C"),
assert(Parse(L"/HQN936#-c*C:C*1C@4AA:gdi.dll:GetTextOutA")), assert(Parse(L"/HQN936#-c*C:C*1C@4AA:gdi.dll:GetTextOutA")),
assert(Parse(L"/HQN936#-c*C:C*1C@4AA:gdi.dll:GetTextOutA /KF")),
assert(Parse(L"HB4@0")), assert(Parse(L"HB4@0")),
assert(Parse(L"/RS65001#@44")), assert(Parse(L"/RS65001#@44")),
assert(Parse(L"HQ@4")), assert(Parse(L"HQ@4")),

View File

@ -120,6 +120,12 @@ inline std::wstring FormatString(const wchar_t* format, const Args&... args)
} }
#pragma warning(pop) #pragma warning(pop)
inline void Trim(std::wstring& text)
{
text.erase(text.begin(), std::find_if_not(text.begin(), text.end(), iswspace));
text.erase(std::find_if_not(text.rbegin(), text.rend(), iswspace).base(), text.end());
}
inline std::optional<std::wstring> StringToWideString(const std::string& text, UINT encoding) inline std::optional<std::wstring> StringToWideString(const std::string& text, UINT encoding)
{ {
std::vector<wchar_t> buffer(text.size() + 1); std::vector<wchar_t> buffer(text.size() + 1);