Use QStringLiteral more judiciously

Replace it with QL1S in QStringBuilder expressions
and in overloaded functions.

Replace patterns 'QString::number() + QStringLiteral'
and 'QStringLiteral + QString::number()' with
QString::asprintf.

Saves some text size.

Change-Id: Ib39b2332264dfc3df04e77f2c101b47a1030cef4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Anton Kudryavtsev 2016-07-06 11:32:54 +03:00
parent 145d8462e3
commit 2788fccd29
26 changed files with 58 additions and 59 deletions

View File

@ -1123,7 +1123,7 @@ void QMessagePattern::setPattern(const QString &pattern)
if (m.hasMatch()) {
int depth = m.capturedRef(1).toInt();
if (depth <= 0)
error += QStringLiteral("QT_MESSAGE_PATTERN: %{backtrace} depth must be a number greater than 0\n");
error += QLatin1String("QT_MESSAGE_PATTERN: %{backtrace} depth must be a number greater than 0\n");
else
backtraceDepth = depth;
}
@ -1135,7 +1135,7 @@ void QMessagePattern::setPattern(const QString &pattern)
backtraceParams.backtraceSeparator = backtraceSeparator;
backtraceArgs.append(backtraceParams);
#else
error += QStringLiteral("QT_MESSAGE_PATTERN: %{backtrace} is not supported by this Qt build\n");
error += QLatin1String("QT_MESSAGE_PATTERN: %{backtrace} is not supported by this Qt build\n");
#endif
}
@ -1156,7 +1156,7 @@ void QMessagePattern::setPattern(const QString &pattern)
else if (lexeme == QLatin1String(endifTokenC)) {
tokens[i] = endifTokenC;
if (!inIf && !nestedIfError)
error += QStringLiteral("QT_MESSAGE_PATTERN: %{endif} without an %{if-*}\n");
error += QLatin1String("QT_MESSAGE_PATTERN: %{endif} without an %{if-*}\n");
inIf = false;
} else {
tokens[i] = emptyTokenC;
@ -1172,9 +1172,9 @@ void QMessagePattern::setPattern(const QString &pattern)
}
}
if (nestedIfError)
error += QStringLiteral("QT_MESSAGE_PATTERN: %{if-*} cannot be nested\n");
error += QLatin1String("QT_MESSAGE_PATTERN: %{if-*} cannot be nested\n");
else if (inIf)
error += QStringLiteral("QT_MESSAGE_PATTERN: missing %{endif}\n");
error += QLatin1String("QT_MESSAGE_PATTERN: missing %{endif}\n");
if (!error.isEmpty()) {
#if defined(Q_OS_WINCE) || defined(Q_OS_WINRT)
OutputDebugString(reinterpret_cast<const wchar_t*>(error.utf16()));

View File

@ -387,7 +387,7 @@ QStringList QFileSelectorPrivate::platformSelectors()
# endif
QString productName = QSysInfo::productType();
# ifdef Q_OS_MACOS
if (productName != QStringLiteral("osx"))
if (productName != QLatin1String("osx"))
ret << QStringLiteral("osx"); // compatibility
# endif
if (productName != QLatin1String("unknown"))

View File

@ -819,7 +819,7 @@ static const ushort * const fragmentInUrl = userNameInUrl + 6;
static inline void parseDecodedComponent(QString &data)
{
data.replace(QLatin1Char('%'), QStringLiteral("%25"));
data.replace(QLatin1Char('%'), QLatin1String("%25"));
}
static inline QString
@ -1477,7 +1477,7 @@ QString QUrlPrivate::toLocalFile(QUrl::FormattingOptions options) const
// magic for shared drive on windows
if (!host.isEmpty()) {
tmp = QStringLiteral("//") + host;
tmp = QLatin1String("//") + host;
#ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only.
if (scheme == webDavScheme())
tmp += webDavSslTag();

View File

@ -2269,7 +2269,7 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString
}
// prepend ACE prefix
output->insert(outLen, QStringLiteral("xn--"));
output->insert(outLen, QLatin1String("xn--"));
return;
}

