From b64a94516b7c789fd36a7a2d4a7ecec10c3bfe17 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 4 Feb 2016 23:07:26 +0100 Subject: [PATCH] Get rid of the QRegExp dependency in qxmlutils. This makes the XML parser 100% independent of having regexp support enabled. Change-Id: I73004b0fb71e8086618995c71a985a86c292df3d Reviewed-by: Robin Burchell Reviewed-by: Thiago Macieira --- src/corelib/xml/qxmlutils.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/corelib/xml/qxmlutils.cpp b/src/corelib/xml/qxmlutils.cpp index 51c52cd3d0..23caae2935 100644 --- a/src/corelib/xml/qxmlutils.cpp +++ b/src/corelib/xml/qxmlutils.cpp @@ -37,7 +37,6 @@ ** ****************************************************************************/ -#include #include #include "qxmlutils_p.h" @@ -230,14 +229,20 @@ bool QXmlUtils::isBaseChar(const QChar c) */ bool QXmlUtils::isEncName(const QString &encName) { - /* Right, we here have a dependency on QRegExp. Writing a manual parser to - * replace that regexp is probably a 70 lines so I prioritize this to when - * the dependency is considered alarming, or when the rest of the bugs - * are fixed. */ - QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); - Q_ASSERT(encNameRegExp.isValid()); - - return encNameRegExp.exactMatch(encName); + // Valid encoding names are given by "[A-Za-z][A-Za-z0-9._\\-]*" + const ushort *c = encName.utf16(); + int l = encName.length(); + if (l < 1 || !((c[0] >= 'a' && c[0] <= 'z') || (c[0] >= 'A' && c[0] <= 'Z'))) + return false; + for (int i = 1; i < l; ++i) { + if ((c[i] >= 'a' && c[i] <= 'z') + || (c[i] >= 'A' && c[i] <= 'Z') + || (c[i] >= '0' && c[i] <= '9') + || c[i] == '.' || c[i] == '_' || c[i] == '-') + continue; + return false; + } + return true; } /*!