Get rid of QRegExp usage in rcc

As a drive-by, enable testing of rcc in the cmake build.

Change-Id: I4150ff3ffe7404bab0cbc72f80b23b47a60cf33d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
Lars Knoll 2020-03-18 11:19:19 +01:00
parent a7fe1af609
commit 53f8f23369
3 changed files with 78 additions and 3 deletions

View File

@ -37,7 +37,6 @@
#include <qfile.h>
#include <qiodevice.h>
#include <qlocale.h>
#include <qregexp.h>
#include <qstack.h>
#include <qxmlstream.h>
@ -1362,7 +1361,17 @@ bool RCCResourceLibrary::writeInitializer()
QString initNameStr = m_initName;
if (!initNameStr.isEmpty()) {
initNameStr.prepend(QLatin1Char('_'));
initNameStr.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
auto isAsciiLetterOrNumber = [] (QChar c) -> bool {
ushort ch = c.unicode();
return (ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= 'a' && ch <= 'z') ||
ch == '_';
};
for (QChar &c : initNameStr) {
if (!isAsciiLetterOrNumber(c))
c = QLatin1Char('_');
}
}
QByteArray initName = initNameStr.toLatin1();

View File

@ -7,7 +7,7 @@ if(NOT WIN32) # @todo: this is broken, see QTBUG-78449
endif()
# special case end
#add_subdirectory(moc)
#add_subdirectory(rcc)
add_subdirectory(rcc)
if(TARGET Qt::Widgets)
add_subdirectory(uic)
endif()

View File

@ -0,0 +1,66 @@
# Generated from rcc.pro.
#####################################################################
## tst_rcc Test:
#####################################################################
qt_add_test(tst_rcc
SOURCES
tst_rcc.cpp
)
# Resources:
set(images_resource_files
"images/circle.png"
"images/square.png"
"images/subdir/triangle.png"
)
qt_add_resource(tst_rcc "images"
PREFIX
"/"
BASE
"data/images"
FILES
${images_resource_files}
)
set(size-0_resource_files
"data/data-0.txt"
)
qt_add_resource(tst_rcc "size-0"
PREFIX
"/"
BASE
"data/sizes"
FILES
${size-0_resource_files}
)
set(size-2-0-35-1_resource_files
"data/data-0.txt"
"data/data-1.txt"
"data/data-2.txt"
"data/data-35.txt"
)
qt_add_resource(tst_rcc "size-2-0-35-1"
PREFIX
"/"
BASE
"data/sizes"
FILES
${size-2-0-35-1_resource_files}
)
set(size-1_resource_files
"data/data-1.txt"
)
qt_add_resource(tst_rcc "size-1"
PREFIX
"/"
BASE
"data/sizes"
FILES
${size-1_resource_files}
)