updated to the new Pikotools api (new Space struct)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -88,7 +88,7 @@ return false;
|
||||
void Locale::ReadFile(const char * dir, const char * dir_def, const char * file)
|
||||
{
|
||||
bool read = false;
|
||||
temp_space.Clear();
|
||||
temp_space.clear();
|
||||
|
||||
if( dir_def && ReadFile(dir_def, file) )
|
||||
read = true;
|
||||
@@ -113,7 +113,7 @@ bool read = false;
|
||||
file_name += file;
|
||||
|
||||
loc_parser.SetSpace(temp_space);
|
||||
PT::SpaceParser::Status status = loc_parser.Parse(file_name);
|
||||
PT::SpaceParser::Status status = loc_parser.ParseSpaceFile(file_name);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
@@ -123,7 +123,7 @@ bool read = false;
|
||||
else
|
||||
if( status == PT::SpaceParser::syntax_error )
|
||||
{
|
||||
log << log1 << "Locale: syntax error in: " << file_name << " in line: " << loc_parser.line << logend;
|
||||
log << log1 << "Locale: syntax error in: " << file_name << " in line: " << loc_parser.get_last_parsed_line() << logend;
|
||||
}
|
||||
|
||||
return read;
|
||||
@@ -133,7 +133,7 @@ return read;
|
||||
|
||||
void Locale::AddLocale(const char * file)
|
||||
{
|
||||
std::wstring * id_str = temp_space.GetFirstValue(L"winix_locale_id");
|
||||
std::wstring * id_str = temp_space.get_wstr(L"winix_locale_id");
|
||||
|
||||
if( !id_str )
|
||||
{
|
||||
@@ -160,6 +160,7 @@ void Locale::ReadSubstTable(const char * dir, const char * dir_def)
|
||||
{
|
||||
bool read = false;
|
||||
|
||||
temp_space.clear();
|
||||
subst_url.clear();
|
||||
subst_smalllet.clear();
|
||||
subst_capitallet.clear();
|
||||
@@ -186,17 +187,17 @@ bool read = false;
|
||||
|
||||
loc_parser.SetSpace(temp_space);
|
||||
|
||||
if( loc_parser.Parse(file_name) == PT::SpaceParser::ok )
|
||||
if( loc_parser.ParseSpaceFile(file_name) == PT::SpaceParser::ok )
|
||||
{
|
||||
read = true;
|
||||
CreateSubstVector(subst_url, temp_space.Text(L"url_original"), temp_space.Text(L"url_changeto"));
|
||||
CreateSubstVector(subst_smalllet, temp_space.Text(L"smallleters"), temp_space.Text(L"capitalics"));
|
||||
CreateSubstVector(subst_capitallet, temp_space.Text(L"capitalics"), temp_space.Text(L"smallleters"));
|
||||
CreateSubstVector(subst_url, temp_space.to_wstr(L"url_original"), temp_space.to_wstr(L"url_changeto"));
|
||||
CreateSubstVector(subst_smalllet, temp_space.to_wstr(L"smallleters"), temp_space.to_wstr(L"capitalics"));
|
||||
CreateSubstVector(subst_capitallet, temp_space.to_wstr(L"capitalics"), temp_space.to_wstr(L"smallleters"));
|
||||
|
||||
std::vector<std::wstring> * sort_vec = temp_space.GetValue(L"sort");
|
||||
std::vector<std::wstring> sort_vec;
|
||||
|
||||
if( sort_vec )
|
||||
CreateSubstSortVector(subst_sort, *sort_vec);
|
||||
if( temp_space.to_list(L"sort", sort_vec) )
|
||||
CreateSubstSortVector(subst_sort, sort_vec);
|
||||
|
||||
log << log3 << "Locale: read characters substitution tables from: " << file_name << logend;
|
||||
}
|
||||
@@ -361,7 +362,7 @@ const std::wstring * Locale::GetKeyInLanguage(const std::wstring & key, size_t l
|
||||
size_t index = locale_indices[lang_id];
|
||||
|
||||
if( index < locale_tab.size() )
|
||||
return locale_tab[index].GetFirstValue(key);
|
||||
return locale_tab[index].get_wstr(key.c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -425,64 +426,29 @@ return empty;
|
||||
|
||||
|
||||
|
||||
bool Locale::IsList(const wchar_t * key, bool try_default_too)
|
||||
|
||||
bool Locale::GetList(const wchar_t * key, std::vector<std::wstring> & list, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsList(key_str, try_default_too);
|
||||
return GetList(key_str, list, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsList(const std::wstring & key, bool try_default_too) const
|
||||
bool Locale::GetList(const std::wstring & key, std::vector<std::wstring> & list, bool try_default_too) const
|
||||
{
|
||||
return IsList(key, current_lang, try_default_too);
|
||||
return GetList(key, current_lang, list, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::IsList(const wchar_t * key, size_t lang_id, bool try_default_too)
|
||||
bool Locale::GetList(const wchar_t * key, size_t lang_id, std::vector<std::wstring> & list, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsList(key_str, lang_id, try_default_too);
|
||||
return GetList(key_str, lang_id, list, 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::vector<std::wstring> * Locale::GetListInLanguage(const std::wstring & key, size_t lang_id) const
|
||||
bool Locale::GetListInLanguage(const std::wstring & key, size_t lang_id, std::vector<std::wstring> & list) const
|
||||
{
|
||||
if( lang_id < locale_indices.size() )
|
||||
{
|
||||
@@ -490,34 +456,26 @@ const std::vector<std::wstring> * Locale::GetListInLanguage(const std::wstring &
|
||||
|
||||
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;
|
||||
return locale_tab[index].to_list(key, list);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key,
|
||||
size_t lang_id, bool try_default_too) const
|
||||
bool Locale::GetList(const std::wstring & key, size_t lang_id, std::vector<std::wstring> & list, bool try_default_too) const
|
||||
{
|
||||
const std::vector<std::wstring> * list = GetListInLanguage(key, lang_id);
|
||||
|
||||
if( list )
|
||||
return *list;
|
||||
if( GetListInLanguage(key, lang_id, list) )
|
||||
return true;
|
||||
|
||||
if( !try_default_too || lang_id == default_lang )
|
||||
return empty_list;
|
||||
|
||||
list = GetListInLanguage(key, default_lang);
|
||||
return false;
|
||||
|
||||
if( list )
|
||||
return *list;
|
||||
if( GetListInLanguage(key, default_lang, list) )
|
||||
return true;
|
||||
|
||||
return empty_list;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -553,7 +511,7 @@ bool Locale::IsKeyByIndex(const std::wstring & key, size_t index, bool try_defau
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
if( locale_tab[index].GetValue(key) != 0 )
|
||||
if( locale_tab[index].get_object_field(key) != 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -582,7 +540,7 @@ const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index,
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
const std::wstring * value = locale_tab[index].GetFirstValue(key);
|
||||
const std::wstring * value = locale_tab[index].get_wstr(key.c_str());
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
@@ -613,47 +571,54 @@ bool Locale::IsListByIndex(const std::wstring & key, size_t index, bool try_defa
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
|
||||
|
||||
if( i != locale_tab[index].table.end() )
|
||||
if( locale_tab[index].has_key(key) )
|
||||
return true;
|
||||
}
|
||||
|
||||
if( try_default_too )
|
||||
return GetListInLanguage(key, default_lang) != 0;
|
||||
return IsListInLanguage(key, default_lang);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetListByIndex(const wchar_t * key,
|
||||
size_t index, bool try_default_too)
|
||||
bool Locale::IsListInLanguage(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
key_str = key;
|
||||
return GetListByIndex(key_str, index, try_default_too);
|
||||
if( lang_id < locale_indices.size() )
|
||||
{
|
||||
size_t index = locale_indices[lang_id];
|
||||
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
if( locale_tab[index].has_key(key) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetListByIndex(const std::wstring & key,
|
||||
size_t index, bool try_default_too) const
|
||||
bool Locale::GetListByIndex(const wchar_t * key, size_t index, std::vector<std::wstring> & list, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return GetListByIndex(key_str, index, list, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::GetListByIndex(const std::wstring & key, size_t index, std::vector<std::wstring> & list, 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;
|
||||
return locale_tab[index].to_list(key, list);
|
||||
}
|
||||
|
||||
if( try_default_too )
|
||||
{
|
||||
const std::vector<std::wstring> * value = GetListInLanguage(key, default_lang);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
return GetListInLanguage(key, default_lang, list);
|
||||
}
|
||||
|
||||
return empty_list;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user