Commit c1187db5 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Use in-place modification API of KLocalizedString

Avoids deep copies

GIT_SILENT
parent 209b928c
Pipeline #115282 failed with stage
in 22 seconds
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(KF5_MIN_VERSION "5.89.0")
set(KF5_MIN_VERSION "5.91.0")
set(PIM_VERSION "5.19.40")
project(GrantleeTheme VERSION ${PIM_VERSION})
......
......@@ -22,35 +22,34 @@ GrantleeKi18nLocalizer::GrantleeKi18nLocalizer()
GrantleeKi18nLocalizer::~GrantleeKi18nLocalizer() = default;
QString GrantleeKi18nLocalizer::processArguments(const KLocalizedString &kstr, const QVariantList &arguments) const
QString GrantleeKi18nLocalizer::processArguments(KLocalizedString &str, const QVariantList &arguments) const
{
KLocalizedString str = kstr;
for (auto iter = arguments.cbegin(), end = arguments.cend(); iter != end; ++iter) {
switch (iter->type()) {
case QVariant::String:
str = str.subs(iter->toString());
str.setSubs(iter->toString());
break;
case QVariant::Int:
str = str.subs(iter->toInt());
str.setSubs(iter->toInt());
break;
case QVariant::UInt:
str = str.subs(iter->toUInt());
str.setSubs(iter->toUInt());
break;
case QVariant::LongLong:
str = str.subs(iter->toLongLong());
str.setSubs(iter->toLongLong());
break;
case QVariant::ULongLong:
str = str.subs(iter->toULongLong());
str.setSubs(iter->toULongLong());
break;
case QVariant::Char:
str = str.subs(iter->toChar());
str.setSubs(iter->toChar());
break;
case QVariant::Double:
str = str.subs(iter->toDouble());
str.setSubs(iter->toDouble());
break;
case QVariant::UserType:
if (iter->canConvert<Grantlee::SafeString>()) {
str = str.subs(iter->value<Grantlee::SafeString>().get());
str.setSubs(iter->value<Grantlee::SafeString>().get());
break;
}
// fall-through
......@@ -69,13 +68,13 @@ QString GrantleeKi18nLocalizer::processArguments(const KLocalizedString &kstr, c
QString GrantleeKi18nLocalizer::localizeContextString(const QString &string, const QString &context, const QVariantList &arguments) const
{
const KLocalizedString str = ki18nc(qPrintable(context), qPrintable(string));
KLocalizedString str = ki18nc(qPrintable(context), qPrintable(string));
return processArguments(str, arguments);
}
QString GrantleeKi18nLocalizer::localizeString(const QString &string, const QVariantList &arguments) const
{
const KLocalizedString str = ki18n(qPrintable(string));
KLocalizedString str = ki18n(qPrintable(string));
return processArguments(str, arguments);
}
......@@ -84,13 +83,13 @@ QString GrantleeKi18nLocalizer::localizePluralContextString(const QString &strin
const QString &context,
const QVariantList &arguments) const
{
const KLocalizedString str = ki18ncp(qPrintable(context), qPrintable(string), qPrintable(pluralForm));
KLocalizedString str = ki18ncp(qPrintable(context), qPrintable(string), qPrintable(pluralForm));
return processArguments(str, arguments);
}
QString GrantleeKi18nLocalizer::localizePluralString(const QString &string, const QString &pluralForm, const QVariantList &arguments) const
{
const KLocalizedString str = ki18np(qPrintable(string), qPrintable(pluralForm));
KLocalizedString str = ki18np(qPrintable(string), qPrintable(pluralForm));
return processArguments(str, arguments);
}
......
......@@ -44,7 +44,7 @@ public:
void setApplicationDomain(const QByteArray &domain);
private:
QString processArguments(const KLocalizedString &str, const QVariantList &arguments) const;
QString processArguments(KLocalizedString &str, const QVariantList &arguments) const;
QByteArray mApplicationDomain;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment