updated to the new Pikotools api (new Space struct)

This commit is contained in:
2021-04-09 17:50:58 +02:00
parent 00b980e74b
commit 35e10ed469
52 changed files with 795 additions and 736 deletions

View File

@@ -464,7 +464,7 @@ void dir_last_has_html_template(Info & i)
void dir_last_meta_str(Info & i)
{
cur->request->dir_tab.back()->item_content.meta.Serialize(i.out, true, false);
cur->request->dir_tab.back()->item_content.meta.serialize_to_space_stream(i.out, true);
}
@@ -497,7 +497,7 @@ void dir_last_meta_tab_has_next(Info & i)
void dir_last_admin_meta_str(Info & i)
{
cur->request->dir_tab.back()->item_content.meta_admin.Serialize(i.out, true, false);
cur->request->dir_tab.back()->item_content.meta_admin.serialize_to_space_stream(i.out, true);
}

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2015, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ void env_str(Info & i)
User * puser = cur->session->puser;
if( puser )
puser->env.Serialize(i.out, true, false);
puser->env.serialize_to_space_stream(i.out, true);
}
@@ -105,7 +105,7 @@ void env_admin_str(Info & i)
User * puser = cur->session->puser;
if( puser )
puser->aenv.Serialize(i.out, true, false);
puser->aenv.serialize_to_space_stream(i.out, true);
}

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2015, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -555,7 +555,7 @@ HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space)
{
if( escape )
{
space.Serialize(*this, true, false);
space.serialize_to_space_stream(*this, true);
/*
tmp_stream.Clear();

View File

@@ -416,7 +416,7 @@ void item_sort(Info & i)
void item_meta_str(Info & i)
{
cur->request->last_item->item_content.meta.Serialize(i.out, true, false);
cur->request->last_item->item_content.meta.serialize_to_space_stream(i.out, true);
}
@@ -456,7 +456,7 @@ void item_meta_tab_has_next(Info & i)
void item_admin_meta_str(Info & i)
{
cur->request->last_item->item_content.meta_admin.Serialize(i.out, true, false);
cur->request->last_item->item_content.meta_admin.serialize_to_space_stream(i.out, true);
}
@@ -848,7 +848,7 @@ void item_tab_has_next(Info & i)
void item_tab_meta_str(Info & i)
{
if( item_index < cur->request->item_tab.size() )
cur->request->item_tab[item_index].item_content.meta.Serialize(i.out, true, false);
cur->request->item_tab[item_index].item_content.meta.serialize_to_space_stream(i.out, true);
}

View File

@@ -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;
}

View File

@@ -145,18 +145,10 @@ public:
// lists
// 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;
bool GetList(const wchar_t * key, std::vector<std::wstring> & list, bool try_default_too = true);
bool GetList(const std::wstring & key, std::vector<std::wstring> & list, bool try_default_too = true) const;
bool GetList(const wchar_t * key, size_t lang_id, std::vector<std::wstring> & list, bool try_default_too = true);
bool GetList(const std::wstring & key, size_t lang_id, std::vector<std::wstring> & list, 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
@@ -181,10 +173,9 @@ public:
// (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;
bool GetListByIndex(const wchar_t * key, size_t index, std::vector<std::wstring> & list, bool try_default_too = true);
bool GetListByIndex(const std::wstring & key, size_t index, std::vector<std::wstring> & list, bool try_default_too = true) const;
// url substitution characters
@@ -227,7 +218,8 @@ private:
size_t SubstFindIndex(const std::vector<SubstItem> & vect, wchar_t val);
wchar_t SubstFind(const std::vector<SubstItem> & vect, wchar_t val);
const std::wstring * GetKeyInLanguage(const std::wstring & key, size_t lang_id) const;
const std::vector<std::wstring> * GetListInLanguage(const std::wstring & key, size_t lang_id) const;
bool GetListInLanguage(const std::wstring & key, size_t lang_id, std::vector<std::wstring> & list) const;
bool IsListInLanguage(const std::wstring & key, size_t lang_id) const;
// locale files
@@ -264,7 +256,6 @@ private:
std::string file_name;
std::wstring key_str;
const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName)
const std::vector<std::wstring> empty_list; // the same as above
std::string adir1, adir2;
std::wstring pattern_value;
};

View File

@@ -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
@@ -143,7 +143,7 @@ void print_date_nice(Info & i, const PT::Date & date)
// cannot be a const reference at the moment (PT::Space is used)
void print_user_name(Info & i, User & user)
{
std::wstring * dname = user.aenv.GetFirstValue(L"display_name");
std::wstring * dname = user.aenv.get_wstr(L"display_name");
if( dname && !IsWhite(*dname, true) )
i.out << *dname;

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2018, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -75,12 +75,14 @@ void copy_space(const std::vector<Ezc::Var> & params, std::vector<std::wstring>
PT::Space * find_space(const std::vector<Ezc::Var> & params, PT::Space & space, size_t level = 0)
{
if( level + 1 < params.size() )
if( level + 1 < params.size() && space.child_spaces )
{
for(size_t i=0 ; i<space.spaces.size() ; ++i)
for(size_t i=0 ; i<space.child_spaces->size() ; ++i)
{
if( space.spaces[i]->name == params[level].str )
return find_space(params, *space.spaces[i], level+1);
PT::Space & child = *(*space.child_spaces)[i];
if( child.name && *child.name == params[level].str )
return find_space(params, child, level+1);
}
// there is no such a space
@@ -155,7 +157,7 @@ void space_value(Info & i, PT::Space & space, bool escape)
if( space_info.last_space )
{
const std::wstring & param = i.params.back().str;
const std::wstring * value = space_info.last_space->GetFirstValue(param);
const std::wstring * value = space_info.last_space->get_wstr(param.c_str());
if( value )
{
@@ -193,7 +195,7 @@ void space_list_tab(Info & i, PT::Space & space)
PT::Space * dst_space = find_space(i.params, space);
if( dst_space )
dst_space->ListText(i.params.back().str, stack_item->values);
dst_space->to_list(i.params.back().str, stack_item->values);
i.res = i.iter < stack_item->values.size();
}

View File

@@ -899,11 +899,15 @@ using namespace TemplatesFunctions;
for(size_t i=0 ; i<TemplatesFunctions::locale.Size() ; ++i)
{
if( TemplatesFunctions::locale.IsKeyByIndex(L"html_lang_attr_value", i, false) &&
if( TemplatesFunctions::locale.IsKeyByIndex(L"winix_html_lang_attr", i, false) &&
TemplatesFunctions::locale.IsListByIndex(L"language_orphans", i, false) )
{
html_filter.AssignOrphans(TemplatesFunctions::locale.GetByIndex(L"html_lang_attr_value", i, false),
TemplatesFunctions::locale.GetListByIndex(L"language_orphans", i, false));
const std::wstring & html_lang_attr = TemplatesFunctions::locale.GetByIndex(L"winix_html_lang_attr", i, false);
std::vector<std::wstring> orphans;
TemplatesFunctions::locale.GetListByIndex(L"language_orphans", i, orphans, false);
html_filter.AssignOrphans(html_lang_attr, orphans);
}
}
}

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -477,7 +477,7 @@ TexTextStream & TexTextStream::operator<<(const PT::Space & space)
tmp_stream.Clear();
// !! IMPROVE ME
// we can calculate how many memory is needed beforehand
space.Serialize(tmp_stream, true, false);
space.serialize_to_space_stream(tmp_stream, true);
operator<<(tmp_stream.Str());
tmp_stream.Clear();