| 1 | #include "extension.h" |
| 2 | |
| 3 | bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) |
| 4 | { |
| 5 | if (sentenceInfo["text number"] == 0) return false; |
| 6 | |
| 7 | // This algorithm looks at all the prefixes of the sentence: if a prefix is found later in the sentence, it is removed from the beginning and the process is repeated |
| 8 | auto timeout = GetTickCount64() + 30'000; // give up if taking over 30 seconds |
| 9 | auto data = std::make_unique<wchar_t[]>(sentence.size() + 1); |
| 10 | wcscpy_s(data.get(), sentence.size() + 1, sentence.c_str()); |
| 11 | wchar_t* dataEnd = data.get() + sentence.size(); |
| 12 | int skip = 0, count = 0; |
| 13 | for (wchar_t* end = dataEnd; end - data.get() > skip && GetTickCount64() < timeout; --end) |
| 14 | { |
| 15 | std::swap(*end, *dataEnd); |
| 16 | int junkLength = end - data.get() - skip; |
| 17 | auto junkFound = wcsstr(sentence.c_str() + skip + junkLength, data.get() + skip); |
| 18 | std::swap(*end, *dataEnd); |
| 19 | if (junkFound) |
| 20 | { |
| 21 | if (count && junkLength < min(skip / count, 4)) break; |
| 22 | skip += junkLength; |
| 23 | count += 1; |
| 24 | end = dataEnd; |
| 25 | } |
| 26 | } |
| 27 | if (count && skip / count >= 3) |
| 28 | { |
| 29 | sentence = data.get() + skip; |
| 30 | return true; |
| 31 | } |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | TEST( |
| 36 | { |
no outgoing calls
no test coverage detected