Tools: replace QRegExp with QRegularExpression
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
######################################################################
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET =
|
||||
TARGET = regexp
|
||||
DEPENDPATH += .
|
||||
INCLUDEPATH += .
|
||||
QT += widgets
|
||||
|
||||
# Input
|
||||
HEADERS += regexpdialog.h
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <qlabel.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qtextedit.h>
|
||||
|
||||
RegExpDialog::RegExpDialog(QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui_RegExpDialog())
|
||||
@@ -53,10 +52,15 @@ void RegExpDialog::performRegExp()
|
||||
return;
|
||||
}
|
||||
|
||||
QRegExp rx(txt);
|
||||
rx.setCaseSensitivity(ui->checkBox1->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
rx.setPatternSyntax(ui->checkBox2->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp);
|
||||
rx.setMinimal(ui->checkBox3->isChecked());
|
||||
QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
|
||||
if (ui->checkBox1->isChecked()) {
|
||||
options |= QRegularExpression::CaseInsensitiveOption;
|
||||
}
|
||||
if (ui->checkBox3->isChecked()) {
|
||||
options |= QRegularExpression::InvertedGreedinessOption;
|
||||
}
|
||||
|
||||
QRegularExpression rx(txt, options);
|
||||
|
||||
// evaluate regular expression
|
||||
ui->textLabel4->setText(rx.errorString());
|
||||
@@ -92,7 +96,7 @@ void RegExpSyntaxHighlighter::highlightBlock (const QString & text)
|
||||
regFormat.setFontWeight(QFont::Normal);
|
||||
setFormat(0, text.length(), regFormat);
|
||||
|
||||
if (regexp.isEmpty())
|
||||
if (regexp.pattern().isEmpty())
|
||||
return; // empty regular expression
|
||||
|
||||
int pos = 0;
|
||||
@@ -100,16 +104,17 @@ void RegExpSyntaxHighlighter::highlightBlock (const QString & text)
|
||||
regFormat.setFontWeight(QFont::Bold);
|
||||
regFormat.setForeground(Qt::blue);
|
||||
|
||||
while ((pos = regexp.indexIn(text, pos)) != -1) {
|
||||
QRegularExpressionMatch match;
|
||||
while ((pos = text.indexOf(regexp, pos, &match)) != -1) {
|
||||
if (last == pos)
|
||||
break;
|
||||
QString sub = text.mid(pos, regexp.matchedLength());
|
||||
QString sub = text.mid(pos, match.capturedLength());
|
||||
if (!sub.isEmpty()) {
|
||||
setFormat(pos, sub.length(), regFormat);
|
||||
}
|
||||
|
||||
pos += regexp.matchedLength();
|
||||
last=pos;
|
||||
pos += match.capturedLength();
|
||||
last = pos;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
@@ -142,7 +147,7 @@ int RegExpSyntaxHighlighter::highlightParagraph ( const QString & text, int /*en
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
void RegExpSyntaxHighlighter::highlightMatchedText(const QRegExp& rx)
|
||||
void RegExpSyntaxHighlighter::highlightMatchedText(const QRegularExpression& rx)
|
||||
{
|
||||
regexp = rx;
|
||||
rehighlight();
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
#define REG_EXP_DIALOG_H
|
||||
|
||||
#include <qdialog.h>
|
||||
#include <qregexp.h>
|
||||
#include <qregularexpression.h>
|
||||
#include <qsyntaxhighlighter.h>
|
||||
#include <qtextedit.h>
|
||||
|
||||
class RegExpSyntaxHighlighter;
|
||||
class Ui_RegExpDialog;
|
||||
@@ -57,11 +58,11 @@ public:
|
||||
|
||||
void highlightBlock (const QString & text);
|
||||
//int highlightParagraph ( const QString & text, int endStateOfLastPara );
|
||||
void highlightMatchedText( const QRegExp& );
|
||||
void highlightMatchedText( const QRegularExpression& );
|
||||
void resethighlight();
|
||||
|
||||
private:
|
||||
QRegExp regexp;
|
||||
QRegularExpression regexp;
|
||||
};
|
||||
|
||||
#endif // REG_EXP_DIALOG_H
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<item row="1" column="0">
|
||||
<widget class="QTextEdit" name="textEdit1"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
@@ -44,17 +44,7 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox1">
|
||||
<property name="text">
|
||||
<string>Case sensitive</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox2">
|
||||
<property name="text">
|
||||
<string>Wildcard</string>
|
||||
<string>Case insensitive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -63,9 +53,6 @@
|
||||
<property name="text">
|
||||
<string>Minimal</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -146,7 +133,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
|
||||
Reference in New Issue
Block a user