diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-12-12 15:00:43 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-12-14 07:52:39 +0000 |
commit | d545d36c8e11dcd974244a69d2beef726be9ed9d (patch) | |
tree | f072d31b8c9f96f84c4bf2d4862d5a7f5996bb91 /src/xml | |
parent | 88d5eb13d7a996772f38e9c9ab90befb3ae0c80d (diff) |
Remove QRegExp dependency from QtXml
Use QRegularExpression instead.
Change-Id: I6fc9400064ef6b7e425b140f5ffac0c9248c1ec0
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'src/xml')
-rw-r--r-- | src/xml/dom/qdom.cpp | 14 | ||||
-rw-r--r-- | src/xml/sax/qxml.cpp | 14 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 5893d8448e..a1f4d57da6 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -48,7 +48,9 @@ #include <qhash.h> #include <qiodevice.h> #include <qlist.h> -#include <qregexp.h> +#if QT_CONFIG(regularexpression) +#include <qregularexpression.h> +#endif #if QT_CONFIG(textcodec) #include <qtextcodec.h> #endif @@ -6430,7 +6432,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod const QDomNodePrivate* n = first; if(encUsed == QDomNode::EncodingFromDocument) { -#if QT_CONFIG(textcodec) +#if QT_CONFIG(textcodec) && QT_CONFIG(regularexpression) const QDomNodePrivate* n = first; QTextCodec *codec = 0; @@ -6438,11 +6440,11 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod if (n && n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) { // we have an XML declaration QString data = n->nodeValue(); - QRegExp encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))")); - encoding.indexIn(data); - QString enc = encoding.cap(3); + QRegularExpression encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))")); + auto match = encoding.match(data); + QString enc = match.captured(3); if (enc.isEmpty()) - enc = encoding.cap(5); + enc = match.captured(5); if (!enc.isEmpty()) codec = QTextCodec::codecForName(std::move(enc).toLatin1()); } diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index 7b6669b057..fa31e71cc1 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -43,7 +43,9 @@ #include "qtextcodec.h" #endif #include "qbuffer.h" -#include "qregexp.h" +#if QT_CONFIG(regularexpression) +#include "qregularexpression.h" +#endif #include "qmap.h" #include "qhash.h" #include "qstack.h" @@ -193,19 +195,23 @@ static const signed char charLookupTable[256]={ */ static bool stripTextDecl(QString& str) { - QString textDeclStart(QLatin1String("<?xml")); + QLatin1String textDeclStart("<?xml"); if (str.startsWith(textDeclStart)) { - QRegExp textDecl(QString::fromLatin1( +#if QT_CONFIG(regularexpression) + QRegularExpression textDecl(QString::fromLatin1( "^<\\?xml\\s+" "(version\\s*=\\s*((['\"])[-a-zA-Z0-9_.:]+\\3))?" "\\s*" "(encoding\\s*=\\s*((['\"])[A-Za-z][-a-zA-Z0-9_.]*\\6))?" "\\s*\\?>" - )); + )); QString strTmp = str.replace(textDecl, QLatin1String("")); if (strTmp.length() != str.length()) return false; // external entity has wrong TextDecl str = strTmp; +#else + return false; +#endif } return true; } |