unordered_map for locale, and const functions where possible

This commit is contained in:
Twan van Laarhoven
2020-09-27 21:53:42 +02:00
parent 7725156225
commit 5b0979f58e
4 changed files with 29 additions and 12 deletions
+4 -4
View File
@@ -77,16 +77,16 @@ String identity(const String& key) {
return key;
}
String SubLocale::tr(const String& key, DefaultLocaleFun def) {
map<String,String>::const_iterator it = translations.find(canonical_name_form(key));
String SubLocale::tr(const String& key, DefaultLocaleFun def) const {
auto it = translations.find(canonical_name_form(key));
if (it == translations.end()) {
return def(key);
} else {
return it->second;
}
}
String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) {
map<String,String>::const_iterator it = translations.find(subcat + _("_") + canonical_name_form(key));
String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) const {
auto it = translations.find(subcat + _("_") + canonical_name_form(key));
if (it == translations.end()) {
return def(key);
} else {
+4 -4
View File
@@ -19,14 +19,14 @@ DECLARE_POINTER_TYPE(SubLocaleValidator);
// ----------------------------------------------------------------------------- : Locale class
/// Translations of the texts of a game/stylesheet/symbolfont
/// Translations of the texts of a locale category or game/stylesheet/symbolfont
class SubLocale : public IntrusivePtrBase<SubLocale> {
public:
map<String,String> translations;
unordered_map<String,String> translations;
/// Translate a key, if not found, apply the default function to the key
String tr(const String& key, DefaultLocaleFun def);
String tr(const String& subcat, const String& key, DefaultLocaleFun def);
String tr(const String& key, DefaultLocaleFun def) const;
String tr(const String& subcat, const String& key, DefaultLocaleFun def) const;
DECLARE_REFLECTION();
};