From 70843acfce65fd1731dd9d8ff64256cf23ff011c Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 30 Jan 2021 23:56:23 -0700 Subject: [PATCH] Revert "temporary remove regex replacement" This reverts commit fcd735283de751dc1c5b13701a55fb5b6961ac69. --- extensions/regexfilter.cpp | 25 +++++++++++++++++++------ extensions/regexfilter.ui | 10 ++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/extensions/regexfilter.cpp b/extensions/regexfilter.cpp index 69c1522..d4d1622 100644 --- a/extensions/regexfilter.cpp +++ b/extensions/regexfilter.cpp @@ -24,6 +24,7 @@ public: ui.setupUi(this); connect(ui.regexEdit, &QLineEdit::textEdited, this, &Window::SetRegex); + connect(ui.replaceEdit, &QLineEdit::textEdited, this, &Window::SetReplace); connect(ui.saveButton, &QPushButton::clicked, this, &Window::Save); setWindowTitle(REGEX_FILTER); @@ -40,13 +41,21 @@ public: ui.output->setText(QString(CURRENT_FILTER).arg(regex)); } + void SetReplace(QString replace) + { + ui.replaceEdit->setText(replace); + std::scoped_lock lock(m); + ::replace = S(replace); + } + private: void Save() { auto formatted = FormatString( - L"\xfeff|PROCESS|%s|FILTER|%s|END|\r\n", + L"\xfeff|PROCESS|%s|FILTER|%s|REPLACE|%s|END|\r\n", GetModuleFilename(GetSelectedProcessId()).value_or(FormatString(L"Error getting name of process 0x%X", GetSelectedProcessId())), - S(ui.regexEdit->text()) + S(ui.regexEdit->text()), + S(ui.replaceEdit->text()) ); std::ofstream(REGEX_SAVE_FILE, std::ios::binary | std::ios::app).write((const char*)formatted.c_str(), formatted.size() * sizeof(wchar_t)); } @@ -61,10 +70,14 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) if (sentenceInfo["current select"] && !regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"])) { std::ifstream stream(REGEX_SAVE_FILE, std::ios::binary); - BlockMarkupIterator savedFilters(stream, Array{ L"|PROCESS|", L"|FILTER|" }); - std::vector regexes; - while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read->at(1))); - if (!regexes.empty()) QMetaObject::invokeMethod(&window, std::bind(&Window::SetRegex, &window, S(regexes.back())), Qt::BlockingQueuedConnection); + BlockMarkupIterator savedFilters(stream, Array{ L"|PROCESS|", L"|FILTER|", L"|REPLACE|" }); + std::vector> regexes; + while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read.value())); + if (!regexes.empty()) QMetaObject::invokeMethod(&window, [regex = S(regexes.back()[1]), replace = S(regexes.back()[2])] + { + window.SetRegex(regex); + window.SetReplace(replace); + }, Qt::BlockingQueuedConnection); } std::shared_lock lock(m); if (regex) sentence = std::regex_replace(sentence, regex.value(), replace); diff --git a/extensions/regexfilter.ui b/extensions/regexfilter.ui index add034b..e22914b 100644 --- a/extensions/regexfilter.ui +++ b/extensions/regexfilter.ui @@ -16,6 +16,16 @@ + + + + => + + + + + +