Remove QRegExp dependency from QtXml

Use QRegularExpression instead.

Change-Id: I6fc9400064ef6b7e425b140f5ffac0c9248c1ec0
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
bb10
Lars Knoll 2018-12-12 15:00:43 +01:00
parent 88d5eb13d7
commit d545d36c8e
2 changed files with 18 additions and 10 deletions

View File

@ -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());
}

View File

@ -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;
}