From db5ae289d27ce402725f02c964b94a345ac1627c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 18 Aug 2022 05:22:37 +0000 Subject: [PATCH] Fix a bug about setting i18n The std::set is not implemented using stack. The languages value MUST be stored in the added order. This patch uses std::vector instead of std::set to add languages. Change-Id: I576761541c61b85b0de7ad6a850ecf23d01a6276 Signed-off-by: Hwankyu Jhun --- tizen-cpp/app-core-cpp/app_core_base.cc | 43 +++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index cb89bce..e4e6e86 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include #include "app-core-cpp/app_core_base.hh" #include "common/glib_private.hh" @@ -152,10 +154,10 @@ class AppCoreBase::Impl { void UpdateRegion(); std::list SplitLanguage(const std::string& lang); std::string GetLanguage(std::string lang); - void AppendDefaultLangs(std::set& lang_set); + void AppendDefaultLangs(std::vector& lang_set); std::string GetStringBefore(const char* str, const char* delim); std::map> GetLangTable(); - void AppendLangs(const std::string& lang, std::set& lang_set, + void AppendLangs(const std::string& lang, std::vector& lang_set, std::map>& table); void ChangeLang(); void OnFreezerSignal(); @@ -891,8 +893,10 @@ std::list AppCoreBase::Impl::SplitLanguage( return li; } -void AppCoreBase::Impl::AppendDefaultLangs(std::set& lang_set) { - lang_set.insert({"en_US", "en_GB", "en"}); +void AppCoreBase::Impl::AppendDefaultLangs(std::vector& langs) { + langs.push_back("en_US"); + langs.push_back("en_GB"); + langs.push_back("en"); } std::string AppCoreBase::Impl::GetStringBefore(const char* cstr, @@ -940,17 +944,17 @@ std::map> AppCoreBase::Impl::GetLangTable() { } void AppCoreBase::Impl::AppendLangs(const std::string& lang, - std::set& lang_set, + std::vector& langs, std::map>& table) { if (lang.empty()) return; - lang_set.insert(lang); + langs.push_back(lang); std::string extract_lang = GetStringBefore(lang.c_str(), "."); if (extract_lang.empty()) return; - if (lang_set.find(extract_lang) != lang_set.end()) + if (std::find(langs.begin(), langs.end(), extract_lang) != langs.end()) return; std::string parent_lang = GetStringBefore(extract_lang.c_str(), "_"); @@ -962,21 +966,30 @@ void AppCoreBase::Impl::AppendLangs(const std::string& lang, auto it = table[parent_lang].find(extract_lang); if (it != table[parent_lang].end()) { - lang_set.insert(move(*it)); + std::string value = *it; + if (std::find(langs.begin(), langs.end(), value) == langs.end()) + langs.push_back(std::move(value)); + table[parent_lang].erase(it); return; } it = table[parent_lang].find(parent_lang); if (it != table[parent_lang].end()) { - lang_set.insert(move(*it)); + std::string value = *it; + if (std::find(langs.begin(), langs.end(), value) == langs.end()) + langs.push_back(std::move(value)); + table[parent_lang].erase(parent_lang); return; } if (!table[parent_lang].empty()) { auto i = table[parent_lang].begin(); - lang_set.insert(move(*i)); + std::string value = *i; + if (std::find(langs.begin(), langs.end(), value) == langs.end()) + langs.push_back(std::move(value)); + table[parent_lang].erase(i); } } @@ -990,17 +1003,17 @@ std::string AppCoreBase::Impl::GetLanguage(std::string lang) { if (table.empty()) return ""; - std::set lang_set {}; + std::vector langs; for (auto& i : l) - AppendLangs(i, lang_set, table); + AppendLangs(i, langs, table); - AppendDefaultLangs(lang_set); + AppendDefaultLangs(langs); std::string ret; - for (auto& i : lang_set) { + for (auto& i : langs) { if (ret.empty()) ret = i; else - ret = i + ":" + ret; + ret += ":" + i; } return ret; -- 2.7.4