View File

@ -3581,7 +3581,7 @@ QString QDateTime::toString(Qt::DateFormat format) const
.arg(tm.toString(Qt::TextDate))
.arg(dt.year());
if (timeSpec() != Qt::LocalTime) {
buf += QStringLiteral(" GMT");
buf += QLatin1String(" GMT");
if (d->m_spec == Qt::OffsetFromUTC)
buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc);
}

View File

@ -86,7 +86,7 @@ QStringList QPlatformIntegrationFactory::keys(const QString &platformPluginPath)
QCoreApplication::addLibraryPath(platformPluginPath);
list = directLoader()->keyMap().values();
if (!list.isEmpty()) {
const QString postFix = QStringLiteral(" (from ")
const QString postFix = QLatin1String(" (from ")
+ QDir::toNativeSeparators(platformPluginPath)
+ QLatin1Char(')');
const QStringList::iterator end = list.end();

View File

@ -88,7 +88,7 @@ QStringList QPlatformThemeFactory::keys(const QString &platformPluginPath)
QCoreApplication::addLibraryPath(platformPluginPath);
list += directLoader()->keyMap().values();
if (!list.isEmpty()) {
const QString postFix = QStringLiteral(" (from ")
const QString postFix = QLatin1String(" (from ")
+ QDir::toNativeSeparators(platformPluginPath)
+ QLatin1Char(')');
const QStringList::iterator end = list.end();

View File

@ -111,7 +111,7 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con
doc->addResource(QTextDocument::ImageResource, url, pm);
}
if (name.contains(QStringLiteral("@2x")))
if (name.contains(QLatin1String("@2x")))
pm.setDevicePixelRatio(sourcePixelRatio);
return pm;

View File

@ -468,7 +468,7 @@ long QSslSocketPrivate::sslLibraryVersionNumber()
QString QSslSocketPrivate::sslLibraryVersionString()
{
return QStringLiteral("Secure Transport, ") + QSysInfo::prettyProductName();
return QLatin1String("Secure Transport, ") + QSysInfo::prettyProductName();
}
long QSslSocketPrivate::sslLibraryBuildVersionNumber()

View File

@ -66,7 +66,7 @@ Q_LOGGING_CATEGORY(qLcTray, "qt.qpa.tray")
static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2");
static const QString KDEWatcherService = QStringLiteral("org.kde.StatusNotifierWatcher");
static const QString TempFileTemplate = QDir::tempPath() + QStringLiteral("/qt-trayicon-XXXXXX.png");
static const QString TempFileTemplate = QDir::tempPath() + QLatin1String("/qt-trayicon-XXXXXX.png");
static const QString XdgNotificationService = QStringLiteral("org.freedesktop.Notifications");
static const QString XdgNotificationPath = QStringLiteral("/org/freedesktop/Notifications");
static const QString DefaultAction = QStringLiteral("default");
@ -156,7 +156,7 @@ QTemporaryFile *QDBusTrayIcon::tempIcon(const QIcon &icon)
QDBusConnection session = QDBusConnection::sessionBus();
uint pid = session.interface()->servicePid(KDEWatcherService).value();
QString processName = QLockFilePrivate::processNameByPid(pid);
necessary = processName.endsWith(QStringLiteral("indicator-application-service"));
necessary = processName.endsWith(QLatin1String("indicator-application-service"));
necessity_checked = true;
}
if (!necessary)

View File

