diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-15 18:26:54 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-03-16 22:03:55 +0100 |
commit | 99813301572ca2054fdf428e580ac4d009ca8e6f (patch) | |
tree | f4493c7067954ac750148f6d837422e61713bc31 /src/gui | |
parent | bc64ccbf00ba09e54240015bc476914b9f4f893d (diff) |
Get rid of QRegExp from the xpm image handler
Change-Id: Ic6bc89c7ffbf1c2f615e9b89aff7c64201ac2837
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qxpmhandler.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index 07fec929bf..5dcc915a57 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -45,7 +45,6 @@ #include <qbytearraymatcher.h> #include <qimage.h> #include <qmap.h> -#include <qregexp.h> #include <qtextstream.h> #include <qvariant.h> @@ -766,17 +765,26 @@ static QString fbname(const QString &fileName) // get file basename (sort of) { QString s = fileName; if (!s.isEmpty()) { - int i; - if ((i = s.lastIndexOf(QLatin1Char('/'))) >= 0) - s = s.mid(i); - if ((i = s.lastIndexOf(QLatin1Char('\\'))) >= 0) - s = s.mid(i); - QRegExp r(QLatin1String("[a-zA-Z][a-zA-Z0-9_]*")); - int p = r.indexIn(s); - if (p == -1) + int i = qMax(s.lastIndexOf(QLatin1Char('/')), s.lastIndexOf(QLatin1Char('\\'))); + if (i < 0) + i = 0; + auto isAsciiLetterOrNumber = [](QChar ch) -> bool { + return (ch.unicode() >= '0' && ch.unicode() <= '9') || + (ch.unicode() >= 'A' && ch.unicode() <= 'Z') || + (ch.unicode() >= 'a' && ch.unicode() <= 'z') || + ch.unicode() == '_'; + }; + int start = -1; + for (; i < s.length(); ++i) { + if (isAsciiLetterOrNumber(s.at(i))) { + start = i; + } else if (start > 0) + break; + } + if (start < 0) s.clear(); else - s = s.mid(p, r.matchedLength()); + s = s.mid(start, i - start); } if (s.isEmpty()) s = QString::fromLatin1("dummy"); |