OSDN Git Service

optimize QXmlUtils::isEncName()
authorIvailo Monev <xakepa10@gmail.com>
Fri, 11 Sep 2020 15:38:57 +0000 (18:38 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 11 Sep 2020 15:39:58 +0000 (18:39 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/xml/kernel/qxmlutils.cpp

index 2764cb5..d0635a1 100644 (file)
@@ -31,7 +31,6 @@
 **
 ****************************************************************************/
 
-#include "qregexp.h"
 #include "qstring.h"
 
 #include "qxmlutils_p.h"
@@ -194,14 +193,24 @@ static inline bool isCombiningChar(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. */
-    const QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*"));
-    Q_ASSERT(encNameRegExp.isValid());
-
-    return encNameRegExp.exactMatch(encName);
+    if (encName.size() < 2)
+        return false;
+
+    const ushort first = encName.at(0).unicode();
+    if ((first >= 'a' && first <= 'z')
+        || (first >= 'A' && first <= 'Z'))
+    {
+        const ushort second = encName.at(1).unicode();
+        if ((second >= 'a' && second <= 'z')
+            || (second >= 'A' && second <= 'Z')
+            || (second >= '0' && second <= '9')
+            || second == '.' || second == '_' || second == '-')
+        {
+            return true;
+        }
+    }
+
+    return false;
 }
 
 /*!