From: <gua...@us...> - 2013-12-06 14:23:17
|
Revision: 5453 http://sourceforge.net/p/moneymanagerex/code/5453 Author: guanlisheng Date: 2013-12-06 14:23:13 +0000 (Fri, 06 Dec 2013) Log Message: ----------- update to latest code from github Modified Paths: -------------- trunk/3rd/cgitemplate/examples/example.cpp trunk/3rd/cgitemplate/html_template.cpp trunk/3rd/cgitemplate/html_template.h trunk/3rd/cgitemplate/test.cpp trunk/3rd/cgitemplate/test.h Modified: trunk/3rd/cgitemplate/examples/example.cpp =================================================================== --- trunk/3rd/cgitemplate/examples/example.cpp 2013-12-06 13:26:54 UTC (rev 5452) +++ trunk/3rd/cgitemplate/examples/example.cpp 2013-12-06 14:23:13 UTC (rev 5453) @@ -5,47 +5,45 @@ //---------------------------------------------------------------------------- -int main(int argc, char* argv[]) -{ - // create a template object - html_template templ("example.tmpl"); +int main(int argc, char* argv[]) { + // create a template object + html_template templ("example.tmpl"); - // assign a value to variable VAR1 - templ("VAR1") = "I am your very first template variable."; + // assign a value to variable VAR1 + templ("VAR1") = "I am your very first template variable."; - // create a loop - does not have to be an std::map, we are just using this for - // clarity + // create a loop - does not have to be an std::map, we are just using this for + // clarity - map<string, int> scores; // student names and scores on a test - scores["Aagney"] = 45; - scores["Eileen"] = 83; - scores["Basil" ] = 91; - scores["Jagati"] = 93; - scores["Raine" ] = 69; + map<string, int> scores; // student names and scores on a test + scores["Aagney"] = 45; + scores["Eileen"] = 83; + scores["Basil" ] = 91; + scores["Jagati"] = 93; + scores["Raine" ] = 69; - map<string, int>::const_iterator itr = scores.begin(); - loop_t loop; // the loop variable - - for( ; itr != scores.end(); ++itr ) - { - const string & name = itr->first; - const int & score = itr->second; + map<string, int>::const_iterator itr = scores.begin(); + loop_t loop; // the loop variable - // create a row - row_t row; - - // populate columns - row("name") = name; - row("score") = score; // can be ANY basic data type, this one is an integer - - // add the row to the loop, and so on.... - loop += row; - } - - // assign the loop to the template (case-insensitive) - templ("SCORES") = loop; + for( ; itr != scores.end(); ++itr ) { + const string & name = itr->first; + const int & score = itr->second; - cout << templ; - return 0; + // create a row + row_t row; + + // populate columns + row("name") = name; + row("score") = score; // can be ANY basic data type, this one is an integer + + // add the row to the loop, and so on.... + loop += row; + } + + // assign the loop to the template (case-insensitive) + templ("SCORES") = loop; + + cout << templ; + return 0; } Modified: trunk/3rd/cgitemplate/html_template.cpp =================================================================== --- trunk/3rd/cgitemplate/html_template.cpp 2013-12-06 13:26:54 UTC (rev 5452) +++ trunk/3rd/cgitemplate/html_template.cpp 2013-12-06 14:23:13 UTC (rev 5453) @@ -1,22 +1,24 @@ /*********************************************************************** * Copyright (C) 2009 Andrei Taranchenko * Contact: http://www.nulidex.com/contact + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + http://www.apache.org/licenses/LICENSE-2.0 - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + **********************************************************************/ - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - **********************************************************************/ - #ifndef html_template_c #define html_template_c #include "html_template.h" @@ -29,2020 +31,1826 @@ //---------------------------------------------------------------------------- // table cell //---------------------------------------------------------------------------- -row_cell_s::row_cell_s() -{ - // we are not creating a table object yet, just because we may not need it in - // the first place. - p_table = 0; +row_cell_s::row_cell_s() { + // we are not creating a table object yet, just because we may not need it in + // the first place. + p_table = 0; } //---------------------------------------------------------------------------- -row_cell_s::row_cell_s(const row_cell_s & arg) -{ - str_val = arg.str_val; - p_table = 0; // IMPORTANT, if not zero, the code will assume memory - // allocated for table, while this cell actually may - // contain a string value only +row_cell_s::row_cell_s(const row_cell_s & arg) { + str_val = arg.str_val; + p_table = 0; // IMPORTANT, if not zero, the code will assume memory + // allocated for table, while this cell actually may + // contain a string value only - if ( arg.p_table ) // this is why zero-init above is important, but it's - // for the object being assigned - { - p_table = new loop_s; - *p_table = *arg.p_table; - } + if ( arg.p_table ) // this is why zero-init above is important, but it's + // for the object being assigned + { + p_table = new loop_s; + *p_table = *arg.p_table; + } } //---------------------------------------------------------------------------- -row_cell_s::~row_cell_s() -{ - if ( p_table ) - { - delete p_table; - } +row_cell_s::~row_cell_s() { + if ( p_table ) { + delete p_table; + } } //---------------------------------------------------------------------------- -row_cell_s & row_cell_s::operator= (const loop_s & arg) -{ - p_table = new loop_s; - *p_table = arg; - return *this; +row_cell_s & row_cell_s::operator= (const loop_s & arg) { + p_table = new loop_s; + *p_table = arg; + return *this; } //---------------------------------------------------------------------------- -// table row + // table row //---------------------------------------------------------------------------- -row_cell_s & row_s::operator() (const std::string & str_name) -{ - string str_name_uc = str_name; - // uppercase - str_name_uc = str_name; - uc( str_name_uc ); - - // create new table cell - row_cell_s cell; - // insert cell into row container - cells_c.insert(std::make_pair(str_name_uc, cell)); - // return cell so that we can assign a value to it - return cells_c[str_name_uc]; +row_cell_s & row_s::operator() (const std::string & str_name) { + string str_name_uc = str_name; + // uppercase + str_name_uc = str_name; + uc( str_name_uc ); + + // create new table cell + row_cell_s cell; + // insert cell into row container + cells_c.insert(std::make_pair(str_name_uc, cell)); + // return cell so that we can assign a value to it + return cells_c[str_name_uc]; } //---------------------------------------------------------------------------- -// tag type object + // tag type object //---------------------------------------------------------------------------- -tag_type_s::tag_type_s() -{ - str_tag_class = ""; - str_tag_type = ""; - b_block_tag = false; +tag_type_s::tag_type_s() { + str_tag_class = ""; + str_tag_type = ""; + b_block_tag = false; } //---------------------------------------------------------------------------- tag_type_s::tag_type_s(const std::string & arg_type, const std::string & arg_class, - bool arg_block_tag /*= false*/) -{ - str_tag_class = arg_class; - str_tag_type = arg_type; - b_block_tag = arg_block_tag; + bool arg_block_tag /*= false*/) { + str_tag_class = arg_class; + str_tag_type = arg_type; + b_block_tag = arg_block_tag; } //---------------------------------------------------------------------------- -bool tag_type_s::operator== (const tag_type_s & rhs) const -{ - // two tags are equal if they are of the same CLASS, so ELSE is equal to IF - return (str_tag_class == rhs.str_tag_class); +bool tag_type_s::operator== (const tag_type_s & rhs) const { + // two tags are equal if they are of the same CLASS, so ELSE is equal to IF + return (str_tag_class == rhs.str_tag_class); } //---------------------------------------------------------------------------- -bool tag_type_s::operator!= (const tag_type_s & rhs) const -{ - return !(*this == rhs); +bool tag_type_s::operator!= (const tag_type_s & rhs) const { + return !(*this == rhs); } //---------------------------------------------------------------------------- -// tag object + // tag object //---------------------------------------------------------------------------- -tag_s::tag_s() -{ - Reset(); +tag_s::tag_s() { + Reset(); } //---------------------------------------------------------------------------- -void tag_s::Reset() -{ - str_name = ""; - begin = string::npos; - end = string::npos; - b_termination = false; - b_splitter = false; - escape_mode = ESC_NONE; +void tag_s::Reset() { + str_name = ""; + begin = string::npos; + end = string::npos; + b_termination = false; + b_splitter = false; + escape_mode = ESC_NONE; } //---------------------------------------------------------------------------- -tag_s::tag_s(const tag_type_s & arg_type) -{ - tag_type = arg_type; +tag_s::tag_s(const tag_type_s & arg_type) { + tag_type = arg_type; } //---------------------------------------------------------------------------- -void tag_s::Shift(const ptrdiff_t i_offset) -{ - // do not shit an empty tag - if ( begin == string::npos ) return; +void tag_s::Shift(const ptrdiff_t i_offset) { + // do not shit an empty tag + if ( begin == string::npos ) return; - begin = static_cast<size_t>(begin + i_offset); - end = static_cast<size_t>(end + i_offset); + begin = static_cast<size_t>(begin + i_offset); + end = static_cast<size_t>(end + i_offset); } //---------------------------------------------------------------------------- -const bool tag_s::Empty() const -{ - // tag is empty if none of its properties have been defined - return ( - str_name.empty() == true - && b_termination == false - && b_splitter == false - ); +const bool tag_s::Empty() const { + // tag is empty if none of its properties have been defined + return ( + str_name.empty() == true + && b_termination == false + && b_splitter == false + ); } //---------------------------------------------------------------------------- -const size_t tag_s::Length() const -{ - return (end - begin) + 1; +const size_t tag_s::Length() const { + return (end - begin) + 1; } //---------------------------------------------------------------------------- -bool tag_s::operator< (const tag_s & rhs) const -{ - // compare start positions of two tags to find which is further up - return begin < rhs.begin; +bool tag_s::operator< (const tag_s & rhs) const { + // compare start positions of two tags to find which is further up + return begin < rhs.begin; } //---------------------------------------------------------------------------- -bool tag_s::operator> (const tag_s & rhs) const -{ - return begin > rhs.begin; +bool tag_s::operator> (const tag_s & rhs) const { + return begin > rhs.begin; } //---------------------------------------------------------------------------- -bool tag_s::operator== (const tag_s & rhs) const -{ - return (rhs.begin == begin); +bool tag_s::operator== (const tag_s & rhs) const { + return (rhs.begin == begin); } //---------------------------------------------------------------------------- -un_predicate_count_tag_type::un_predicate_count_tag_type(const tag_type_s & arg) -{ - tag_type = arg; +un_predicate_count_tag_type::un_predicate_count_tag_type(const tag_type_s & arg) { + tag_type = arg; } //---------------------------------------------------------------------------- -bool un_predicate_count_tag_type::operator()(const tag_s & arg_tag) -{ - return (arg_tag.Get_Tag_Type() == tag_type); +bool un_predicate_count_tag_type::operator()(const tag_s & arg_tag) { + return (arg_tag.Get_Tag_Type() == tag_type); } //---------------------------------------------------------------------------- // block object //---------------------------------------------------------------------------- -block_s::block_s(const tag_s & arg_open) -{ - b_deleted = false; - Set_Open_Tag( arg_open ); +block_s::block_s(const tag_s & arg_open) { + b_deleted = false; + Set_Open_Tag( arg_open ); } //---------------------------------------------------------------------------- -void block_s::Set_Open_Tag(const tag_s & arg) -{ - tag_open = arg; - block_type = arg.Get_Tag_Type(); +void block_s::Set_Open_Tag(const tag_s & arg) { + tag_open = arg; + block_type = arg.Get_Tag_Type(); } //---------------------------------------------------------------------------- -block_s::block_s() -{ - b_deleted = false; +block_s::block_s() { + b_deleted = false; } //---------------------------------------------------------------------------- void block_s::Shift(const ptrdiff_t i_offset, const size_t ui_start, - const size_t ui_end) -{ - // do nothing if the block is no longer in the set - if ( Deleted() == true ) return; - - // store all tags in a container, for easy iteration - vector <tag_s*> tags_c; - tags_c.push_back(&tag_open); - tags_c.push_back(&tag_split); - tags_c.push_back(&tag_close); + const size_t ui_end) { + // do nothing if the block is no longer in the set + if ( Deleted() == true ) return; - for ( size_t n=0; n < tags_c.size(); n++ ) - { - /*not const*/ tag_s* itr_tag = tags_c[n]; + // store all tags in a container, for easy iteration + vector <tag_s*> tags_c; + tags_c.push_back(&tag_open); + tags_c.push_back(&tag_split); + tags_c.push_back(&tag_close); - // do nothing if the tag is above the start position or below the end - // posisiton - if ( itr_tag->Start() < ui_start || itr_tag->Stop() > ui_end ) - { - continue; - } + for ( size_t n=0; n < tags_c.size(); n++ ) { + /*not const*/ tag_s* itr_tag = tags_c[n]; - itr_tag->Shift(i_offset); + // do nothing if the tag is above the start position or below the end + // posisiton + if ( itr_tag->Start() < ui_start || itr_tag->Stop() > ui_end ) { + continue; + } + + itr_tag->Shift(i_offset); } } //---------------------------------------------------------------------------- -bool block_s::Contains(const block_s & rhs) const -{ - // if this is a block with no terminating tag, it can't contain anything - if ( this->Get_Type().b_block_tag == false ) - { - return false; - } - - return (rhs.Get_Open_Tag() > this->Get_Open_Tag() && - rhs.Get_Close_Tag() < this->Get_Close_Tag()); +bool block_s::Contains(const block_s & rhs) const { + // if this is a block with no terminating tag, it can't contain anything + if ( this->Get_Type().b_block_tag == false ) { + return false; + } + + return (rhs.Get_Open_Tag() > this->Get_Open_Tag() && + rhs.Get_Close_Tag() < this->Get_Close_Tag()); } //---------------------------------------------------------------------------- -bool block_s::operator== (const tag_s & rhs) const -{ - return (rhs.Start() == tag_open.Start() - || rhs.Start() == tag_close.Start() - || rhs.Start() == tag_split.Start()); +bool block_s::operator== (const tag_s & rhs) const { + return (rhs.Start() == tag_open.Start() + || rhs.Start() == tag_close.Start() + || rhs.Start() == tag_split.Start()); } //---------------------------------------------------------------------------- -bool block_s::operator!= (const tag_s & rhs) const -{ - return !(*this == rhs); +bool block_s::operator!= (const tag_s & rhs) const { + return !(*this == rhs); } //---------------------------------------------------------------------------- -bool block_s::operator== (const block_s & rhs) const -{ - return (rhs.tag_open == tag_open); +bool block_s::operator== (const block_s & rhs) const { + return (rhs.tag_open == tag_open); } //---------------------------------------------------------------------------- -bool block_s::operator!= (const block_s & rhs) const -{ - return !(*this == rhs); +bool block_s::operator!= (const block_s & rhs) const { + return !(*this == rhs); } //---------------------------------------------------------------------------- -bool block_s::operator> (const block_s & rhs) const -{ - // block is greater than another block if the start of the block is after the - // close of another block - return (tag_open > rhs.tag_close); +bool block_s::operator> (const block_s & rhs) const { + // block is greater than another block if the start of the block is after the + // close of another block + return (tag_open > rhs.tag_close); } //---------------------------------------------------------------------------- -un_predicate_count_tag::un_predicate_count_tag(const tag_s & arg) -{ - tag = arg; +un_predicate_count_tag::un_predicate_count_tag(const tag_s & arg) { + tag = arg; } //---------------------------------------------------------------------------- -bool un_predicate_count_tag::operator()(const block_s & arg_block) -{ - return (arg_block == tag); +bool un_predicate_count_tag::operator()(const block_s & arg_block) { + return (arg_block == tag); } //---------------------------------------------------------------------------- // template class public //---------------------------------------------------------------------------- -html_template::html_template() -{ - tag_type_prefix = "TMPL_"; - init(); +html_template::html_template() { + tag_type_prefix = "TMPL_"; + init(); } //---------------------------------------------------------------------------- -html_template::html_template(const std::string & arg_file_name) -{ - tag_type_prefix = "TMPL_"; - init(); - Set_Template_File(arg_file_name); +html_template::html_template(const std::string & arg_file_name) { + tag_type_prefix = "TMPL_"; + init(); + Set_Template_File(arg_file_name); } //---------------------------------------------------------------------------- -void html_template::Set_Template_File(const std::string arg_file_name) -{ - str_tmpl_file_name = arg_file_name; +void html_template::Set_Template_File(const std::string arg_file_name) { + str_tmpl_file_name = arg_file_name; - if (arg_file_name.empty()) - { - throw("Template file name not specified"); - } + if (arg_file_name.empty()) { + throw("Template file name not specified"); + } #ifdef DEBUG - cout << "\n!!!!!!!!!!!!!!!\ntemplate " << str_tmpl_file_name << " loaded" << endl; + cout << "\n!!!!!!!!!!!!!!!\ntemplate " << str_tmpl_file_name << " loaded" << endl; #endif } //---------------------------------------------------------------------------- -const std::string & html_template::Process() -{ - std::ifstream in_stream; - in_stream.open( str_tmpl_file_name.c_str(), ios::binary ); - - if( !in_stream.is_open() ) - { - runtime_ex ex("Could not open template file"); - throw_exception(ex); - } +const std::string & html_template::Process() { + std::ifstream in_stream; + in_stream.open( str_tmpl_file_name.c_str(), ios::binary ); - // read in the file - std::stringstream oss; - oss << in_stream.rdbuf(); - str_tmpl_txt = oss.str(); - in_stream.close(); - - // this will expand the include files, and build the map of all the variables - - // once if there are no includes or (1 + # of includes) - expand_includes(); + if( !in_stream.is_open() ) { + runtime_ex ex("Could not open template file"); + throw_exception(ex); + } - str_tmpl_txt_cpy = str_tmpl_txt; + // read in the file + std::stringstream oss; + oss << in_stream.rdbuf(); + str_tmpl_txt = oss.str(); + in_stream.close(); + // this will expand the include files, and build the map of all the variables - + // once if there are no includes or (1 + # of includes) + expand_includes(); + + str_tmpl_txt_cpy = str_tmpl_txt; + #ifdef DEBUG - print_block_map(block_map); + print_block_map(block_map); #endif - // tag iterator - tag_map_t::const_iterator itr_tag; + // tag iterator + tag_map_t::const_iterator itr_tag; - // check that every tag is part of a block - for ( itr_tag = tag_map.begin(); itr_tag != tag_map.end(); ++itr_tag ) - { - block_map_t::const_iterator itr_block - = find(block_map.begin(), block_map.end(), *itr_tag); + // check that every tag is part of a block + for ( itr_tag = tag_map.begin(); itr_tag != tag_map.end(); ++itr_tag ) { + block_map_t::const_iterator itr_block + = find(block_map.begin(), block_map.end(), *itr_tag); - if ( itr_block == block_map.end() ) - { - syntax_ex error("Unmatched tag"); - error.line = get_line_from_pos(itr_tag->Start()); - error.detail = "Unmatched '" - + itr_tag->Get_Tag_Type().str_tag_type - + "' tag"; - throw_exception(error); - } - } - + if ( itr_block == block_map.end() ) { + syntax_ex error("Unmatched tag"); + error.line = get_line_from_pos(itr_tag->Start()); + error.detail = "Unmatched '" + + itr_tag->Get_Tag_Type().str_tag_type + + "' tag"; + throw_exception(error); + } + } + #ifdef DEBUG - // - // assert that every tag appears only once in each block - // - for ( itr_tag = tag_map.begin(); itr_tag != tag_map.end(); ++itr_tag ) - { - un_predicate_count_tag predicate(*itr_tag); - - const size_t ui_occurances - = std::count_if(block_map.begin(), block_map.end(), predicate); + // + // assert that every tag appears only once in each block + // + for ( itr_tag = tag_map.begin(); itr_tag != tag_map.end(); ++itr_tag ) { + un_predicate_count_tag predicate(*itr_tag); - assert(ui_occurances == 1 && "Each tag must appear in a block only ONCE"); - } + const size_t ui_occurances + = std::count_if(block_map.begin(), block_map.end(), predicate); + assert(ui_occurances == 1 && "Each tag must appear in a block only ONCE"); + } + #endif - - //************************************************************************** - //************************************************************************** - // - // start variable substitution - // - // process IF blocks first to take out unwanted data right away - process_conditionals(block_map, str_tmpl_txt_cpy, variables_c); + //************************************************************************** + //************************************************************************** + // + // start variable substitution + // - // process loops - process_loops(block_map, str_tmpl_txt_cpy, variables_c); + // process IF blocks first to take out unwanted data right away + process_conditionals(block_map, str_tmpl_txt_cpy, variables_c); - // - // process simple variables - // - process_simple_vars(block_map, str_tmpl_txt_cpy, variables_c); - - // - // end variable substitution - // - //************************************************************************** - //************************************************************************** + // process loops + process_loops(block_map, str_tmpl_txt_cpy, variables_c); - return str_tmpl_txt_cpy; + // + // process simple variables + // + process_simple_vars(block_map, str_tmpl_txt_cpy, variables_c); + + // + // end variable substitution + // + //************************************************************************** + //************************************************************************** + + return str_tmpl_txt_cpy; } //---------------------------------------------------------------------------- -void html_template::print_block_map(block_map_t & r_block_map) -{ - // block iterator - block_map_t::const_iterator itr_block = r_block_map.begin(); +void html_template::print_block_map(block_map_t & r_block_map) { + // block iterator + block_map_t::const_iterator itr_block = r_block_map.begin(); - cout << "\n*************************************************" - << "\nBLOCK MAP" - << "\n*************************************************\n"; + cout << "\n*************************************************" + << "\nBLOCK MAP" + << "\n*************************************************\n"; - for ( ; itr_block != r_block_map.end(); ++itr_block) - { - cout << itr_block->Get_Type().str_tag_class - << "\t"<< itr_block->Get_Name(); + for ( ; itr_block != r_block_map.end(); ++itr_block) { + cout << itr_block->Get_Type().str_tag_class + << "\t"<< itr_block->Get_Name(); - if ( itr_block->Deleted() ) - cout << " [DELETED]"; + if ( itr_block->Deleted() ) + cout << " [DELETED]"; - cout << "\nOpen\tL " << get_line_from_pos(itr_block->Get_Open_Tag().Start()) - << " (" << itr_block->Get_Open_Tag().Start() - << ", " << itr_block->Get_Open_Tag().Stop() << ")"; + cout << "\nOpen\tL " << get_line_from_pos(itr_block->Get_Open_Tag().Start()) + << " (" << itr_block->Get_Open_Tag().Start() + << ", " << itr_block->Get_Open_Tag().Stop() << ")"; - if ( itr_block->Get_Split_Tag().Start() != string::npos ) - cout << "\nSplit\tL " - << get_line_from_pos(itr_block->Get_Split_Tag().Start()) - << " (" << itr_block->Get_Split_Tag().Start() - << ", " << itr_block->Get_Split_Tag().Stop() << ")"; + if ( itr_block->Get_Split_Tag().Start() != string::npos ) + cout << "\nSplit\tL " + << get_line_from_pos(itr_block->Get_Split_Tag().Start()) + << " (" << itr_block->Get_Split_Tag().Start() + << ", " << itr_block->Get_Split_Tag().Stop() << ")"; - if ( itr_block->Get_Close_Tag().Start() != string::npos ) - cout << "\nClose\tL " - << get_line_from_pos(itr_block->Get_Close_Tag().Start()) - << " (" << itr_block->Get_Close_Tag().Start() - << ", " << itr_block->Get_Close_Tag().Stop() << ")"; + if ( itr_block->Get_Close_Tag().Start() != string::npos ) + cout << "\nClose\tL " + << get_line_from_pos(itr_block->Get_Close_Tag().Start()) + << " (" << itr_block->Get_Close_Tag().Start() + << ", " << itr_block->Get_Close_Tag().Stop() << ")"; - cout << "\n-------------\n"; - } + cout << "\n-------------\n"; + } } //---------------------------------------------------------------------------- -void html_template::print_tag_map() -{ - //! - //! NOTE - the tag map is used to create the block map. After the block map - //! is created, the tag map is no longer used for anything - you can't debug - //! tag shifting with it. Use the block map for that. - //! +void html_template::print_tag_map() { +//! +//! NOTE - the tag map is used to create the block map. After the block map +//! is created, the tag map is no longer used for anything - you can't debug +//! tag shifting with it. Use the block map for that. +//! - // tag iterator - tag_map_t::const_iterator itr_tag; + // tag iterator + tag_map_t::const_iterator itr_tag; - cout << "\n*************************************************" - << "\nTAG MAP" - << "\n*************************************************\n"; + cout << "\n*************************************************" + << "\nTAG MAP" + << "\n*************************************************\n"; - for ( itr_tag = tag_map.begin(); itr_tag != tag_map.end(); ++itr_tag ) - { - cout << "L " << get_line_from_pos(itr_tag->Start()) << "\t"; - - if ( itr_tag->Is_Termination() ) - cout << "</"; - else - cout << "<"; + for ( itr_tag = tag_map.begin(); itr_tag != tag_map.end(); ++itr_tag ) { + cout << "L " << get_line_from_pos(itr_tag->Start()) << "\t"; - cout << itr_tag->Get_Tag_Type().str_tag_type << ">"; + if ( itr_tag->Is_Termination() ) + cout << "</"; + else + cout << "<"; - if ( itr_tag->Is_Named() ) - cout << "\t= "; - - cout << itr_tag->Get_Name() - << " (" << itr_tag->Start() << ", " << itr_tag->Stop() << ")" - << endl; - } + cout << itr_tag->Get_Tag_Type().str_tag_type << ">"; + + if ( itr_tag->Is_Named() ) + cout << "\t= "; + + cout << itr_tag->Get_Name() + << " (" << itr_tag->Start() << ", " << itr_tag->Stop() << ")" + << endl; + } } //---------------------------------------------------------------------------- -html_template::~html_template() -{ +html_template::~html_template() { #ifdef DEBUG - cout << "template " << str_tmpl_file_name << " destroyed" << endl; + cout << "template " << str_tmpl_file_name << " destroyed" << endl; #endif } //---------------------------------------------------------------------------- -cls_variable & html_template::operator() (const std::string arg_var_name) -{ - string arg_var_name_uc = arg_var_name; - // uppercase - uc(arg_var_name_uc); +cls_variable & html_template::operator() (const std::string arg_var_name) { + string arg_var_name_uc = arg_var_name; + // uppercase + uc(arg_var_name_uc); - // create variable - cls_variable var(arg_var_name_uc); + // create variable + cls_variable var(arg_var_name_uc); - // save it - variables_c[arg_var_name_uc] = var; - + // save it + variables_c[arg_var_name_uc] = var; + #ifdef DEBUG3 - cout << "creating variable '" << arg_var_name_uc << "'" << endl; + cout << "creating variable '" << arg_var_name_uc << "'" << endl; #endif - // return the variable so a value can be assigned to it - return variables_c[arg_var_name_uc]; + // return the variable so a value can be assigned to it + return variables_c[arg_var_name_uc]; } //---------------------------------------------------------------------------- -const size_t -html_template::Get_Tag_Type_Count(const tag_type_s & tag_type) const -{ - un_predicate_count_tag_type predicate(tag_type); +const size_t +html_template::Get_Tag_Type_Count(const tag_type_s & tag_type) const { + un_predicate_count_tag_type predicate(tag_type); - const size_t ui_count = std::count_if( - tag_map.begin(), tag_map.end(), predicate - ); + const size_t ui_count = std::count_if( + tag_map.begin(), tag_map.end(), predicate + ); - return ui_count; + return ui_count; } //---------------------------------------------------------------------------- // template class private //---------------------------------------------------------------------------- -void html_template::init() -{ - // - // declare all known tag types - // - // the last boolean flag defines if the tag is a block (has open and close - // tags) - tag_types_c["SIMPLE"] = tag_type_s("VAR", "VAR"); - tag_types_c["LOOP"] = tag_type_s("LOOP", "LOOP", true); - tag_types_c["IF"] = tag_type_s("IF", "IF", true); - tag_types_c["ELSE"] = tag_type_s("ELSE", "IF"); - tag_types_c["UNLESS"] = tag_type_s("UNLESS", "IF", true); - tag_types_c["INCLUDE"] = tag_type_s("INCLUDE", "INCLUDE"); +void html_template::init() { + // + // declare all known tag types + // + // the last boolean flag defines if the tag is a block (has open and close + // tags) + tag_types_c["SIMPLE"] = tag_type_s("VAR", "VAR"); + tag_types_c["LOOP"] = tag_type_s("LOOP", "LOOP", true); + tag_types_c["IF"] = tag_type_s("IF", "IF", true); + tag_types_c["ELSE"] = tag_type_s("ELSE", "IF"); + tag_types_c["UNLESS"] = tag_type_s("UNLESS", "IF", true); + tag_types_c["INCLUDE"] = tag_type_s("INCLUDE", "INCLUDE"); - // create the tag strings we expect to see in a document, based on the tag - // types - tag_types_t::const_iterator itr_tag_type = tag_types_c.begin(); - - for ( ; itr_tag_type != tag_types_c.end(); ++itr_tag_type ) - { - tag_type_s tag_type = itr_tag_type->second; - string str_tag_type_ref = tag_type_prefix + tag_type.str_tag_type; - // save - tag_strings_c[ str_tag_type_ref ] = 1; - } - - // populate reserved words container (helps us during parsing) - reserved_words_c[ "ESCAPE" ] = 1; - reserved_words_c[ "ESC" ] = 1; - reserved_words_c[ "HTML" ] = 1; - reserved_words_c[ "JS" ] = 1; - reserved_words_c[ "JAVASCRIPT" ] = 1; - reserved_words_c[ "URL" ] = 1; - reserved_words_c[ "XML" ] = 1; + // create the tag strings we expect to see in a document, based on the tag + // types + tag_types_t::const_iterator itr_tag_type = tag_types_c.begin(); + + for ( ; itr_tag_type != tag_types_c.end(); ++itr_tag_type ) { + tag_type_s tag_type = itr_tag_type->second; + string str_tag_type_ref = tag_type_prefix + tag_type.str_tag_type; + // save + tag_strings_c[ str_tag_type_ref ] = 1; + } + + // populate reserved words container (helps us during parsing) + reserved_words_c[ "ESCAPE" ] = 1; + reserved_words_c[ "ESC" ] = 1; + reserved_words_c[ "HTML" ] = 1; + reserved_words_c[ "JS" ] = 1; + reserved_words_c[ "JAVASCRIPT" ] = 1; + reserved_words_c[ "URL" ] = 1; + reserved_words_c[ "XML" ] = 1; } //---------------------------------------------------------------------------- -void html_template::expand_includes() -{ - build_block_map(); +void html_template::expand_includes() { + build_block_map(); - // block iterator - block_map_t::const_iterator itr_block; + // block iterator + block_map_t::const_iterator itr_block; - itr_block = block_map.begin(); + itr_block = block_map.begin(); - unsigned short ush_processed_includes = 0; + unsigned short ush_processed_includes = 0; - for (; itr_block != block_map.end(); ++itr_block) - { - if ( itr_block->Get_Type() != tag_types_c["INCLUDE"] ) continue; - if ( itr_block->Deleted() ) continue; + for (; itr_block != block_map.end(); ++itr_block) { + if ( itr_block->Get_Type() != tag_types_c["INCLUDE"] ) continue; - // increment count - ++ush_processed_includes; - - // read in the file contents - string str_file_name = itr_block->Get_Name(); + if ( itr_block->Deleted() ) continue; - - // the file may have either absolute or relative path. If relative, combine - // it with the path of the parent file - if ( str_file_name.find_first_of("\\/", 0, 1) == string::npos ) - { - // this file is relative to main template location - - // get the main template dir - const string str_parent_tmpl_dir = file_directory( str_tmpl_file_name ); + // increment count + ++ush_processed_includes; - str_file_name = str_parent_tmpl_dir + str_file_name; - } - - std::ifstream in_stream; - in_stream.open( str_file_name.c_str() ); + // read in the file contents + string str_file_name = itr_block->Get_Name(); - if( !in_stream.is_open() ) - { - runtime_ex ex("Could not open file for reading"); - throw_exception(ex); - } - // read in the file - std::stringstream oss; - oss << in_stream.rdbuf(); - const string str_replace_with = oss.str(); + // the file may have either absolute or relative path. If relative, combine + // it with the path of the parent file + if ( str_file_name.find_first_of("\\/", 0, 1) == string::npos ) { + // this file is relative to main template location - in_stream.close(); + // get the main template dir + const string str_parent_tmpl_dir = file_directory( str_tmpl_file_name ); - const size_t block_len = itr_block->Get_Open_Tag().Stop() - - itr_block->Get_Open_Tag().Start() - + 1; + str_file_name = str_parent_tmpl_dir + str_file_name; + } - const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); + std::ifstream in_stream; + in_stream.open( str_file_name.c_str() ); - // shift tags in rest of document - - shift_tags( - str_tmpl_txt, block_map, i_offset, - itr_block->Get_Open_Tag().Stop() - ); + if( !in_stream.is_open() ) { + runtime_ex ex("Could not open file for reading"); + throw_exception(ex); + } - str_tmpl_txt.replace( - itr_block->Get_Open_Tag().Start(), - block_len, - str_replace_with - ); - } - - // recurse if any tags were processed - if ( ush_processed_includes ) - { - expand_includes(); // RECURSION - } + // read in the file + std::stringstream oss; + oss << in_stream.rdbuf(); + const string str_replace_with = oss.str(); - // no need to build the map again - if there was at least one include, the - // map would be rebuilt by the recursive call + in_stream.close(); + + const size_t block_len = itr_block->Get_Open_Tag().Stop() + - itr_block->Get_Open_Tag().Start() + + 1; + + const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); + + // shift tags in rest of document + + shift_tags( + str_tmpl_txt, block_map, i_offset, + itr_block->Get_Open_Tag().Stop() + ); + + str_tmpl_txt.replace( + itr_block->Get_Open_Tag().Start(), + block_len, + str_replace_with + ); + } + + // recurse if any tags were processed + if ( ush_processed_includes ) { + expand_includes(); // RECURSION + } + + // no need to build the map again - if there was at least one include, the + // map would be rebuilt by the recursive call } //---------------------------------------------------------------------------- -void html_template::process_conditionals(block_map_t & r_block_map, - std::string & str_text, - variables_t & r_variables_c) -{ - // block iterator - block_map_t::iterator itr_block = r_block_map.begin(); +void html_template::process_conditionals(block_map_t & r_block_map, + std::string & str_text, + variables_t & r_variables_c) { + // block iterator + block_map_t::iterator itr_block = r_block_map.begin(); - for (; itr_block != r_block_map.end(); ++itr_block) - { - if ( itr_block->Get_Type() != tag_types_c["IF"] ) continue; - if ( itr_block->Deleted() ) continue; + for (; itr_block != r_block_map.end(); ++itr_block) { + if ( itr_block->Get_Type() != tag_types_c["IF"] ) continue; - // ignore this conditional if it's within a loop scope (defined inside the - // given block map - block_map_t::const_iterator itr_block_2 = r_block_map.begin(); - bool b_this_scope = true; + if ( itr_block->Deleted() ) continue; - for (; itr_block_2 != r_block_map.end(); ++itr_block_2) - { - if ( itr_block_2->Get_Type() == tag_types_c["LOOP"] ) - { - if ( itr_block_2->Contains(*itr_block) ) - { - b_this_scope = false; - break;; - } - } - } + // ignore this conditional if it's within a loop scope (defined inside the + // given block map + block_map_t::const_iterator itr_block_2 = r_block_map.begin(); + bool b_this_scope = true; - if ( !b_this_scope ) continue; - + for (; itr_block_2 != r_block_map.end(); ++itr_block_2) { + if ( itr_block_2->Get_Type() == tag_types_c["LOOP"] ) { + if ( itr_block_2->Contains(*itr_block) ) { + b_this_scope = false; + break;; + } + } + } + + if ( !b_this_scope ) continue; + #ifdef DEBUG2 - cout << "processing conditional " << itr_block->Get_Name() << endl; + cout << "processing conditional " << itr_block->Get_Name() << endl; #endif - size_t replace_len = 0; - size_t replace_with_begin = 0; - size_t replace_with_end = 0; - size_t block_len = 0; - string str_replace_with = ""; - bool b_eval_as_true = false; + size_t replace_len = 0; + size_t replace_with_begin = 0; + size_t replace_with_end = 0; + size_t block_len = 0; + string str_replace_with = ""; + bool b_eval_as_true = false; - // part of an IF block may be deleted. In that case, there are two tags - // between each other tags will need to be deleted as well - tag_s delete_btwn_tag_begin; - tag_s delete_btwn_tag_end; + // part of an IF block may be deleted. In that case, there are two tags + // between each other tags will need to be deleted as well + tag_s delete_btwn_tag_begin; + tag_s delete_btwn_tag_end; - // space between these tags will be the offset to shift other tags by - tag_s shift_offset_tag_begin; - tag_s shift_offset_tag_end; + // space between these tags will be the offset to shift other tags by + tag_s shift_offset_tag_begin; + tag_s shift_offset_tag_end; - // these define the block where tag shifting will occur - tag_s shift_tag_from; - tag_s shift_tag_until; - - // if variable for this IF found, evaluate - variables_t::iterator itr_var; - itr_var = r_variables_c.find( itr_block->Get_Name() ); + // these define the block where tag shifting will occur + tag_s shift_tag_from; + tag_s shift_tag_until; - if ( itr_var != r_variables_c.end() ) - { - cls_variable & r_var = itr_var->second; + // if variable for this IF found, evaluate + variables_t::iterator itr_var; + itr_var = r_variables_c.find( itr_block->Get_Name() ); - // evaluate the IF - b_eval_as_true = evaluate(r_var); + if ( itr_var != r_variables_c.end() ) { + cls_variable & r_var = itr_var->second; - // if this is an UNLESS, flip the evaluation result - if ( itr_block->Get_Type().str_tag_type == "UNLESS" ) - { - b_eval_as_true = (b_eval_as_true == false) ? true : false; - } - } - else - { - // if this is an unless, the absent variable should eval to TRUE - if ( itr_block->Get_Type().str_tag_type == "UNLESS" ) - { - b_eval_as_true = true; - } - } + // evaluate the IF + b_eval_as_true = evaluate(r_var); - // determine what we are replacing the IF with - - // if this is a two part block - if ( itr_block->Has_Split_Tag() ) - { - // replace with first part of statement if true - if ( b_eval_as_true) - { - // replace the whole if with what's between the IF and the ELSE - replace_with_begin = itr_block->Get_Open_Tag().Stop(); - replace_with_end = itr_block->Get_Split_Tag().Start(); - - // delete between the ELSE and the /IF - delete_btwn_tag_begin = itr_block->Get_Split_Tag(); - delete_btwn_tag_end = itr_block->Get_Close_Tag(); - - shift_offset_tag_begin = itr_block->Get_Open_Tag(); - shift_offset_tag_end = itr_block->Get_Open_Tag(); - shift_tag_from = itr_block->Get_Open_Tag(); - shift_tag_until = itr_block->Get_Split_Tag(); - } - else // replace with second part if false - { - // replace the whole IF with what's between the ELSE and the /IF - replace_with_begin = itr_block->Get_Split_Tag().Stop(); - replace_with_end = itr_block->Get_Close_Tag().Start(); - - // delete between the IF and the ELSE - delete_btwn_tag_begin = itr_block->Get_Open_Tag(); - delete_btwn_tag_end = itr_block->Get_Split_Tag(); + // if this is an UNLESS, flip the evaluation result + if ( itr_block->Get_Type().str_tag_type == "UNLESS" ) { + b_eval_as_true = (b_eval_as_true == false) ? true : false; + } + } else { + // if this is an unless, the absent variable should eval to TRUE + if ( itr_block->Get_Type().str_tag_type == "UNLESS" ) { + b_eval_as_true = true; + } + } - shift_offset_tag_begin = itr_block->Get_Open_Tag(); - shift_offset_tag_end = itr_block->Get_Split_Tag(); - shift_tag_from = itr_block->Get_Split_Tag(); - shift_tag_until = itr_block->Get_Close_Tag(); - } - - } - else //one part IF block - it either stays or goes - { - // replacing with whatever's in the whole IF, when the statements - // evaluates to TRUE - replace_with_begin = itr_block->Get_Open_Tag().Stop(); - replace_with_end = itr_block->Get_Close_Tag().Start(); - - shift_offset_tag_begin = itr_block->Get_Open_Tag(); - shift_offset_tag_end = itr_block->Get_Open_Tag(); - shift_tag_from = itr_block->Get_Open_Tag(); - shift_tag_until = itr_block->Get_Close_Tag(); + // determine what we are replacing the IF with - // if this evaluates to FALSE, define range in which all other tags - // will be nuked, and no longer expanded by future operations - if (!b_eval_as_true) - { - delete_btwn_tag_begin = itr_block->Get_Open_Tag(); - delete_btwn_tag_end = itr_block->Get_Close_Tag(); - } - } + // if this is a two part block + if ( itr_block->Has_Split_Tag() ) { + // replace with first part of statement if true + if ( b_eval_as_true) { + // replace the whole if with what's between the IF and the ELSE + replace_with_begin = itr_block->Get_Open_Tag().Stop(); + replace_with_end = itr_block->Get_Split_Tag().Start(); - // length of test that will replace the IF - replace_len = replace_with_end - replace_with_begin - 1; + // delete between the ELSE and the /IF + delete_btwn_tag_begin = itr_block->Get_Split_Tag(); + delete_btwn_tag_end = itr_block->Get_Close_Tag(); - // get the actual text to replace the IF with - str_replace_with = str_text.substr(replace_with_begin + 1, - replace_len); - - // length of the IF block - block_len = itr_block->Get_Close_Tag().Stop() - - itr_block->Get_Open_Tag().Start() - + 1; + shift_offset_tag_begin = itr_block->Get_Open_Tag(); + shift_offset_tag_end = itr_block->Get_Open_Tag(); + shift_tag_from = itr_block->Get_Open_Tag(); + shift_tag_until = itr_block->Get_Split_Tag(); + } else { // replace with second part if false + // replace the whole IF with what's between the ELSE and the /IF + replace_with_begin = itr_block->Get_Split_Tag().Stop(); + replace_with_end = itr_block->Get_Close_Tag().Start(); - // delete all blocks in IF part that will go away, if that part is defined - if ( delete_btwn_tag_begin.Empty() == false ) - { - delete_blocks(delete_btwn_tag_begin, delete_btwn_tag_end, r_block_map); - } + // delete between the IF and the ELSE + delete_btwn_tag_begin = itr_block->Get_Open_Tag(); + delete_btwn_tag_end = itr_block->Get_Split_Tag(); - // shift tags inside the IF - shift_tags( - // subject text - str_text, - // the block map - r_block_map, - // shift size - (shift_offset_tag_end.Stop() - shift_offset_tag_begin.Start() + 1) * -1, - // shift range start - shift_tag_from.Stop(), - // shift range end - shift_tag_until.Start() - ); + shift_offset_tag_begin = itr_block->Get_Open_Tag(); + shift_offset_tag_end = itr_block->Get_Split_Tag(); + shift_tag_from = itr_block->Get_Split_Tag(); + shift_tag_until = itr_block->Get_Close_Tag(); + } - if ( itr_block->Has_Split_Tag() ) - { - // shift tags in rest of document - const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); + } else { //one part IF block - it either stays or goes + // replacing with whatever's in the whole IF, when the statements + // evaluates to TRUE + replace_with_begin = itr_block->Get_Open_Tag().Stop(); + replace_with_end = itr_block->Get_Close_Tag().Start(); - shift_tags( - str_text, - r_block_map, - i_offset, - shift_tag_until.Stop() - ); + shift_offset_tag_begin = itr_block->Get_Open_Tag(); + shift_offset_tag_end = itr_block->Get_Open_Tag(); + shift_tag_from = itr_block->Get_Open_Tag(); + shift_tag_until = itr_block->Get_Close_Tag(); - str_text.replace( - itr_block->Get_Open_Tag().Start(), - block_len, - str_replace_with - ); - } - else // process the whole IF - { - if (!b_eval_as_true) - { - str_replace_with.clear(); - } + // if this evaluates to FALSE, define range in which all other tags + // will be nuked, and no longer expanded by future operations + if (!b_eval_as_true) { + delete_btwn_tag_begin = itr_block->Get_Open_Tag(); + delete_btwn_tag_end = itr_block->Get_Close_Tag(); + } + } - const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); - - // shift tags in rest of document - shift_tags( - str_text, - r_block_map, - i_offset, - itr_block->Get_Close_Tag().Start() - ); + // length of test that will replace the IF + replace_len = replace_with_end - replace_with_begin - 1; - str_text.replace( - itr_block->Get_Open_Tag().Start(), - block_len, - str_replace_with - ); - } + // get the actual text to replace the IF with + str_replace_with = str_text.substr(replace_with_begin + 1, + replace_len); - itr_block->Delete(); - } + // length of the IF block + block_len = itr_block->Get_Close_Tag().Stop() + - itr_block->Get_Open_Tag().Start() + + 1; + // delete all blocks in IF part that will go away, if that part is defined + if ( delete_btwn_tag_begin.Empty() == false ) { + delete_blocks(delete_btwn_tag_begin, delete_btwn_tag_end, r_block_map); + } + + // shift tags inside the IF + shift_tags( + // subject text + str_text, + // the block map + r_block_map, + // shift size + (shift_offset_tag_end.Stop() - shift_offset_tag_begin.Start() + 1) * -1, + // shift range start + shift_tag_from.Stop(), + // shift range end + shift_tag_until.Start() + ); + + if ( itr_block->Has_Split_Tag() ) { + // shift tags in rest of document + const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); + + shift_tags( + str_text, + r_block_map, + i_offset, + shift_tag_until.Stop() + ); + + str_text.replace( + itr_block->Get_Open_Tag().Start(), + block_len, + str_replace_with + ); + } else { // process the whole IF + if (!b_eval_as_true) { + str_replace_with.clear(); + } + + const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); + + // shift tags in rest of document + shift_tags( + str_text, + r_block_map, + i_offset, + itr_block->Get_Close_Tag().Start() + ); + + str_text.replace( + itr_block->Get_Open_Tag().Start(), + block_len, + str_replace_with + ); + } + + itr_block->Delete(); + } + } //---------------------------------------------------------------------------- -void html_template::process_simple_vars(block_map_t & r_block_map, +void html_template::process_simple_vars(block_map_t & r_block_map, std::string & str_text, - html_template::variables_t & r_variables_c) -{ - block_map_t::iterator itr_block = r_block_map.begin(); + html_template::variables_t & r_variables_c) { + block_map_t::iterator itr_block = r_block_map.begin(); - for (; itr_block != r_block_map.end(); ++itr_block) - { - if ( itr_block->Get_Type() != tag_types_c["SIMPLE"] ) continue; - if ( itr_block->Deleted() ) continue; + for (; itr_block != r_block_map.end(); ++itr_block) { + if ( itr_block->Get_Type() != tag_types_c["SIMPLE"] ) continue; + if ( itr_block->Deleted() ) continue; + #ifdef DEBUG2 - cout << "processing variable " << itr_block->Get_Name() << endl; + cout << "processing variable " << itr_block->Get_Name() << endl; #endif - - string str_replace_with = ""; - // find the variable of this name - variables_t::iterator pos_var; - pos_var = r_variables_c.find(itr_block->Get_Name()); - cls_variable* p_var = 0; + string str_replace_with = ""; - pos_var = r_variables_c.find(itr_block->Get_Name()); + // find the variable of this name + variables_t::iterator pos_var; + pos_var = r_variables_c.find(itr_block->Get_Name()); + cls_variable* p_var = 0; - if ( pos_var != r_variables_c.end() ) - { - p_var = &(pos_var->second); - str_replace_with = p_var->Get_Val_String(); - escape_var( str_replace_with, itr_block->Get_Escape_Mode() ); - } + pos_var = r_variables_c.find(itr_block->Get_Name()); - const size_t block_len = itr_block->Get_Open_Tag().Stop() - - itr_block->Get_Open_Tag().Start() + 1; + if ( pos_var != r_variables_c.end() ) { + p_var = &(pos_var->second); + str_replace_with = p_var->Get_Val_String(); + escape_var( str_replace_with, itr_block->Get_Escape_Mode() ); + } - const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); + const size_t block_len = itr_block->Get_Open_Tag().Stop() + - itr_block->Get_Open_Tag().Start() + 1; - shift_tags( - str_text, - r_block_map, - i_offset, - itr_block->Get_Open_Tag().Stop() - ); + const ptrdiff_t i_offset = get_offset(block_len, str_replace_with); - str_text.replace( - itr_block->Get_Open_Tag().Start(), - block_len, - str_replace_with - ); + shift_tags( + str_text, + r_block_map, + i_offset, + itr_block->Get_Open_Tag().Stop() + ); - itr_block->Delete(); - } + str_text.replace( + itr_block->Get_Open_Tag().Start(), + block_len, + str_replace_with + ); + + itr_block->Delete(); + } } //---------------------------------------------------------------------------- -void html_template::process_loops(block_map_t & r_block_map, +void html_template::process_loops(block_map_t & r_block_map, std::string & str_text, - variables_t & r_variables_c) -{ - block_map_t::iterator itr_block = r_block_map.begin(); + variables_t & r_variables_c) { + block_map_t::iterator itr_block = r_block_map.begin(); - for (; itr_block != r_block_map.end(); ++itr_block) - { - if ( itr_block->Get_Type() != tag_types_c["LOOP"] ) continue; - if ( itr_block->Deleted() ) continue; + for (; itr_block != r_block_map.end(); ++itr_block) { + if ( itr_block->Get_Type() != tag_types_c["LOOP"] ) continue; - process_loop( *itr_block, str_text, r_block_map, r_variables_c ); + if ( itr_block->Deleted() ) continue; - itr_block->Delete(); - } + process_loop( *itr_block, str_text, r_block_map, r_variables_c ); + + itr_block->Delete(); + } } //---------------------------------------------------------------------------- - + void html_template::process_loop(const block_s & block, std::string & str_text, block_map_t & r_block_map, - variables_t & r_variables_c) -{ + variables_t & r_variables_c) { #ifdef DEBUG - cout << "processing loop: "<< block.Get_Name() << endl; + cout << "processing loop: "<< block.Get_Name() << endl; #endif - // Get the table variable for this block. - variables_t::iterator itr_var = r_variables_c.find( block.Get_Name() ); - loop_s local_table; + // Get the table variable for this block. + variables_t::iterator itr_var = r_variables_c.find( block.Get_Name() ); + loop_s local_table; - itr_var = r_variables_c.find(block.Get_Name()); - - if ( itr_var != r_variables_c.end() ) - { - cls_variable & r_var = itr_var->second; - local_table = r_var.Get_Val_Table(); + itr_var = r_variables_c.find(block.Get_Name()); + + if ( itr_var != r_variables_c.end() ) { + cls_variable & r_var = itr_var->second; + local_table = r_var.Get_Val_Table(); } - const size_t block_start = block.Get_Open_Tag().Start(); - const size_t block_end = block.Get_Close_Tag().Stop(); - const size_t block_len = block_end - bl... [truncated message content] |