@ -64,7 +64,7 @@ QTsLibMouseHandler::QTsLibMouseHandler(const QString &key,
QByteArray device = qgetenv("TSLIB_TSDEVICE");
if (specification.startsWith(QStringLiteral("/dev/")))
if (specification.startsWith(QLatin1String("/dev/")))
device = specification.toLocal8Bit();
if (device.isEmpty())

View File

@ -101,7 +101,7 @@ static inline bool detectWebBrowser(const QByteArray &desktop,
if (desktop == QByteArray("KDE")) {
// Konqueror launcher
if (checkExecutable(QStringLiteral("kfmclient"), browser)) {
browser->append(QStringLiteral(" exec"));
browser->append(QLatin1String(" exec"));
return true;
}
} else if (desktop == QByteArray("GNOME")) {
@ -121,7 +121,7 @@ static inline bool launch(const QString &launcher, const QUrl &url)
if (debug)
qDebug("Launching %s", qPrintable(command));
#if defined(QT_NO_PROCESS)
const bool ok = ::system(qPrintable(command + QStringLiteral(" &")));
const bool ok = ::system(qPrintable(command + QLatin1String(" &")));
#else
const bool ok = QProcess::startDetached(command);
#endif

View File

@ -170,7 +170,7 @@ QStringList QGenericUnixTheme::xdgIconThemePaths()
{
QStringList paths;
// Add home directory first in search path
const QFileInfo homeIconDir(QDir::homePath() + QStringLiteral("/.icons"));
const QFileInfo homeIconDir(QDir::homePath() + QLatin1String("/.icons"));
if (homeIconDir.isDir())
paths.prepend(homeIconDir.absoluteFilePath());
@ -247,8 +247,8 @@ public:
static QString kdeGlobals(const QString &kdeDir, int kdeVersion)
{
if (kdeVersion > 4)
return kdeDir + QStringLiteral("/kdeglobals");
return kdeDir + QStringLiteral("/share/config/kdeglobals");
return kdeDir + QLatin1String("/kdeglobals");
return kdeDir + QLatin1String("/share/config/kdeglobals");
}
void refresh();
@ -559,22 +559,22 @@ QPlatformTheme *QKdeTheme::createKdeTheme()
if (!kdeDirsVar.isEmpty())
kdeDirs += kdeDirsVar.split(QLatin1Char(':'), QString::SkipEmptyParts);
const QString kdeVersionHomePath = QDir::homePath() + QStringLiteral("/.kde") + QLatin1String(kdeVersionBA);
const QString kdeVersionHomePath = QDir::homePath() + QLatin1String("/.kde") + QLatin1String(kdeVersionBA);
if (QFileInfo(kdeVersionHomePath).isDir())
kdeDirs += kdeVersionHomePath;
const QString kdeHomePath = QDir::homePath() + QStringLiteral("/.kde");
const QString kdeHomePath = QDir::homePath() + QLatin1String("/.kde");
if (QFileInfo(kdeHomePath).isDir())
kdeDirs += kdeHomePath;
const QString kdeRcPath = QStringLiteral("/etc/kde") + QLatin1String(kdeVersionBA) + QStringLiteral("rc");
const QString kdeRcPath = QLatin1String("/etc/kde") + QLatin1String(kdeVersionBA) + QLatin1String("rc");
if (QFileInfo(kdeRcPath).isReadable()) {
QSettings kdeSettings(kdeRcPath, QSettings::IniFormat);
kdeSettings.beginGroup(QStringLiteral("Directories-default"));
kdeDirs += kdeSettings.value(QStringLiteral("prefixes")).toStringList();
}
const QString kdeVersionPrefix = QStringLiteral("/etc/kde") + QLatin1String(kdeVersionBA);
const QString kdeVersionPrefix = QLatin1String("/etc/kde") + QLatin1String(kdeVersionBA);
if (QFileInfo(kdeVersionPrefix).isDir())
kdeDirs += kdeVersionPrefix;

View File

@ -278,7 +278,7 @@ QString TableGenerator::findComposeFile()
// check if users home directory has a file named .XCompose
if (cleanState()) {
QString path = qgetenv("HOME") + QStringLiteral("/.XCompose");
QString path = qgetenv("HOME") + QLatin1String("/.XCompose");
if (QFile::exists(path))
return path;
}

View File

@ -79,7 +79,7 @@ QStringList QEGLDeviceIntegrationFactory::keys(const QString &pluginPath)
QCoreApplication::addLibraryPath(pluginPath);
list = directLoader()->keyMap().values();
if (!list.isEmpty()) {
const QString postFix = QStringLiteral(" (from ")
const QString postFix = QLatin1String(" (from ")
+ QDir::toNativeSeparators(pluginPath)
+ QLatin1Char(')');
const QStringList::iterator end = list.end();

View File

@ -509,28 +509,29 @@ QString QWindowsContext::registerWindowClass(const QWindow *w)
break;
}
// Create a unique name for the flag combination
QString cname = QStringLiteral("Qt5QWindow");
QString cname;
cname += QLatin1String("Qt5QWindow");
switch (type) {
case Qt::Tool:
cname += QStringLiteral("Tool");
cname += QLatin1String("Tool");
break;
case Qt::ToolTip:
cname += QStringLiteral("ToolTip");
cname += QLatin1String("ToolTip");
break;
case Qt::Popup:
cname += QStringLiteral("Popup");
cname += QLatin1String("Popup");
break;
default:
break;
}
if (style & CS_DROPSHADOW)
cname += QStringLiteral("DropShadow");
cname += QLatin1String("DropShadow");
if (style & CS_SAVEBITS)
cname += QStringLiteral("SaveBits");
cname += QLatin1String("SaveBits");
if (style & CS_OWNDC)
cname += QStringLiteral("OwnDC");
cname += QLatin1String("OwnDC");
if (icon)
cname += QStringLiteral("Icon");
cname += QLatin1String("Icon");
return registerWindowClass(cname, qWindowsWndProc, style, GetSysColorBrush(COLOR_WINDOW), icon);
}
@ -828,8 +829,8 @@ static inline QString errorMessageFromComError(const _com_error &comError)
return result;
}
if (const WORD wCode = comError.WCode())
return QStringLiteral("IDispatch error #") + QString::number(wCode);
return QStringLiteral("Unknown error 0x0") + QString::number(comError.Error(), 16);
return QString::asprintf("IDispatch error #%u", uint(wCode));
return QString::asprintf("Unknown error 0x0%x", uint(comError.Error()));
}
#endif // !Q_OS_WINCE

View File

@ -698,7 +698,7 @@ QVariant QWindowsMimeText::convertToMime(const QString &mime, LPDATAOBJECT pData
QByteArray data = getData(CF_UNICODETEXT, pDataObj);
if (!data.isEmpty()) {
str = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()));
str.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
str.replace(QLatin1String("\r\n"), QLatin1String("\n"));
} else {
data = getData(CF_TEXT, pDataObj);
if (!data.isEmpty()) {

View File

@ -94,9 +94,8 @@ static inline QString mailCommand()
keyName = QString::fromWCharArray(command);
RegCloseKey(handle);
}
if (keyName.isEmpty())
keyName = QStringLiteral("mailto");
keyName += QStringLiteral("\\Shell\\Open\\Command");
const QLatin1String mailto = keyName.isEmpty() ? QLatin1String("mailto") : QLatin1String();
keyName += mailto + QLatin1String("\\Shell\\Open\\Command");
if (debug)
qDebug() << __FUNCTION__ << "keyName=" << keyName;
command[0] = 0;
@ -134,7 +133,7 @@ static inline bool launchMail(const QUrl &url)
}
// Pass the url as the parameter. Should use QProcess::startDetached(),
// but that cannot handle a Windows command line [yet].
command.replace(QStringLiteral("%1"), url.toString(QUrl::FullyEncoded));
command.replace(QLatin1String("%1"), url.toString(QUrl::FullyEncoded));
if (debug)
qDebug() << __FUNCTION__ << "Launching" << command;
//start the process

View File

@ -246,11 +246,11 @@ QString QWindowsTabletSupport::description() const
.arg(implementationVersion >> 8).arg(implementationVersion & 0xFF)
.arg(opts, 0, 16);
if (opts & CXO_MESSAGES)
result += QStringLiteral(" CXO_MESSAGES");
result += QLatin1String(" CXO_MESSAGES");
if (opts & CXO_CSRMESSAGES)
result += QStringLiteral(" CXO_CSRMESSAGES");
result += QLatin1String(" CXO_CSRMESSAGES");
if (m_tiltSupport)
result += QStringLiteral(" tilt");
result += QLatin1String(" tilt");
return result;
}

View File

@ -346,7 +346,7 @@ QWindowsTheme::~QWindowsTheme()
static inline QStringList iconThemeSearchPaths()
{
const QFileInfo appDir(QCoreApplication::applicationDirPath() + QStringLiteral("/icons"));
const QFileInfo appDir(QCoreApplication::applicationDirPath() + QLatin1String("/icons"));
return appDir.isDir() ? QStringList(appDir.absoluteFilePath()) : QStringList();
}

View File

@ -102,7 +102,7 @@ QMimeData *QWinRTClipboard::mimeData(QClipboard::Mode mode)
quint32 size;
const wchar_t *textStr = result.GetRawBuffer(&size);
QString text = QString::fromWCharArray(textStr, size);
text.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
text.replace(QLatin1String("\r\n"), QLatin1String("\n"));
m_mimeData.setText(text);
return &m_mimeData;

