From db3f9da08a5b2bc0d9aff0e10809d135261b8238 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Mon, 11 Apr 2022 14:37:22 +0200 Subject: [PATCH 1/2] coverity fixes and other bits --- components/l10n/messagebundles.cpp | 26 +++++++++++++------------- components/l10n/messagebundles.hpp | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/components/l10n/messagebundles.cpp b/components/l10n/messagebundles.cpp index 9560e60d3b..18036a6136 100644 --- a/components/l10n/messagebundles.cpp +++ b/components/l10n/messagebundles.cpp @@ -22,19 +22,19 @@ namespace l10n for (const icu::Locale &loc: preferredLocales) { mPreferredLocales.push_back(loc); - mPreferredLocaleStrings.push_back(loc.getName()); + mPreferredLocaleStrings.emplace_back(loc.getName()); // Try without variant or country if they are specified, starting with the most specific if (strcmp(loc.getVariant(), "") != 0) { icu::Locale withoutVariant(loc.getLanguage(), loc.getCountry()); mPreferredLocales.push_back(withoutVariant); - mPreferredLocaleStrings.push_back(withoutVariant.getName()); + mPreferredLocaleStrings.emplace_back(withoutVariant.getName()); } if (strcmp(loc.getCountry(), "") != 0) { icu::Locale withoutCountry(loc.getLanguage()); mPreferredLocales.push_back(withoutCountry); - mPreferredLocaleStrings.push_back(withoutCountry.getName()); + mPreferredLocaleStrings.emplace_back(withoutCountry.getName()); } } } @@ -53,7 +53,7 @@ namespace l10n if (status.isFailure()) { std::string errorText = getErrorText(parseError); - if (errorText.size()) + if (!errorText.empty()) { Log(Debug::Error) << message << ": " << status.errorName() << " in \"" << errorText << "\""; } @@ -73,8 +73,8 @@ namespace l10n std::string localeName = lang.getName(); for (const auto& it: data) { - std::string key = it.first.as(); - std::string value = it.second.as(); + auto key = it.first.as(); + auto value = it.second.as(); icu::UnicodeString pattern = icu::UnicodeString::fromUTF8(value); icu::ErrorCode status; UParseError parseError; @@ -110,10 +110,10 @@ namespace l10n { std::vector argNames; std::vector argValues; - for (auto& [key, value] : args) + for (auto& [k, v] : args) { - argNames.push_back(icu::UnicodeString::fromUTF8(key)); - argValues.push_back(value); + argNames.push_back(icu::UnicodeString::fromUTF8(k)); + argValues.push_back(v); } return formatMessage(key, argNames, argValues); } @@ -137,7 +137,7 @@ namespace l10n if (message) { - if (args.size() > 0 && argNames.size() > 0) + if (!args.empty() && !argNames.empty()) message->format(&argNames[0], &args[0], args.size(), result, success); else message->format(nullptr, nullptr, args.size(), result, success); @@ -145,8 +145,8 @@ namespace l10n result.toUTF8String(resultString); return resultString; } - icu::Locale defaultLocale(NULL); - if (mPreferredLocales.size() > 0) + icu::Locale defaultLocale(nullptr); + if (!mPreferredLocales.empty()) { defaultLocale = mPreferredLocales[0]; } @@ -156,7 +156,7 @@ namespace l10n // If we can't parse the key as a pattern, just return the key return std::string(key); - if (args.size() > 0 && argNames.size() > 0) + if (!args.empty() && !argNames.empty()) defaultMessage.format(&argNames[0], &args[0], args.size(), result, success); else defaultMessage.format(nullptr, nullptr, args.size(), result, success); diff --git a/components/l10n/messagebundles.hpp b/components/l10n/messagebundles.hpp index 02333fad2c..1a4636c95a 100644 --- a/components/l10n/messagebundles.hpp +++ b/components/l10n/messagebundles.hpp @@ -38,7 +38,7 @@ namespace l10n void setPreferredLocales(const std::vector &preferredLocales); const std::vector & getPreferredLocales() const { return mPreferredLocales; } void load(std::istream &input, const icu::Locale &lang, const std::string &path); - bool isLoaded(icu::Locale loc) const { return mBundles.find(loc.getName()) != mBundles.end(); } + bool isLoaded(const icu::Locale& loc) const { return mBundles.find(loc.getName()) != mBundles.end(); } const icu::Locale & getFallbackLocale() const { return mFallbackLocale; } private: From 7fe6c39aa21b5fb24295261d511cae3b7aa6d843 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Mon, 11 Apr 2022 16:59:46 +0200 Subject: [PATCH 2/2] const the key/value --- components/l10n/messagebundles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/l10n/messagebundles.cpp b/components/l10n/messagebundles.cpp index 18036a6136..d02735313e 100644 --- a/components/l10n/messagebundles.cpp +++ b/components/l10n/messagebundles.cpp @@ -73,8 +73,8 @@ namespace l10n std::string localeName = lang.getName(); for (const auto& it: data) { - auto key = it.first.as(); - auto value = it.second.as(); + const auto key = it.first.as(); + const auto value = it.second.as(); icu::UnicodeString pattern = icu::UnicodeString::fromUTF8(value); icu::ErrorCode status; UParseError parseError;