move onnewsentence into own file
This commit is contained in:
parent
f7e3bbeb02
commit
199844987b
@ -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)
|
@ -1,4 +1,4 @@
|
||||
#include "extensions.h"
|
||||
#include "extension.h"
|
||||
|
||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||
{
|
||||
|
27
extensions/extension.h
Normal file
27
extensions/extension.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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(); }
|
@ -1,29 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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; }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "extensions.h"
|
||||
#include "extension.h"
|
||||
|
||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "extensions.h"
|
||||
#include "extension.h"
|
||||
#include <winhttp.h>
|
||||
#include <ctime>
|
||||
#include <regex>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "extensions.h"
|
||||
#include "extension.h"
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
|
||||
@ -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<std::pair<int64_t, std::wstring>> seenSentences;
|
||||
static std::mutex m;
|
||||
std::lock_guard<std::mutex> l(m);
|
||||
if (seenSentences.count({ handle, sentence }) != 0) throw InvalidSentence();
|
||||
if (seenSentences.count({ handle, sentence }) != 0) Skip();
|
||||
seenSentences.insert({ handle, sentence });
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user