Textractor_test/extensions/regexfilter.cpp

43 lines
961 B
C++
Raw Normal View History

#include "extension.h"
#include "ui_regexfilter.h"
2019-02-28 00:33:17 +08:00
extern const char* REGEX_FILTER;
extern const char* INVALID_REGEX;
extern const char* CURRENT_FILTER;
std::wregex regex;
2019-01-24 02:59:34 +08:00
std::shared_mutex m;
2019-06-21 13:29:48 +08:00
class Window : public QMainWindow
{
2019-06-21 13:29:48 +08:00
public:
Window()
{
ui.setupUi(this);
2019-06-21 13:29:48 +08:00
connect(ui.input, &QLineEdit::textEdited, this, &Window::setRegex);
setWindowTitle(REGEX_FILTER);
2019-06-21 13:29:48 +08:00
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
}
2019-06-21 13:29:48 +08:00
private:
void setRegex(QString newRegex)
{
2019-06-21 13:29:48 +08:00
std::lock_guard l(m);
try { regex = newRegex.toStdWString(); }
catch (std::regex_error) { return ui.output->setText(INVALID_REGEX); }
ui.output->setText(QString(CURRENT_FILTER).arg(newRegex));
}
2019-06-21 13:29:48 +08:00
Ui::FilterWindow ui;
} window;
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
2019-02-22 02:09:44 +08:00
if (sentenceInfo["text number"] == 0) return false;
2019-06-21 13:29:48 +08:00
std::shared_lock l(m);
sentence = std::regex_replace(sentence, regex, L"");
return true;
}