summaryrefslogtreecommitdiffstats
path: root/src/tools/rcc
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-04-14 15:46:14 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2022-05-03 01:38:46 +0200
commit39a6307178603211e070580ed0c25ec65c0b8a70 (patch)
treee3f95d155a92a0d9c49f6694d9aa4874d49764d0 /src/tools/rcc
parenta0539ed53f45619df7e4aad664369301dd6da091 (diff)
Tools: use _L1 for for creating Latin-1 string literals
As a drive-by, fix qsizetype -> int narrowing conversion warnings for the touched lines. Task-number: QTBUG-98434 Change-Id: I6d4712a71b5ebf3f379f1f98ea476557bce963ef Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/tools/rcc')
-rw-r--r--src/tools/rcc/main.cpp54
-rw-r--r--src/tools/rcc/rcc.cpp55
2 files changed, 56 insertions, 53 deletions
diff --git a/src/tools/rcc/main.cpp b/src/tools/rcc/main.cpp
index 14da7099e5..0be339dce2 100644
--- a/src/tools/rcc/main.cpp
+++ b/src/tools/rcc/main.cpp
@@ -49,6 +49,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
void dumpRecursive(const QDir &dir, QTextStream &out)
{
const QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot
@@ -57,9 +59,9 @@ void dumpRecursive(const QDir &dir, QTextStream &out)
if (entry.isDir()) {
dumpRecursive(entry.filePath(), out);
} else {
- out << QLatin1String("<file>")
+ out << "<file>"_L1
<< entry.filePath()
- << QLatin1String("</file>\n");
+ << "</file>\n"_L1;
}
}
}
@@ -69,7 +71,7 @@ int createProject(const QString &outFileName)
QDir currentDir = QDir::current();
QString currentDirName = currentDir.dirName();
if (currentDirName.isEmpty())
- currentDirName = QLatin1String("root");
+ currentDirName = "root"_L1;
QFile file;
bool isOk = false;
@@ -87,14 +89,14 @@ int createProject(const QString &outFileName)
}
QTextStream out(&file);
- out << QLatin1String("<!DOCTYPE RCC><RCC version=\"1.0\">\n"
- "<qresource>\n");
+ out << "<!DOCTYPE RCC><RCC version=\"1.0\">\n"
+ "<qresource>\n"_L1;
// use "." as dir to get relative file paths
- dumpRecursive(QDir(QLatin1String(".")), out);
+ dumpRecursive(QDir("."_L1), out);
- out << QLatin1String("</qresource>\n"
- "</RCC>\n");
+ out << "</qresource>\n"
+ "</RCC>\n"_L1;
return 0;
}
@@ -105,11 +107,11 @@ QString makefileEscape(const QString &filepath)
// Always use forward slashes
QString result = QDir::cleanPath(filepath);
// Spaces are escaped with a backslash
- result.replace(u' ', QLatin1String("\\ "));
+ result.replace(u' ', "\\ "_L1);
// Pipes are escaped with a backslash
- result.replace(u'|', QLatin1String("\\|"));
+ result.replace(u'|', "\\|"_L1);
// Dollars are escaped with a dollar
- result.replace(u'$', QLatin1String("$$"));
+ result.replace(u'$', "$$"_L1);
return result;
}
@@ -139,7 +141,7 @@ int runRcc(int argc, char *argv[])
// If you use this code as an example for a translated app, make sure to translate the strings.
QCommandLineParser parser;
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
- parser.setApplicationDescription(QLatin1String("Qt Resource Compiler version " QT_VERSION_STR));
+ parser.setApplicationDescription("Qt Resource Compiler version " QT_VERSION_STR ""_L1);
parser.addHelpOption();
parser.addVersionOption();
@@ -233,9 +235,9 @@ int runRcc(int argc, char *argv[])
bool ok = false;
formatVersion = parser.value(formatVersionOption).toUInt(&ok);
if (!ok) {
- errorMsg = QLatin1String("Invalid format version specified");
+ errorMsg = "Invalid format version specified"_L1;
} else if (formatVersion < 1 || formatVersion > 3) {
- errorMsg = QLatin1String("Unsupported format version specified");
+ errorMsg = "Unsupported format version specified"_L1;
}
}
@@ -245,13 +247,13 @@ int runRcc(int argc, char *argv[])
if (parser.isSet(rootOption)) {
library.setResourceRoot(QDir::cleanPath(parser.value(rootOption)));
if (library.resourceRoot().isEmpty() || library.resourceRoot().at(0) != u'/')
- errorMsg = QLatin1String("Root must start with a /");
+ errorMsg = "Root must start with a /"_L1;
}
if (parser.isSet(compressionAlgoOption))
library.setCompressionAlgorithm(RCCResourceLibrary::parseCompressionAlgorithm(parser.value(compressionAlgoOption), &errorMsg));
if (formatVersion < 3 && library.compressionAlgorithm() == RCCResourceLibrary::CompressionAlgorithm::Zstd)
- errorMsg = QLatin1String("Zstandard compression requires format version 3 or higher");
+ errorMsg = "Zstandard compression requires format version 3 or higher"_L1;
if (parser.isSet(nocompressOption))
library.setCompressionAlgorithm(RCCResourceLibrary::CompressionAlgorithm::None);
if (parser.isSet(noZstdOption))
@@ -266,25 +268,25 @@ int runRcc(int argc, char *argv[])
library.setFormat(RCCResourceLibrary::Binary);
if (parser.isSet(generatorOption)) {
auto value = parser.value(generatorOption);
- if (value == QLatin1String("cpp")) {
+ if (value == "cpp"_L1) {
library.setFormat(RCCResourceLibrary::C_Code);
- } else if (value == QLatin1String("python")) {
+ } else if (value == "python"_L1) {
library.setFormat(RCCResourceLibrary::Python_Code);
- } else if (value == QLatin1String("python2")) { // ### fixme Qt 7: remove
+ } else if (value == "python2"_L1) { // ### fixme Qt 7: remove
qWarning("Format python2 is no longer supported, defaulting to python.");
library.setFormat(RCCResourceLibrary::Python_Code);
} else {
- errorMsg = QLatin1String("Invalid generator: ") + value;
+ errorMsg = "Invalid generator: "_L1 + value;
}
}
if (parser.isSet(passOption)) {
- if (parser.value(passOption) == QLatin1String("1"))
+ if (parser.value(passOption) == "1"_L1)
library.setFormat(RCCResourceLibrary::Pass1);
- else if (parser.value(passOption) == QLatin1String("2"))
+ else if (parser.value(passOption) == "2"_L1)
library.setFormat(RCCResourceLibrary::Pass2);
else
- errorMsg = QLatin1String("Pass number must be 1 or 2");
+ errorMsg = "Pass number must be 1 or 2"_L1;
}
if (parser.isSet(namespaceOption))
library.setUseNameSpace(!library.useNameSpace());
@@ -297,7 +299,7 @@ int runRcc(int argc, char *argv[])
const QStringList filenamesIn = parser.positionalArguments();
for (const QString &file : filenamesIn) {
- if (file == QLatin1String("-"))
+ if (file == "-"_L1)
continue;
else if (!QFile::exists(file)) {
qWarning("%s: File does not exist '%s'", argv[0], qPrintable(file));
@@ -349,7 +351,7 @@ int runRcc(int argc, char *argv[])
}
- if (outFilename.isEmpty() || outFilename == QLatin1String("-")) {
+ if (outFilename.isEmpty() || outFilename == "-"_L1) {
#ifdef Q_OS_WIN
// Make sure fwrite to stdout doesn't do LF->CRLF
if (library.format() == RCCResourceLibrary::Binary)
@@ -397,7 +399,7 @@ int runRcc(int argc, char *argv[])
QFile depout;
depout.setFileName(depFilename);
- if (outFilename.isEmpty() || outFilename == QLatin1String("-")) {
+ if (outFilename.isEmpty() || outFilename == "-"_L1) {
const QString msg = QString::fromUtf8("Unable to write depfile when outputting to stdout!\n");
errorDevice.write(msg.toUtf8());
return 1;
diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp
index a01d5bc310..edd833ca31 100644
--- a/src/tools/rcc/rcc.cpp
+++ b/src/tools/rcc/rcc.cpp
@@ -50,6 +50,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
enum {
CONSTANT_USENAMESPACE = 1,
CONSTANT_COMPRESSLEVEL_DEFAULT = -1,
@@ -445,14 +447,14 @@ qint64 RCCFileInfo::writeDataName(RCCResourceLibrary &lib, qint64 offset)
///////////////////////////////////////////////////////////
RCCResourceLibrary::Strings::Strings() :
- TAG_RCC(QLatin1String("RCC")),
- TAG_RESOURCE(QLatin1String("qresource")),
- TAG_FILE(QLatin1String("file")),
- ATTRIBUTE_LANG(QLatin1String("lang")),
- ATTRIBUTE_PREFIX(QLatin1String("prefix")),
- ATTRIBUTE_ALIAS(QLatin1String("alias")),
- ATTRIBUTE_THRESHOLD(QLatin1String("threshold")),
- ATTRIBUTE_COMPRESS(QLatin1String("compress")),
+ TAG_RCC("RCC"_L1),
+ TAG_RESOURCE("qresource"_L1),
+ TAG_FILE("file"_L1),
+ ATTRIBUTE_LANG("lang"_L1),
+ ATTRIBUTE_PREFIX("prefix"_L1),
+ ATTRIBUTE_ALIAS("alias"_L1),
+ ATTRIBUTE_THRESHOLD("threshold"_L1),
+ ATTRIBUTE_COMPRESS("compress"_L1),
ATTRIBUTE_COMPRESSALGO(QStringLiteral("compression-algorithm"))
{
}
@@ -520,12 +522,12 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
case QXmlStreamReader::StartElement:
if (reader.name() == m_strings.TAG_RCC) {
if (!tokens.isEmpty())
- reader.raiseError(QLatin1String("expected <RCC> tag"));
+ reader.raiseError("expected <RCC> tag"_L1);
else
tokens.push(RccTag);
} else if (reader.name() == m_strings.TAG_RESOURCE) {
if (tokens.isEmpty() || tokens.top() != RccTag) {
- reader.raiseError(QLatin1String("unexpected <RESOURCE> tag"));
+ reader.raiseError("unexpected <RESOURCE> tag"_L1);
} else {
tokens.push(ResourceTag);
@@ -555,7 +557,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
}
} else if (reader.name() == m_strings.TAG_FILE) {
if (tokens.isEmpty() || tokens.top() != ResourceTag) {
- reader.raiseError(QLatin1String("unexpected <FILE> tag"));
+ reader.raiseError("unexpected <FILE> tag"_L1);
} else {
tokens.push(FileTag);
@@ -587,7 +589,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
reader.raiseError(errorString);
}
} else {
- reader.raiseError(QString(QLatin1String("unexpected tag: %1")).arg(reader.name().toString()));
+ reader.raiseError(QString("unexpected tag: %1"_L1).arg(reader.name().toString()));
}
break;
@@ -596,17 +598,17 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
if (!tokens.isEmpty() && tokens.top() == RccTag)
tokens.pop();
else
- reader.raiseError(QLatin1String("unexpected closing tag"));
+ reader.raiseError("unexpected closing tag"_L1);
} else if (reader.name() == m_strings.TAG_RESOURCE) {
if (!tokens.isEmpty() && tokens.top() == ResourceTag)
tokens.pop();
else
- reader.raiseError(QLatin1String("unexpected closing tag"));
+ reader.raiseError("unexpected closing tag"_L1);
} else if (reader.name() == m_strings.TAG_FILE) {
if (!tokens.isEmpty() && tokens.top() == FileTag)
tokens.pop();
else
- reader.raiseError(QLatin1String("unexpected closing tag"));
+ reader.raiseError("unexpected closing tag"_L1);
}
break;
@@ -614,7 +616,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
if (reader.isWhitespace())
break;
if (tokens.isEmpty() || tokens.top() != FileTag) {
- reader.raiseError(QLatin1String("unexpected text"));
+ reader.raiseError("unexpected text"_L1);
} else {
QString fileName = reader.text().toString();
if (fileName.isEmpty()) {
@@ -626,7 +628,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
alias = fileName;
alias = QDir::cleanPath(alias);
- while (alias.startsWith(QLatin1String("../")))
+ while (alias.startsWith("../"_L1))
alias.remove(0, 3);
alias = QDir::cleanPath(m_resourceRoot) + prefix + alias;
@@ -643,8 +645,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
QDirIterator it(dir, QDirIterator::FollowSymlinks|QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
- if (it.fileName() == QLatin1String(".")
- || it.fileName() == QLatin1String(".."))
+ if (it.fileName() == "."_L1 || it.fileName() == ".."_L1)
continue;
filePaths.append(it.filePath());
}
@@ -793,8 +794,8 @@ bool RCCResourceLibrary::readFiles(bool listMode, QIODevice &errorDevice)
QFile fileIn;
QString fname = m_fileNames.at(i);
QString pwd;
- if (fname == QLatin1String("-")) {
- fname = QLatin1String("(stdin)");
+ if (fname == "-"_L1) {
+ fname = "(stdin)"_L1;
pwd = QDir::currentPath();
fileIn.setFileName(fname);
if (!fileIn.open(stdin, QIODevice::ReadOnly)) {
@@ -868,21 +869,21 @@ RCCResourceLibrary::ResourceDataFileMap RCCResourceLibrary::resourceDataFileMap(
RCCResourceLibrary::CompressionAlgorithm RCCResourceLibrary::parseCompressionAlgorithm(QStringView value, QString *errorMsg)
{
- if (value == QLatin1String("best"))
+ if (value == "best"_L1)
return CompressionAlgorithm::Best;
- if (value == QLatin1String("zlib")) {
+ if (value == "zlib"_L1) {
#ifdef QT_NO_COMPRESS
- *errorMsg = QLatin1String("zlib support not compiled in");
+ *errorMsg = "zlib support not compiled in"_L1;
#else
return CompressionAlgorithm::Zlib;
#endif
- } else if (value == QLatin1String("zstd")) {
+ } else if (value == "zstd"_L1) {
#if QT_CONFIG(zstd)
return CompressionAlgorithm::Zstd;
#else
- *errorMsg = QLatin1String("Zstandard support not compiled in");
+ *errorMsg = "Zstandard support not compiled in"_L1;
#endif
- } else if (value != QLatin1String("none")) {
+ } else if (value != "none"_L1) {
*errorMsg = QString::fromLatin1("Unknown compression algorithm '%1'").arg(value);
}