rewritten: public interface in TemplatesFunctions::Locale

added a default parameter bool try_default_too = true to some methods: Get(), IsKey()
           added more methods for accessing by an internal index



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@854 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-06-27 23:21:43 +00:00
parent b8ff5d4cfc
commit 403cca5aad
4 changed files with 221 additions and 96 deletions

View File

@@ -308,27 +308,27 @@ size_t Locale::GetDefLang() const
}
bool Locale::IsKey(const wchar_t * key)
bool Locale::IsKey(const wchar_t * key, bool try_default_too)
{
key_str = key;
return IsKey(key_str);
return IsKey(key_str, try_default_too);
}
bool Locale::IsKey(const wchar_t * key, size_t lang_id)
bool Locale::IsKey(const std::wstring & key, bool try_default_too) const
{
return IsKey(key, current_lang, try_default_too);
}
bool Locale::IsKey(const wchar_t * key, size_t lang_id, bool try_default_too)
{
key_str = key;
return IsKey(key_str, lang_id);
return IsKey(key_str, lang_id, try_default_too);
}
bool Locale::IsKey(const std::wstring & key) const
{
return IsKey(key, current_lang);
}
const std::wstring * Locale::GetKeyInLanguage(const std::wstring & key, size_t lang_id) const
{
if( lang_id < locale_indices.size() )
@@ -343,63 +343,50 @@ return 0;
}
bool Locale::IsKey(const std::wstring & key, size_t lang_id) const
bool Locale::IsKey(const std::wstring & key, size_t lang_id, bool try_default_too) const
{
const std::wstring * value = GetKeyInLanguage(key, lang_id);
if( value )
if( GetKeyInLanguage(key, lang_id) != 0 )
return true;
if( lang_id == default_lang )
if( !try_default_too || lang_id == default_lang )
return false;
return GetKeyInLanguage(key, default_lang) != 0;
}
bool Locale::IsKeyLang(const wchar_t * key, size_t lang)
const std::wstring & Locale::Get(const wchar_t * key, bool try_default_too)
{
key_str = key;
return IsKeyLang(key_str, lang);
return Get(key_str, try_default_too);
}
bool Locale::IsKeyLang(const std::wstring & key, size_t lang_id) const
const std::wstring & Locale::Get(const std::wstring & key, bool try_default_too) const
{
return GetKeyInLanguage(key, lang_id) != 0;
return Get(key, current_lang, try_default_too);
}
const std::wstring & Locale::Get(const wchar_t * key)
const std::wstring & Locale::Get(const wchar_t * key, size_t lang_id, bool try_default_too)
{
key_str = key;
return Get(key_str);
}
const std::wstring & Locale::Get(const wchar_t * key, size_t lang_id)
{
key_str = key;
return Get(key_str, lang_id);
return Get(key_str, lang_id, try_default_too);
}
const std::wstring & Locale::Get(const std::wstring & key) const
{
return Get(key, current_lang);
}
const std::wstring & Locale::Get(const std::wstring & key, size_t lang_id) const
const std::wstring & Locale::Get(const std::wstring & key, size_t lang_id, bool try_default_too) const
{
const std::wstring * value = GetKeyInLanguage(key, lang_id);
if( value )
return *value;
if( lang_id == default_lang )
if( !try_default_too || lang_id == default_lang )
return empty;
value = GetKeyInLanguage(key, default_lang);
@@ -412,22 +399,60 @@ return empty;
bool Locale::IsKeyLangList(const wchar_t * key, size_t lang_id)
bool Locale::IsList(const wchar_t * key, bool try_default_too)
{
key_str = key;
return IsKeyLangList(key_str, lang_id);
return IsList(key_str, try_default_too);
}
bool Locale::IsKeyLangList(const std::wstring & key, size_t lang_id) const
bool Locale::IsList(const std::wstring & key, bool try_default_too) const
{
return GetListInLanguage(key, lang_id) != 0;
return IsList(key, current_lang, try_default_too);
}
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key) const
bool Locale::IsList(const wchar_t * key, size_t lang_id, bool try_default_too)
{
return GetList(key, current_lang);
key_str = key;
return IsList(key_str, lang_id, try_default_too);
}
bool Locale::IsList(const std::wstring & key, size_t lang_id, bool try_default_too) const
{
if( GetListInLanguage(key, lang_id) != 0 )
return true;
if( !try_default_too || lang_id == default_lang )
return false;
return GetListInLanguage(key, default_lang) != 0;
}
const std::vector<std::wstring> & Locale::GetList(const wchar_t * key, bool try_default_too)
{
key_str = key;
return GetList(key_str, try_default_too);
}
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key, bool try_default_too) const
{
return GetList(key, current_lang, try_default_too);
}
const std::vector<std::wstring> & Locale::GetList(const wchar_t * key, size_t lang_id, bool try_default_too)
{
key_str = key;
return GetList(key_str, lang_id, try_default_too);
}
@@ -451,14 +476,15 @@ return 0;
}
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key, size_t lang_id) const
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key,
size_t lang_id, bool try_default_too) const
{
const std::vector<std::wstring> * list = GetListInLanguage(key, lang_id);
if( list )
return *list;
if( lang_id == default_lang )
if( !try_default_too || lang_id == default_lang )
return empty_list;
list = GetListInLanguage(key, default_lang);
@@ -490,14 +516,44 @@ size_t Locale::Size() const
}
const std::wstring & Locale::GetByIndex(const wchar_t * key, size_t index)
bool Locale::IsKeyByIndex(const wchar_t * key, size_t index, bool try_default_too)
{
key_str = key;
return GetByIndex(key_str, index);
return IsKeyByIndex(key_str, index, try_default_too);
}
const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index) const
bool Locale::IsKeyByIndex(const std::wstring & key, size_t index, bool try_default_too) const
{
if( index < locale_tab.size() )
{
if( locale_tab[index].GetValue(key) != 0 )
return true;
}
if( try_default_too )
{
if( GetKeyInLanguage(key, default_lang) != 0 )
return true;
}
return false;
}
const std::wstring & Locale::GetByIndex(const wchar_t * key, size_t index, bool try_default_too)
{
key_str = key;
return GetByIndex(key_str, index, try_default_too);
}
const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index,
bool try_default_too) const
{
if( index < locale_tab.size() )
{
@@ -507,12 +563,76 @@ const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index)
return *value;
}
if( try_default_too )
{
const std::wstring * value = GetKeyInLanguage(key, default_lang);
if( value )
return *value;
}
return empty;
}
bool Locale::IsListByIndex(const wchar_t * key, size_t index, bool try_default_too)
{
key_str = key;
return IsListByIndex(key_str, index, try_default_too);
}
bool Locale::IsListByIndex(const std::wstring & key, size_t index, bool try_default_too) const
{
if( index < locale_tab.size() )
{
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
if( i != locale_tab[index].table.end() )
return true;
}
if( try_default_too )
return GetListInLanguage(key, default_lang) != 0;
return false;
}
const std::vector<std::wstring> & Locale::GetListByIndex(const wchar_t * key,
size_t index, bool try_default_too)
{
key_str = key;
return GetListByIndex(key_str, index, try_default_too);
}
const std::vector<std::wstring> & Locale::GetListByIndex(const std::wstring & key,
size_t index, bool try_default_too) const
{
if( index < locale_tab.size() )
{
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
if( i != locale_tab[index].table.end() )
return i->second;
}
if( try_default_too )
{
const std::vector<std::wstring> * value = GetListInLanguage(key, default_lang);
if( value )
return *value;
}
return empty_list;
}