From b1c7b04e9e4c65cf00140ec8f2bf72682ee834a9 Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Sun, 31 Dec 2017 00:03:52 +0000 Subject: [PATCH 14/31] LanguageList ~> std::vector --- src/language.h | 2 +- src/settings_gui.cpp | 2 +- src/strings.cpp | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/language.h b/src/language.h index d33ba8189..a4111c737 100644 --- a/src/language.h +++ b/src/language.h @@ -96,7 +96,7 @@ struct LanguageMetadata : public LanguagePackHeader { }; /** Type for the list of language meta data. */ -typedef SmallVector LanguageList; +using LanguageList = std::vector; /** The actual list of language meta data. */ extern LanguageList _languages; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0420ba15b..1fe442773 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -268,7 +268,7 @@ struct GameOptionsWindow : Window { case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown list = new DropDownList(); - for (uint i = 0; i < _languages.Length(); i++) { + for (uint i = 0; i < _languages.size(); i++) { if (&_languages[i] == _current_language) *selected_index = i; *list->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false); } diff --git a/src/strings.cpp b/src/strings.cpp index 1c539d934..591932f4f 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1874,8 +1874,8 @@ int CDECL StringIDSorter(const StringID *a, const StringID *b) */ const LanguageMetadata *GetLanguage(byte newgrflangid) { - for (const LanguageMetadata *lang = _languages.Begin(); lang != _languages.End(); lang++) { - if (newgrflangid == lang->newgrflangid) return lang; + for (auto &lang : _languages) { + if (newgrflangid == lang.newgrflangid) return ⟨ } return NULL; @@ -1930,7 +1930,7 @@ static void GetLanguageList(const char *path) } else if (GetLanguage(lmd.newgrflangid) != NULL) { DEBUG(misc, 3, "%s's language ID is already known", lmd.file); } else { - *_languages.Append() = lmd; + _languages.push_back(lmd); } } closedir(dir); @@ -1950,7 +1950,7 @@ void InitializeLanguagePacks() FioAppendDirectory(path, lastof(path), sp, LANG_DIR); GetLanguageList(path); } - if (_languages.Length() == 0) usererror("No available language packs (invalid versions?)"); + if (_languages.empty()) usererror("No available language packs (invalid versions?)"); /* Acquire the locale of the current system */ const char *lang = GetCurrentLocale("LC_MESSAGES"); @@ -1958,22 +1958,22 @@ void InitializeLanguagePacks() const LanguageMetadata *chosen_language = NULL; ///< Matching the language in the configuration file or the current locale const LanguageMetadata *language_fallback = NULL; ///< Using pt_PT for pt_BR locale when pt_BR is not available - const LanguageMetadata *en_GB_fallback = _languages.Begin(); ///< Fallback when no locale-matching language has been found + const LanguageMetadata *en_GB_fallback = _languages.data(); ///< Fallback when no locale-matching language has been found /* Find a proper language. */ - for (const LanguageMetadata *lng = _languages.Begin(); lng != _languages.End(); lng++) { + for (const auto& lng : _languages) { /* We are trying to find a default language. The priority is by * configuration file, local environment and last, if nothing found, * English. */ - const char *lang_file = strrchr(lng->file, PATHSEPCHAR) + 1; + const char *lang_file = strrchr(lng.file, PATHSEPCHAR) + 1; if (strcmp(lang_file, _config_language_file) == 0) { - chosen_language = lng; + chosen_language = &lng; break; } - if (strcmp (lng->isocode, "en_GB") == 0) en_GB_fallback = lng; - if (strncmp(lng->isocode, lang, 5) == 0) chosen_language = lng; - if (strncmp(lng->isocode, lang, 2) == 0) language_fallback = lng; + if (strcmp (lng.isocode, "en_GB") == 0) en_GB_fallback = &lng; + if (strncmp(lng.isocode, lang, 5) == 0) chosen_language = &lng; + if (strncmp(lng.isocode, lang, 2) == 0) language_fallback = &lng; } /* We haven't found the language in the config nor the one in the locale. -- 2.14.1