View File

@ -144,7 +144,7 @@ template<> inline char *toString(const QRectF &s)
template<> inline char *toString(const QUrl &uri)
{
if (!uri.isValid())
return qstrdup(qPrintable(QStringLiteral("Invalid URL: ") + uri.errorString()));
return qstrdup(qPrintable(QLatin1String("Invalid URL: ") + uri.errorString()));
return qstrdup(uri.toEncoded().constData());
}

View File

@ -926,7 +926,7 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
QBenchmarkTestMethodData::current = &benchmarkData;
const QByteArray &name = m_methods[index].name();
QBenchmarkGlobalData::current->context.slotName = QLatin1String(name) + QStringLiteral("()");
QBenchmarkGlobalData::current->context.slotName = QLatin1String(name) + QLatin1String("()");
char member[512];
QTestTable table;

View File

@ -824,12 +824,12 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end
AttributeFormatter attrs;
QString family = charFormatFont.family();
if (!family.isEmpty()) {
family = family.replace('\\',QStringLiteral("\\\\"));
family = family.replace(':',QStringLiteral("\\:"));
family = family.replace(',',QStringLiteral("\\,"));
family = family.replace('=',QStringLiteral("\\="));
family = family.replace(';',QStringLiteral("\\;"));
family = family.replace('\"',QStringLiteral("\\\""));
family = family.replace('\\', QLatin1String("\\\\"));
family = family.replace(':', QLatin1String("\\:"));
family = family.replace(',', QLatin1String("\\,"));
family = family.replace('=', QLatin1String("\\="));
family = family.replace(';', QLatin1String("\\;"));
family = family.replace('\"', QLatin1String("\\\""));
attrs["font-family"] = QString::fromLatin1("\"%1\"").arg(family);
}

View File

@ -307,7 +307,7 @@ private:
if (develMode) {
// Write a PID file to help runner
const QString pidFileName = QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation))
.absoluteFilePath(QString::number(uint(GetCurrentProcessId())) + QStringLiteral(".pid"));
.absoluteFilePath(QString::asprintf("%u.pid", uint(GetCurrentProcessId())));
CREATEFILE2_EXTENDED_PARAMETERS params = {
sizeof(CREATEFILE2_EXTENDED_PARAMETERS),
FILE_ATTRIBUTE_NORMAL

View File

@ -1295,8 +1295,7 @@ static QString extractEncodingDecl(const QString &text, bool *needMoreText)
*needMoreText = false;
int l = text.length();
const QString declStart = QStringLiteral("<?xml");
const QStringRef snip = declStart.leftRef(l);
const QLatin1String snip("<?xml", std::min(l, 5));
if (l > 0 && !text.startsWith(snip))
return QString();