2019-01-23 14:48:09 -05:00
|
|
|
|
#include "extension.h"
|
2018-12-28 11:57:06 -05:00
|
|
|
|
#include "defs.h"
|
2018-08-19 00:13:19 -04:00
|
|
|
|
|
2018-11-07 10:43:54 -05:00
|
|
|
|
void RemoveRepeatedChars(std::wstring& sentence)
|
2018-08-19 00:13:19 -04:00
|
|
|
|
{
|
2018-12-28 11:57:06 -05:00
|
|
|
|
std::vector<int> repeatNumbers(sentence.size() + 1, 0);
|
|
|
|
|
int repeatNumber = 1;
|
|
|
|
|
wchar_t prevChar = L'\0';
|
|
|
|
|
for (auto nextChar : sentence)
|
|
|
|
|
if (nextChar == prevChar) repeatNumber++;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
prevChar = nextChar;
|
|
|
|
|
++repeatNumbers.at(repeatNumber);
|
|
|
|
|
repeatNumber = 1;
|
|
|
|
|
}
|
|
|
|
|
if ((repeatNumber = std::distance(repeatNumbers.begin(), std::max_element(repeatNumbers.begin(), repeatNumbers.end()))) == 1) return;
|
2018-09-01 04:24:22 -04:00
|
|
|
|
|
2018-12-28 11:57:06 -05:00
|
|
|
|
std::wstring newSentence;
|
|
|
|
|
for (int i = 0; i < sentence.size();)
|
|
|
|
|
{
|
|
|
|
|
newSentence.push_back(sentence.at(i));
|
|
|
|
|
for (int j = i; j <= sentence.size(); ++j)
|
|
|
|
|
{
|
|
|
|
|
if (j == sentence.size() || sentence.at(i) != sentence.at(j))
|
|
|
|
|
{
|
|
|
|
|
i += (j - i) % repeatNumber == 0 ? repeatNumber : 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 02:50:03 -04:00
|
|
|
|
sentence = newSentence;
|
2018-09-01 04:24:22 -04:00
|
|
|
|
}
|
2018-08-19 00:13:19 -04:00
|
|
|
|
|
2018-11-07 10:43:54 -05:00
|
|
|
|
void RemoveCyclicRepeats(std::wstring& sentence)
|
2018-09-01 04:24:22 -04:00
|
|
|
|
{
|
2018-11-15 00:06:49 -05:00
|
|
|
|
remove:
|
2018-11-27 16:54:19 -05:00
|
|
|
|
for (std::wstring junk = sentence; junk.size() > 4; junk.pop_back())
|
2018-11-15 00:06:49 -05:00
|
|
|
|
if (sentence.rfind(junk) > 0)
|
|
|
|
|
{
|
|
|
|
|
sentence.erase(0, junk.size());
|
|
|
|
|
goto remove;
|
|
|
|
|
}
|
2018-09-01 04:24:22 -04:00
|
|
|
|
}
|
2018-08-19 00:13:19 -04:00
|
|
|
|
|
2018-09-22 15:08:31 -04:00
|
|
|
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
2018-09-01 04:24:22 -04:00
|
|
|
|
{
|
2018-09-22 15:08:31 -04:00
|
|
|
|
if (sentenceInfo["hook address"] == -1) return false;
|
2018-11-07 10:43:54 -05:00
|
|
|
|
RemoveRepeatedChars(sentence);
|
|
|
|
|
RemoveCyclicRepeats(sentence);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-12-28 11:57:06 -05:00
|
|
|
|
|
|
|
|
|
TEST(
|
|
|
|
|
{
|
|
|
|
|
std::wstring repeatedChars = L"aaaaaaaaaaaabbbbbbcccdddaabbbcccddd";
|
|
|
|
|
RemoveRepeatedChars(repeatedChars);
|
|
|
|
|
assert(repeatedChars.find(L"aaaabbcd") == 0);
|
|
|
|
|
|
|
|
|
|
std::wstring cyclicRepeats = L"abcdeabcdefabcdefgabcdefgabcdefgabcdefgabcdefg";
|
|
|
|
|
RemoveCyclicRepeats(cyclicRepeats);
|
|
|
|
|
assert(cyclicRepeats == L"abcdefg");
|
|
|
|
|
|
|
|
|
|
InfoForExtension tester{ "hook address", 0, nullptr };
|
2019-01-23 14:48:09 -05:00
|
|
|
|
std::wstring empty = L"", one = L" ", normal = L"This is a normal sentence. はい";
|
2018-12-28 11:57:06 -05:00
|
|
|
|
ProcessSentence(empty, { &tester });
|
|
|
|
|
ProcessSentence(one, { &tester });
|
|
|
|
|
ProcessSentence(normal, { &tester });
|
2019-01-23 16:11:14 -05:00
|
|
|
|
assert(empty == L"" && one == L" " && normal == L"This is a normal sentence. はい");
|
2018-12-28 11:57:06 -05:00
|
|
|
|
}
|
|
|
|
|
);
|