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

@@ -31,6 +31,15 @@ public:
// if you change this values you should reload all locale files
void SetLocaleMaxId(size_t max_id);
// setting/getting current language
// default: 0
void SetCurLang(size_t lang_id);
size_t GetCurLang() const;
// which language is used instead of if there is no a key in an other language
// default: 0
void SetDefLang(size_t lang_id);
size_t GetDefLang() const;
// reading locales
// you should call SetLocaleFiles() beforehand
@@ -42,46 +51,35 @@ public:
// returns true if a language with lang_id exists
bool HasLanguage(size_t lang_id);
// checking whether there is a 'key' in the current language (or in 'lang' language)
bool IsKey(const wchar_t * key);
bool IsKey(const wchar_t * key, size_t lang_id);
bool IsKey(const std::wstring & key) const;
bool IsKey(const std::wstring & key, size_t lang_id) const;
// checking whether there is a 'key' in the current language
// or in the default language if try_default_too is true
bool IsKey(const wchar_t * key, bool try_default_too = true);
bool IsKey(const std::wstring & key, bool try_default_too = true) const;
// checking whether there is a 'key' in the lang language
// (default language is not checked)
bool IsKeyLang(const wchar_t * key, size_t lang_id);
bool IsKeyLang(const std::wstring & key, size_t lang_id) const;
// returning specific 'key'
const std::wstring & Get(const wchar_t * key);
const std::wstring & Get(const wchar_t * key, size_t lang_id);
const std::wstring & Get(const std::wstring & key) const;
const std::wstring & Get(const std::wstring & key, size_t lang_id) const;
// checking whether there is a 'key' in the lang_id language
// or in the default language if try_default_too is true
bool IsKey(const wchar_t * key, size_t lang_id, bool try_default_too = true);
bool IsKey(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
// returning a value for a specific key
const std::wstring & Get(const wchar_t * key, bool try_default_too = true);
const std::wstring & Get(const wchar_t * key, size_t lang_id, bool try_default_too = true);
const std::wstring & Get(const std::wstring & key, bool try_default_too = true) const;
const std::wstring & Get(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
// lists
bool IsKeyLangList(const wchar_t * key, size_t lang_id);
bool IsKeyLangList(const std::wstring & key, size_t lang_id) const;
const std::vector<std::wstring> & GetList(const std::wstring & key) const;
const std::vector<std::wstring> & GetList(const std::wstring & key, size_t lang_id) const;
// setting/getting current language
// default: 0
void SetCurLang(size_t lang_id);
size_t GetCurLang() const;
// which language is used instead of if there is no a key in an other language
// default: 0
void SetDefLang(size_t lang_id);
size_t GetDefLang() const;
// current limitation:
// we are looking only in 'space.table' so lists with only one item are not found
// (SplitSingle(true) was called to the space struct)
bool IsList(const wchar_t * key, bool try_default_too = true);
bool IsList(const std::wstring & key, bool try_default_too = true) const;
bool IsList(const wchar_t * key, size_t lang_id, bool try_default_too = true);
bool IsList(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
const std::vector<std::wstring> & GetList(const wchar_t * key, bool try_default_too = true);
const std::vector<std::wstring> & GetList(const std::wstring & key, bool try_default_too = true) const;
const std::vector<std::wstring> & GetList(const wchar_t * key, size_t lang_id, bool try_default_too = true);
const std::vector<std::wstring> & GetList(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
// converting lang_id to an internal index
// returns an index from <0, Size()-1> or size_t(-1) if lang_id is incorrect
@@ -95,9 +93,21 @@ public:
// accessing by an internal index
// internal index is from zero to Size()-1
const std::wstring & GetByIndex(const wchar_t * key, size_t index);
const std::wstring & GetByIndex(const std::wstring & key, size_t index) const;
bool IsKeyByIndex(const wchar_t * key, size_t index, bool try_default_too = true);
bool IsKeyByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const;
const std::wstring & GetByIndex(const wchar_t * key, size_t index, bool try_default_too = true);
const std::wstring & GetByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const;
// lists by an internal index
// current limitation:
// we are looking only in 'space.table' so lists with only one item are not found
// (SplitSingle(true) was called to the space struct)
bool IsListByIndex(const wchar_t * key, size_t index, bool try_default_too = true);
bool IsListByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const;
const std::vector<std::wstring> & GetListByIndex(const wchar_t * key, size_t index,
bool try_default_too = true);
const std::vector<std::wstring> & GetListByIndex(const std::wstring & key, size_t index,
bool try_default_too = true) const;
// it sets whether we should parse locale files as utf-8 files