Commit cec8df95 authored by Ahmad Samir's avatar Ahmad Samir Committed by Christoph Cullmann
Browse files

[XMLTools Plugin] Port QRegExp to QRegularExpression

Port QRegExp::setMinimal() by making quantifiers in the pattern non-greedy.
All unit tests pass.
parent 541b79ed
...@@ -75,7 +75,7 @@ TODO: ...@@ -75,7 +75,7 @@ TODO:
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QPushButton> #include <QPushButton>
#include <QRegExp> #include <QRegularExpression>
#include <QStandardPaths> #include <QStandardPaths>
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
...@@ -388,16 +388,16 @@ void PluginKateXMLToolsCompletionModel::getDTD() ...@@ -388,16 +388,16 @@ void PluginKateXMLToolsCompletionModel::getDTD()
// <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
uint checkMaxLines = 200; uint checkMaxLines = 200;
QString documentStart = kv->document()->text(KTextEditor::Range(0, 0, checkMaxLines + 1, 0)); QString documentStart = kv->document()->text(KTextEditor::Range(0, 0, checkMaxLines + 1, 0));
QRegExp re("<!DOCTYPE\\s+(.*)\\s+PUBLIC\\s+[\"'](.*)[\"']", Qt::CaseInsensitive); const QRegularExpression re(QStringLiteral("<!DOCTYPE\\s+\\b(\\w+)\\b\\s+PUBLIC\\s+[\"\']([^\"\']+?)[\"\']"),
re.setMinimal(true); QRegularExpression::CaseInsensitiveOption);
int matchPos = re.indexIn(documentStart); const QRegularExpressionMatch match = re.match(documentStart);
QString filename; QString filename;
QString doctype; QString doctype;
QString topElement; QString topElement;
if (matchPos != -1) { if (match.hasMatch()) {
topElement = re.cap(1); topElement = match.captured(1);
doctype = re.cap(2); doctype = match.captured(2);
qDebug() << "Top element: " << topElement; qDebug() << "Top element: " << topElement;
qDebug() << "Doctype match: " << doctype; qDebug() << "Doctype match: " << doctype;
// XHTML: // XHTML:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment