diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index e645da1..95d8407 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_policy(SET CMP0037 OLD) -add_library(256_Remove\ Repetition SHARED removerepeat.cpp) -add_library(512_Copy\ to\ Clipboard SHARED copyclipboard.cpp) -add_library(1024_Google\ Translate SHARED googletranslate.cpp) -add_library(2048_Extra\ Newlines SHARED extranewlines.cpp) +add_library(256_Remove\ Repetition SHARED removerepeat.cpp extensionimpl.cpp) +add_library(512_Copy\ to\ Clipboard SHARED copyclipboard.cpp extensionimpl.cpp) +add_library(1024_Google\ Translate SHARED googletranslate.cpp extensionimpl.cpp) +add_library(2048_Extra\ Newlines SHARED extranewlines.cpp extensionimpl.cpp) target_link_libraries(1024_Google\ Translate winhttp.lib) \ No newline at end of file diff --git a/extensions/copyclipboard.cpp b/extensions/copyclipboard.cpp index 920d0f1..9b344f8 100644 --- a/extensions/copyclipboard.cpp +++ b/extensions/copyclipboard.cpp @@ -1,4 +1,4 @@ -#include "extensions.h" +#include "extension.h" bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) { diff --git a/extensions/extension.h b/extensions/extension.h new file mode 100644 index 0000000..7731410 --- /dev/null +++ b/extensions/extension.h @@ -0,0 +1,27 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include + +struct InfoForExtension +{ + const char* name; + int64_t value; + InfoForExtension* next; +}; + +struct SentenceInfo +{ + const InfoForExtension* list; + // Traverse linked list to find info. + int64_t operator[](std::string propertyName) + { + for (auto i = list; i != nullptr; i = i->next) if (propertyName == i->name) return i->value; + throw; + } +}; + +struct SKIP {}; +inline void Skip() { throw SKIP(); } diff --git a/extensions/extensions.h b/extensions/extensionimpl.cpp similarity index 75% rename from extensions/extensions.h rename to extensions/extensionimpl.cpp index 9b6e769..794d91b 100644 --- a/extensions/extensions.h +++ b/extensions/extensionimpl.cpp @@ -1,29 +1,4 @@ -#pragma once - -#define WIN32_LEAN_AND_MEAN -#include -#include -#include - -struct InfoForExtension -{ - const char* name; - int64_t value; - InfoForExtension* next; -}; - -struct SentenceInfo -{ - const InfoForExtension* list; - // Traverse linked list to find info. - int64_t operator[](std::string propertyName) - { - for (auto i = list; i != nullptr; i = i->next) if (propertyName == i->name) return i->value; - throw; - } -}; - -struct InvalidSentence {}; +#include "extension.h" bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo); @@ -52,5 +27,5 @@ extern "C" __declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sen } else return sentence; } - catch (InvalidSentence) { return nullptr; } + catch (SKIP) { return nullptr; } } diff --git a/extensions/extranewlines.cpp b/extensions/extranewlines.cpp index 210c491..d0fb344 100644 --- a/extensions/extranewlines.cpp +++ b/extensions/extranewlines.cpp @@ -1,4 +1,4 @@ -#include "extensions.h" +#include "extension.h" bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) { diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index a405196..44d4ff1 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -1,4 +1,4 @@ -#include "extensions.h" +#include "extension.h" #include #include #include diff --git a/extensions/removerepeat.cpp b/extensions/removerepeat.cpp index 09996bc..b0baa0a 100644 --- a/extensions/removerepeat.cpp +++ b/extensions/removerepeat.cpp @@ -1,4 +1,4 @@ -#include "extensions.h" +#include "extension.h" #include #include @@ -25,7 +25,7 @@ bool RemoveRepeatedChars(std::wstring& sentence) bool RemoveCyclicRepeats(std::wstring& sentence) { - if (sentence == L"") throw InvalidSentence(); + if (sentence == L"") Skip(); int junkLength = 0; wchar_t junk[2000] = {}; while (wcsstr(sentence.c_str() + junkLength, junk)) @@ -47,7 +47,7 @@ bool RemoveRepeatedSentences(std::wstring& sentence, int64_t handle) static std::set> seenSentences; static std::mutex m; std::lock_guard l(m); - if (seenSentences.count({ handle, sentence }) != 0) throw InvalidSentence(); + if (seenSentences.count({ handle, sentence }) != 0) Skip(); seenSentences.insert({ handle, sentence }); return false; }