From 4164078c8540bbf75b47afd5c1bee0acbbd5b253 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 27 Dec 2016 16:38:09 +0100 Subject: cmake-gui: Add MATCHALL option to Regex Explorer Closes: #16204 --- Source/QtDialog/RegexExplorer.cxx | 34 ++++++++++++++++++++++++++++++++-- Source/QtDialog/RegexExplorer.h | 1 + Source/QtDialog/RegexExplorer.ui | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Source/QtDialog/RegexExplorer.cxx b/Source/QtDialog/RegexExplorer.cxx index 1512166..abed70e 100644 --- a/Source/QtDialog/RegexExplorer.cxx +++ b/Source/QtDialog/RegexExplorer.cxx @@ -64,10 +64,32 @@ void RegexExplorer::on_inputText_textChanged() return; } + std::string matchingText; + + if (matchAll->isChecked()) { + const char* p = m_text.c_str(); + while (m_regexParser.find(p)) { + std::string::size_type l = m_regexParser.start(); + std::string::size_type r = m_regexParser.end(); + if (r - l == 0) { + // matched empty string + clearMatch(); + return; + } + if (!matchingText.empty()) { + matchingText += ";"; + } + matchingText += std::string(p + l, r - l); + p += r; + } + } else { + matchingText = m_regexParser.match(0); + } + #ifdef QT_NO_STL - QString matchText = m_regexParser.match(0).c_str(); + QString matchText = matchingText.c_str(); #else - QString matchText = QString::fromStdString(m_regexParser.match(0)); + QString matchText = QString::fromStdString(matchingText); #endif match0->setPlainText(matchText); @@ -95,8 +117,16 @@ void RegexExplorer::on_matchNumber_currentIndexChanged(int index) matchN->setPlainText(match); } +void RegexExplorer::on_matchAll_toggled(bool checked) +{ + Q_UNUSED(checked); + + on_inputText_textChanged(); +} + void RegexExplorer::clearMatch() { + m_matched = false; match0->clear(); matchN->clear(); } diff --git a/Source/QtDialog/RegexExplorer.h b/Source/QtDialog/RegexExplorer.h index f1c1e5f..caef975 100644 --- a/Source/QtDialog/RegexExplorer.h +++ b/Source/QtDialog/RegexExplorer.h @@ -22,6 +22,7 @@ private slots: void on_regularExpression_textChanged(const QString& text); void on_inputText_textChanged(); void on_matchNumber_currentIndexChanged(int index); + void on_matchAll_toggled(bool checked); private: static void setStatusColor(QWidget* widget, bool successful); diff --git a/Source/QtDialog/RegexExplorer.ui b/Source/QtDialog/RegexExplorer.ui index 2c2d761..0af6999 100644 --- a/Source/QtDialog/RegexExplorer.ui +++ b/Source/QtDialog/RegexExplorer.ui @@ -104,11 +104,38 @@ - - - Complete Match - - + + + + + Complete Match + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + Match All + + + + -- cgit v0.12