diff options
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/optimized_translation.cpp | 18 | ||||
-rw-r--r-- | core/string/translation.cpp | 101 | ||||
-rw-r--r-- | core/string/ustring.cpp | 23 |
3 files changed, 71 insertions, 71 deletions
diff --git a/core/string/optimized_translation.cpp b/core/string/optimized_translation.cpp index 07302cc8c3..b130c2fc79 100644 --- a/core/string/optimized_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -179,14 +179,14 @@ void OptimizedTranslation::generate(const Ref<Translation> &p_from) { } bool OptimizedTranslation::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name.operator String(); - if (name == "hash_table") { + String prop_name = p_name.operator String(); + if (prop_name == "hash_table") { hash_table = p_value; - } else if (name == "bucket_table") { + } else if (prop_name == "bucket_table") { bucket_table = p_value; - } else if (name == "strings") { + } else if (prop_name == "strings") { strings = p_value; - } else if (name == "load_from") { + } else if (prop_name == "load_from") { generate(p_value); } else { return false; @@ -196,12 +196,12 @@ bool OptimizedTranslation::_set(const StringName &p_name, const Variant &p_value } bool OptimizedTranslation::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name.operator String(); - if (name == "hash_table") { + String prop_name = p_name.operator String(); + if (prop_name == "hash_table") { r_ret = hash_table; - } else if (name == "bucket_table") { + } else if (prop_name == "bucket_table") { r_ret = bucket_table; - } else if (name == "strings") { + } else if (prop_name == "strings") { r_ret = strings; } else { return false; diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 4748f1a0cb..9ee7f2b17b 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -297,27 +297,27 @@ String TranslationServer::standardize_locale(const String &p_locale) const { String univ_locale = p_locale.replace("-", "_"); // Extract locale elements. - String lang, script, country, variant; + String lang_name, script_name, country_name, variant_name; Vector<String> locale_elements = univ_locale.get_slice("@", 0).split("_"); - lang = locale_elements[0]; + lang_name = locale_elements[0]; if (locale_elements.size() >= 2) { if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) { - script = locale_elements[1]; + script_name = locale_elements[1]; } if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) { - country = locale_elements[1]; + country_name = locale_elements[1]; } } if (locale_elements.size() >= 3) { if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) { - country = locale_elements[2]; - } else if (variant_map.has(locale_elements[2].to_lower()) && variant_map[locale_elements[2].to_lower()] == lang) { - variant = locale_elements[2].to_lower(); + country_name = locale_elements[2]; + } else if (variant_map.has(locale_elements[2].to_lower()) && variant_map[locale_elements[2].to_lower()] == lang_name) { + variant_name = locale_elements[2].to_lower(); } } if (locale_elements.size() >= 4) { - if (variant_map.has(locale_elements[3].to_lower()) && variant_map[locale_elements[3].to_lower()] == lang) { - variant = locale_elements[3].to_lower(); + if (variant_map.has(locale_elements[3].to_lower()) && variant_map[locale_elements[3].to_lower()] == lang_name) { + variant_name = locale_elements[3].to_lower(); } } @@ -325,69 +325,69 @@ String TranslationServer::standardize_locale(const String &p_locale) const { Vector<String> script_extra = univ_locale.get_slice("@", 1).split(";"); for (int i = 0; i < script_extra.size(); i++) { if (script_extra[i].to_lower() == "cyrillic") { - script = "Cyrl"; + script_name = "Cyrl"; break; } else if (script_extra[i].to_lower() == "latin") { - script = "Latn"; + script_name = "Latn"; break; } else if (script_extra[i].to_lower() == "devanagari") { - script = "Deva"; + script_name = "Deva"; break; - } else if (variant_map.has(script_extra[i].to_lower()) && variant_map[script_extra[i].to_lower()] == lang) { - variant = script_extra[i].to_lower(); + } else if (variant_map.has(script_extra[i].to_lower()) && variant_map[script_extra[i].to_lower()] == lang_name) { + variant_name = script_extra[i].to_lower(); } } // Handles known non-ISO language names used e.g. on Windows. - if (locale_rename_map.has(lang)) { - lang = locale_rename_map[lang]; + if (locale_rename_map.has(lang_name)) { + lang_name = locale_rename_map[lang_name]; } // Handle country renames. - if (country_rename_map.has(country)) { - country = country_rename_map[country]; + if (country_rename_map.has(country_name)) { + country_name = country_rename_map[country_name]; } // Remove unsupported script codes. - if (!script_map.has(script)) { - script = ""; + if (!script_map.has(script_name)) { + script_name = ""; } // Add script code base on language and country codes for some ambiguous cases. - if (script.is_empty()) { + if (script_name.is_empty()) { for (int i = 0; i < locale_script_info.size(); i++) { const LocaleScriptInfo &info = locale_script_info[i]; - if (info.name == lang) { - if (country.is_empty() || info.supported_countries.has(country)) { - script = info.script; + if (info.name == lang_name) { + if (country_name.is_empty() || info.supported_countries.has(country_name)) { + script_name = info.script; break; } } } } - if (!script.is_empty() && country.is_empty()) { + if (!script_name.is_empty() && country_name.is_empty()) { // Add conntry code based on script for some ambiguous cases. for (int i = 0; i < locale_script_info.size(); i++) { const LocaleScriptInfo &info = locale_script_info[i]; - if (info.name == lang && info.script == script) { - country = info.default_country; + if (info.name == lang_name && info.script == script_name) { + country_name = info.default_country; break; } } } // Combine results. - String locale = lang; - if (!script.is_empty()) { - locale = locale + "_" + script; + String out = lang_name; + if (!script_name.is_empty()) { + out = out + "_" + script_name; } - if (!country.is_empty()) { - locale = locale + "_" + country; + if (!country_name.is_empty()) { + out = out + "_" + country_name; } - if (!variant.is_empty()) { - locale = locale + "_" + variant; + if (!variant_name.is_empty()) { + out = out + "_" + variant_name; } - return locale; + return out; } int TranslationServer::compare_locales(const String &p_locale_a, const String &p_locale_b) const { @@ -420,31 +420,29 @@ int TranslationServer::compare_locales(const String &p_locale_a, const String &p } String TranslationServer::get_locale_name(const String &p_locale) const { - String locale = standardize_locale(p_locale); - - String lang, script, country; - Vector<String> locale_elements = locale.split("_"); - lang = locale_elements[0]; + String lang_name, script_name, country_name; + Vector<String> locale_elements = standardize_locale(p_locale).split("_"); + lang_name = locale_elements[0]; if (locale_elements.size() >= 2) { if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) { - script = locale_elements[1]; + script_name = locale_elements[1]; } if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) { - country = locale_elements[1]; + country_name = locale_elements[1]; } } if (locale_elements.size() >= 3) { if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) { - country = locale_elements[2]; + country_name = locale_elements[2]; } } - String name = language_map[lang]; - if (!script.is_empty()) { - name = name + " (" + script_map[script] + ")"; + String name = language_map[lang_name]; + if (!script_name.is_empty()) { + name = name + " (" + script_map[script_name] + ")"; } - if (!country.is_empty()) { - name = name + ", " + country_name_map[country]; + if (!country_name.is_empty()) { + name = name + ", " + country_name_map[country_name]; } return name; } @@ -630,12 +628,12 @@ TranslationServer *TranslationServer::singleton = nullptr; bool TranslationServer::_load_translations(const String &p_from) { if (ProjectSettings::get_singleton()->has_setting(p_from)) { - Vector<String> translations = ProjectSettings::get_singleton()->get(p_from); + const Vector<String> &translation_names = ProjectSettings::get_singleton()->get(p_from); - int tcount = translations.size(); + int tcount = translation_names.size(); if (tcount) { - const String *r = translations.ptr(); + const String *r = translation_names.ptr(); for (int i = 0; i < tcount; i++) { Ref<Translation> tr = ResourceLoader::load(r[i]); @@ -964,7 +962,6 @@ void TranslationServer::_bind_methods() { } void TranslationServer::load_translations() { - String locale = get_locale(); _load_translations("internationalization/locale/translations"); //all _load_translations("internationalization/locale/translations_" + locale.substr(0, 2)); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 6218c21cde..872c8357ae 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3669,13 +3669,16 @@ String String::simplify_path() const { String drive; if (s.begins_with("local://")) { drive = "local://"; - s = s.substr(8, s.length()); + s = s.substr(8); } else if (s.begins_with("res://")) { drive = "res://"; - s = s.substr(6, s.length()); + s = s.substr(6); } else if (s.begins_with("user://")) { drive = "user://"; - s = s.substr(7, s.length()); + s = s.substr(7); + } else if (s.begins_with("uid://")) { + drive = "uid://"; + s = s.substr(6); } else if (is_network_share_path()) { drive = s.substr(0, 2); s = s.substr(2, s.length() - 2); @@ -3689,7 +3692,7 @@ String String::simplify_path() const { } if (p != -1 && p < s.find("/")) { drive = s.substr(0, p + 2); - s = s.substr(p + 2, s.length()); + s = s.substr(p + 2); } } @@ -4651,10 +4654,10 @@ String String::sprintf(const Array &values, bool *error) const { double value = values[value_index]; bool is_negative = (value < 0); String str = String::num(ABS(value), min_decimals); - bool not_numeric = isinf(value) || isnan(value); + const bool is_finite = Math::is_finite(value); // Pad decimals out. - if (!not_numeric) { + if (is_finite) { str = str.pad_decimals(min_decimals); } @@ -4662,7 +4665,7 @@ String String::sprintf(const Array &values, bool *error) const { // Padding. Leave room for sign later if required. int pad_chars_count = (is_negative || show_sign) ? min_chars - 1 : min_chars; - String pad_char = (pad_with_zeros && !not_numeric) ? String("0") : String(" "); // Never pad NaN or inf with zeros + String pad_char = (pad_with_zeros && is_finite) ? String("0") : String(" "); // Never pad NaN or inf with zeros if (left_justified) { str = str.rpad(pad_chars_count, pad_char); } else { @@ -4713,10 +4716,10 @@ String String::sprintf(const Array &values, bool *error) const { for (int i = 0; i < count; i++) { double val = vec[i]; String number_str = String::num(ABS(val), min_decimals); - bool not_numeric = isinf(val) || isnan(val); + const bool is_finite = Math::is_finite(val); // Pad decimals out. - if (!not_numeric) { + if (is_finite) { number_str = number_str.pad_decimals(min_decimals); } @@ -4724,7 +4727,7 @@ String String::sprintf(const Array &values, bool *error) const { // Padding. Leave room for sign later if required. int pad_chars_count = val < 0 ? min_chars - 1 : min_chars; - String pad_char = (pad_with_zeros && !not_numeric) ? String("0") : String(" "); // Never pad NaN or inf with zeros + String pad_char = (pad_with_zeros && is_finite) ? String("0") : String(" "); // Never pad NaN or inf with zeros if (left_justified) { number_str = number_str.rpad(pad_chars_count, pad_char); } else { |