From 53f8f233692b6f9cd622eafbf669c5f8bdb0a25d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 18 Mar 2020 11:19:19 +0100 Subject: 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 Reviewed-by: Samuel Gaist --- src/tools/rcc/rcc.cpp | 13 ++++++-- tests/auto/tools/CMakeLists.txt | 2 +- tests/auto/tools/rcc/CMakeLists.txt | 66 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/auto/tools/rcc/CMakeLists.txt diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 808208573a..8b1ebad14c 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -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(); diff --git a/tests/auto/tools/CMakeLists.txt b/tests/auto/tools/CMakeLists.txt index aa45587993..048051663d 100644 --- a/tests/auto/tools/CMakeLists.txt +++ b/tests/auto/tools/CMakeLists.txt @@ -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() diff --git a/tests/auto/tools/rcc/CMakeLists.txt b/tests/auto/tools/rcc/CMakeLists.txt new file mode 100644 index 0000000000..06d62244ff --- /dev/null +++ b/tests/auto/tools/rcc/CMakeLists.txt @@ -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} +) + -- cgit v1.2.3