add regex filter

This commit is contained in:
Akash Mozumdar 2018-11-03 23:58:52 -04:00
parent 1ca9b3c8e6
commit 66d02a7bf0
6 changed files with 114 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Compress-Archive -Force -DestinationPath Textractor -Path @(
"Copy to Clipboard.dll", "Copy to Clipboard.dll",
"Extra Newlines.dll", "Extra Newlines.dll",
"Google Translate.dll", "Google Translate.dll",
"Regex Filter.dll",
"Remove Repetition.dll", "Remove Repetition.dll",
"Extensions.txt" "Extensions.txt"
) )
@ -28,6 +29,7 @@ Compress-Archive -Force -DestinationPath Textractor -Path @(
"Copy to Clipboard.dll", "Copy to Clipboard.dll",
"Extra Newlines.dll", "Extra Newlines.dll",
"Google Translate.dll", "Google Translate.dll",
"Regex Filter.dll",
"Remove Repetition.dll", "Remove Repetition.dll",
"Extensions.txt" "Extensions.txt"
) )

View File

@ -7,6 +7,10 @@ cmake_policy(SET CMP0037 OLD)
add_library(Bing\ Translate SHARED bingtranslate/bingtranslate.cpp extensionimpl.cpp) add_library(Bing\ Translate SHARED bingtranslate/bingtranslate.cpp extensionimpl.cpp)
add_library(Copy\ to\ Clipboard SHARED copyclipboard/copyclipboard.cpp extensionimpl.cpp) add_library(Copy\ to\ Clipboard SHARED copyclipboard/copyclipboard.cpp extensionimpl.cpp)
add_library(Extra\ Newlines SHARED extranewlines/extranewlines.cpp extensionimpl.cpp) add_library(Extra\ Newlines SHARED extranewlines/extranewlines.cpp extensionimpl.cpp)
add_library(Google\ Translate SHARED googletranslate/googletranslate.cpp extensionimpl.cpp)
add_library(Regex\ Filter SHARED regexfilter/regexfilter.cpp regexfilter/window.cpp extensionimpl.cpp)
add_library(Remove\ Repetition SHARED removerepeat/removerepeat.cpp extensionimpl.cpp) add_library(Remove\ Repetition SHARED removerepeat/removerepeat.cpp extensionimpl.cpp)
target_link_libraries(Bing\ Translate winhttp Qt5::Widgets) target_link_libraries(Bing\ Translate winhttp Qt5::Widgets)
target_link_libraries(Google\ Translate winhttp Qt5::Widgets)
target_link_libraries(Regex\ Filter Qt5::Widgets)

View File

@ -0,0 +1,31 @@
#include "../extension.h"
#include "window.h"
#include <QTimer>
Window* w = nullptr;
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
QTimer::singleShot(0, [] { (w = new Window)->show(); });
}
break;
case DLL_PROCESS_DETACH:
{
delete w;
}
break;
}
return TRUE;
}
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
if (w == nullptr) return false;
std::lock_guard l(w->locker);
sentence = std::regex_replace(sentence, w->regex, L"");
return true;
}

View File

@ -0,0 +1,21 @@
#include "window.h"
#include "ui_window.h"
Window::Window(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Window)
{
ui->setupUi(this);
}
Window::~Window()
{
delete ui;
}
void Window::on_regexInput_textEdited(const QString& newRegex)
{
std::lock_guard<std::mutex> lock(locker);
try { regex = newRegex.toStdWString(); }
catch (...) {}
}

View File

@ -0,0 +1,30 @@
#ifndef WINDOW_H
#define WINDOW_H
#include <QMainWindow>
#include <QString>
#include <regex>
#include <mutex>
namespace Ui
{
class Window;
}
class Window : public QMainWindow
{
Q_OBJECT
public:
explicit Window(QWidget *parent = nullptr);
~Window();
Ui::Window* ui;
std::mutex locker;
std::wregex regex;
private slots:
void on_regexInput_textEdited(const QString& regex);
};
#endif // WINDOW_H

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Window</class>
<widget class="QMainWindow" name="Window">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>80</height>
</rect>
</property>
<property name="windowTitle">
<string>Regex Filter</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="regexInput"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>