Merge branch 'task/i10n_fixups' into 'master'

coverity fixes and other bits

See merge request OpenMW/openmw!1766
pull/3226/head
psi29a 3 years ago
commit fd6899e91d

@ -22,19 +22,19 @@ namespace l10n
for (const icu::Locale &loc: preferredLocales) for (const icu::Locale &loc: preferredLocales)
{ {
mPreferredLocales.push_back(loc); 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 // Try without variant or country if they are specified, starting with the most specific
if (strcmp(loc.getVariant(), "") != 0) if (strcmp(loc.getVariant(), "") != 0)
{ {
icu::Locale withoutVariant(loc.getLanguage(), loc.getCountry()); icu::Locale withoutVariant(loc.getLanguage(), loc.getCountry());
mPreferredLocales.push_back(withoutVariant); mPreferredLocales.push_back(withoutVariant);
mPreferredLocaleStrings.push_back(withoutVariant.getName()); mPreferredLocaleStrings.emplace_back(withoutVariant.getName());
} }
if (strcmp(loc.getCountry(), "") != 0) if (strcmp(loc.getCountry(), "") != 0)
{ {
icu::Locale withoutCountry(loc.getLanguage()); icu::Locale withoutCountry(loc.getLanguage());
mPreferredLocales.push_back(withoutCountry); mPreferredLocales.push_back(withoutCountry);
mPreferredLocaleStrings.push_back(withoutCountry.getName()); mPreferredLocaleStrings.emplace_back(withoutCountry.getName());
} }
} }
} }
@ -53,7 +53,7 @@ namespace l10n
if (status.isFailure()) if (status.isFailure())
{ {
std::string errorText = getErrorText(parseError); std::string errorText = getErrorText(parseError);
if (errorText.size()) if (!errorText.empty())
{ {
Log(Debug::Error) << message << ": " << status.errorName() << " in \"" << errorText << "\""; Log(Debug::Error) << message << ": " << status.errorName() << " in \"" << errorText << "\"";
} }
@ -73,8 +73,8 @@ namespace l10n
std::string localeName = lang.getName(); std::string localeName = lang.getName();
for (const auto& it: data) for (const auto& it: data)
{ {
std::string key = it.first.as<std::string>(); const auto key = it.first.as<std::string>();
std::string value = it.second.as<std::string>(); const auto value = it.second.as<std::string>();
icu::UnicodeString pattern = icu::UnicodeString::fromUTF8(value); icu::UnicodeString pattern = icu::UnicodeString::fromUTF8(value);
icu::ErrorCode status; icu::ErrorCode status;
UParseError parseError; UParseError parseError;
@ -110,10 +110,10 @@ namespace l10n
{ {
std::vector<icu::UnicodeString> argNames; std::vector<icu::UnicodeString> argNames;
std::vector<icu::Formattable> argValues; std::vector<icu::Formattable> argValues;
for (auto& [key, value] : args) for (auto& [k, v] : args)
{ {
argNames.push_back(icu::UnicodeString::fromUTF8(key)); argNames.push_back(icu::UnicodeString::fromUTF8(k));
argValues.push_back(value); argValues.push_back(v);
} }
return formatMessage(key, argNames, argValues); return formatMessage(key, argNames, argValues);
} }
@ -137,7 +137,7 @@ namespace l10n
if (message) if (message)
{ {
if (args.size() > 0 && argNames.size() > 0) if (!args.empty() && !argNames.empty())
message->format(&argNames[0], &args[0], args.size(), result, success); message->format(&argNames[0], &args[0], args.size(), result, success);
else else
message->format(nullptr, nullptr, args.size(), result, success); message->format(nullptr, nullptr, args.size(), result, success);
@ -145,8 +145,8 @@ namespace l10n
result.toUTF8String(resultString); result.toUTF8String(resultString);
return resultString; return resultString;
} }
icu::Locale defaultLocale(NULL); icu::Locale defaultLocale(nullptr);
if (mPreferredLocales.size() > 0) if (!mPreferredLocales.empty())
{ {
defaultLocale = mPreferredLocales[0]; defaultLocale = mPreferredLocales[0];
} }
@ -156,7 +156,7 @@ namespace l10n
// If we can't parse the key as a pattern, just return the key // If we can't parse the key as a pattern, just return the key
return std::string(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); defaultMessage.format(&argNames[0], &args[0], args.size(), result, success);
else else
defaultMessage.format(nullptr, nullptr, args.size(), result, success); defaultMessage.format(nullptr, nullptr, args.size(), result, success);

@ -38,7 +38,7 @@ namespace l10n
void setPreferredLocales(const std::vector<icu::Locale> &preferredLocales); void setPreferredLocales(const std::vector<icu::Locale> &preferredLocales);
const std::vector<icu::Locale> & getPreferredLocales() const { return mPreferredLocales; } const std::vector<icu::Locale> & getPreferredLocales() const { return mPreferredLocales; }
void load(std::istream &input, const icu::Locale &lang, const std::string &path); 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; } const icu::Locale & getFallbackLocale() const { return mFallbackLocale; }
private: private:

Loading…
Cancel
Save