summaryrefslogtreecommitdiffstats
path: root/Source/QtDialog/RegexExplorer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/QtDialog/RegexExplorer.cxx')
-rw-r--r--Source/QtDialog/RegexExplorer.cxx80
1 files changed, 30 insertions, 50 deletions
diff --git a/Source/QtDialog/RegexExplorer.cxx b/Source/QtDialog/RegexExplorer.cxx
index dfcf048..d23a08c 100644
--- a/Source/QtDialog/RegexExplorer.cxx
+++ b/Source/QtDialog/RegexExplorer.cxx
@@ -12,16 +12,16 @@
#include "RegexExplorer.h"
-RegexExplorer::RegexExplorer(QWidget* p) : QDialog(p), m_matched(false)
+RegexExplorer::RegexExplorer(QWidget* p)
+ : QDialog(p)
+ , m_matched(false)
{
this->setupUi(this);
- for(int i = 1; i < cmsys::RegularExpression::NSUBEXP; ++i)
- {
- matchNumber->addItem(
- QString("Match %1").arg(QString::number(i)),
- QVariant(i));
- }
+ for (int i = 1; i < cmsys::RegularExpression::NSUBEXP; ++i) {
+ matchNumber->addItem(QString("Match %1").arg(QString::number(i)),
+ QVariant(i));
+ }
matchNumber->setCurrentIndex(0);
}
@@ -44,10 +44,9 @@ void RegexExplorer::on_regularExpression_textChanged(const QString& text)
bool validExpression =
stripEscapes(m_regex) && m_regexParser.compile(m_regex);
- if(!validExpression)
- {
+ if (!validExpression) {
m_regexParser.set_invalid();
- }
+ }
setStatusColor(labelRegexValid, validExpression);
@@ -56,8 +55,7 @@ void RegexExplorer::on_regularExpression_textChanged(const QString& text)
void RegexExplorer::on_inputText_textChanged()
{
- if(m_regexParser.is_valid())
- {
+ if (m_regexParser.is_valid()) {
QString plainText = inputText->toPlainText();
#ifdef QT_NO_STL
m_text = plainText.toAscii().constData();
@@ -65,19 +63,16 @@ void RegexExplorer::on_inputText_textChanged()
m_text = plainText.toStdString();
#endif
m_matched = m_regexParser.find(m_text);
- }
- else
- {
+ } else {
m_matched = false;
- }
+ }
setStatusColor(labelRegexMatch, m_matched);
- if(!m_matched)
- {
+ if (!m_matched) {
clearMatch();
return;
- }
+ }
#ifdef QT_NO_STL
QString matchText = m_regexParser.match(0).c_str();
@@ -91,18 +86,16 @@ void RegexExplorer::on_inputText_textChanged()
void RegexExplorer::on_matchNumber_currentIndexChanged(int index)
{
- if(!m_matched)
- {
+ if (!m_matched) {
return;
- }
+ }
QVariant itemData = matchNumber->itemData(index);
int idx = itemData.toInt();
- if(idx < 1 || idx >= cmsys::RegularExpression::NSUBEXP)
- {
+ if (idx < 1 || idx >= cmsys::RegularExpression::NSUBEXP) {
return;
- }
+ }
#ifdef QT_NO_STL
QString match = m_regexParser.match(idx).c_str();
@@ -125,42 +118,29 @@ bool RegexExplorer::stripEscapes(std::string& source)
std::string result;
result.reserve(source.size());
- for(char inc = *in; inc != '\0'; inc = *++in)
- {
- if(inc == '\\')
- {
+ for (char inc = *in; inc != '\0'; inc = *++in) {
+ if (inc == '\\') {
char nextc = in[1];
- if(nextc == 't')
- {
+ if (nextc == 't') {
result.append(1, '\t');
in++;
- }
- else if(nextc == 'n')
- {
+ } else if (nextc == 'n') {
result.append(1, '\n');
in++;
- }
- else if(nextc == 't')
- {
+ } else if (nextc == 't') {
result.append(1, '\t');
in++;
- }
- else if(isalnum(nextc) || nextc == '\0')
- {
+ } else if (isalnum(nextc) || nextc == '\0') {
return false;
- }
- else
- {
+ } else {
result.append(1, nextc);
in++;
- }
- }
- else
- {
- result.append(1, inc);
}
+ } else {
+ result.append(1, inc);
}
+ }
- source = result;
- return true;
+ source = result;
+ return true;
}