Loading src/html.cpp +17 −14 Original line number Diff line number Diff line Loading @@ -313,7 +313,6 @@ libhtmlpp::DocElements *libhtmlpp::HtmlString::_buildtreenode(DocElements* prev, return _buildtreenode(prev,next->nextel,next,end); } libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { DocElements *firstEl = nullptr, *lastEl = nullptr; Loading @@ -331,7 +330,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { for (size_t i = 0; i < _HTableSize; ++i) { if(_HTable[i][0] == -1 || _HTable[i][2] == -1) if(_HTable[i][0] == -1) continue; addelement(&firstEl,&lastEl); Loading @@ -347,7 +346,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos,std::insert_iterator<std::vector<char>>(tmp,tmp.begin())); _serialelize(tmp, (HtmlElement**) &lastEl->element); size_t epos=0; ssize_t epos=-1; for(size_t ii=i+1; ii<_HTableSize; ++ii){ if(_HTable[ii][0]>=0 && _HTable[ii][2]>=0){ Loading @@ -356,12 +355,15 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { } } if(epos < _HTableSize){ if(epos<0) continue; if(epos < (ssize_t)_HTableSize){ int tlen = (_HTable[epos][0]-_HTable[i][2]); if(tlen>1){ addelement(&firstEl,&lastEl); lastEl->element=new TextElement(); lastEl->spos = _HTable[i][2]; lastEl->spos = _HTable[i][2]+1; lastEl->epos = _HTable[epos][0]; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos,std::insert_iterator<std::vector<char>> (((TextElement*) lastEl->element)->_Text,((TextElement*) lastEl->element)->_Text.begin())); Loading @@ -376,11 +378,13 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { _buildtreenode(nullptr,firstEl->nextel,firstEl,lastEl); DocElements *dnext=firstEl,*dcurel=nullptr; while(dnext){ dcurel=dnext; dnext=dnext->nextel; DocElements *dnext=nullptr,*dcurel=firstEl; while(dcurel){ dnext=dcurel->nextel; dcurel->nextel=nullptr; dcurel->element=nullptr; delete dcurel; dcurel=dnext; } return firsthel; Loading Loading @@ -705,7 +709,6 @@ NEWEL: cpylist.push(childel); } }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){ if(!(((TextElement*)src)->_Text).empty()) ((TextElement*)dest)->_Text=(((TextElement*)src)->_Text); } Loading Loading @@ -911,7 +914,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(const HtmlString *node){ } void libhtmlpp::HtmlPage::saveFile(const char* path){ std::string data; HtmlString data; std::ofstream fs; print(_Page.parse(),data); Loading @@ -923,7 +926,7 @@ void libhtmlpp::HtmlPage::saveFile(const char* path){ throw excp[HTMLException::Critical] << e.what(); } fs << data; fs << data.c_str(); fs.close(); Loading Loading @@ -968,7 +971,7 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ } } void libhtmlpp::print(Element* el, std::string &output) { void libhtmlpp::print(Element* el, HtmlString &output) { std::stack<libhtmlpp::Element*> *cpylist = new std::stack<libhtmlpp::Element*>; Loading src/html.h +5 −4 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace libhtmlpp { class DocElements; class HtmlElement; class HtmlString; enum ElementType{ TextEl=0, Loading Loading @@ -69,7 +70,7 @@ namespace libhtmlpp { friend class HtmlElement; friend class TextElement; friend class HtmlString; friend void print(Element* el, std::string &output); friend void print(Element* el, HtmlString &output); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading Loading @@ -126,7 +127,7 @@ namespace libhtmlpp { friend class HtmlString; friend class HtmlTable; friend void print(Element* el, std::string &output); friend void print(Element* el, HtmlString &output); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading @@ -146,11 +147,11 @@ namespace libhtmlpp { std::vector<char> _Text; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, std::string &output); friend void print(Element* el, HtmlString &output); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; void print(Element* el, std::string &output); void print(Element* el, HtmlString &output); class HtmlString { public: Loading test/htmlcopytest.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -46,9 +46,9 @@ public: } void printModify(){ std::string html; libhtmlpp::HtmlString html; libhtmlpp::print(&index2,html); std::cout << html.data() << std::endl; std::cout << html.c_str() << std::endl; } ~HtmlCopy(){ Loading @@ -66,11 +66,11 @@ int main(int arc,char *argv[]){ HtmlCopy cpy(index); std::string html; libhtmlpp::HtmlString html; std::cout << "Orginal html:" << std::endl; libhtmlpp::print(index,html); std::cout << html.data() << std::endl; std::cout << html.c_str() << std::endl; std::cout << "Modified html:" << std::endl; Loading test/htmlpagetest.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -38,9 +38,9 @@ int main(int arc,char *argv[]){ libhtmlpp::HtmlPage page; try{ libhtmlpp::Element *index=page.loadFile(argv[1]); std::string html; libhtmlpp::HtmlString html; libhtmlpp::print(index,html); std::cout << html.data() << std::endl; std::cout << html.c_str() << std::endl; std::cout << Green << "Test Passed!" << NOCOLOR << std::endl; }catch(libhtmlpp::HTMLException &exp){ std::cout << exp.what() << std::endl; Loading Loading
src/html.cpp +17 −14 Original line number Diff line number Diff line Loading @@ -313,7 +313,6 @@ libhtmlpp::DocElements *libhtmlpp::HtmlString::_buildtreenode(DocElements* prev, return _buildtreenode(prev,next->nextel,next,end); } libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { DocElements *firstEl = nullptr, *lastEl = nullptr; Loading @@ -331,7 +330,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { for (size_t i = 0; i < _HTableSize; ++i) { if(_HTable[i][0] == -1 || _HTable[i][2] == -1) if(_HTable[i][0] == -1) continue; addelement(&firstEl,&lastEl); Loading @@ -347,7 +346,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos,std::insert_iterator<std::vector<char>>(tmp,tmp.begin())); _serialelize(tmp, (HtmlElement**) &lastEl->element); size_t epos=0; ssize_t epos=-1; for(size_t ii=i+1; ii<_HTableSize; ++ii){ if(_HTable[ii][0]>=0 && _HTable[ii][2]>=0){ Loading @@ -356,12 +355,15 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { } } if(epos < _HTableSize){ if(epos<0) continue; if(epos < (ssize_t)_HTableSize){ int tlen = (_HTable[epos][0]-_HTable[i][2]); if(tlen>1){ addelement(&firstEl,&lastEl); lastEl->element=new TextElement(); lastEl->spos = _HTable[i][2]; lastEl->spos = _HTable[i][2]+1; lastEl->epos = _HTable[epos][0]; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos,std::insert_iterator<std::vector<char>> (((TextElement*) lastEl->element)->_Text,((TextElement*) lastEl->element)->_Text.begin())); Loading @@ -376,11 +378,13 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { _buildtreenode(nullptr,firstEl->nextel,firstEl,lastEl); DocElements *dnext=firstEl,*dcurel=nullptr; while(dnext){ dcurel=dnext; dnext=dnext->nextel; DocElements *dnext=nullptr,*dcurel=firstEl; while(dcurel){ dnext=dcurel->nextel; dcurel->nextel=nullptr; dcurel->element=nullptr; delete dcurel; dcurel=dnext; } return firsthel; Loading Loading @@ -705,7 +709,6 @@ NEWEL: cpylist.push(childel); } }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){ if(!(((TextElement*)src)->_Text).empty()) ((TextElement*)dest)->_Text=(((TextElement*)src)->_Text); } Loading Loading @@ -911,7 +914,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(const HtmlString *node){ } void libhtmlpp::HtmlPage::saveFile(const char* path){ std::string data; HtmlString data; std::ofstream fs; print(_Page.parse(),data); Loading @@ -923,7 +926,7 @@ void libhtmlpp::HtmlPage::saveFile(const char* path){ throw excp[HTMLException::Critical] << e.what(); } fs << data; fs << data.c_str(); fs.close(); Loading Loading @@ -968,7 +971,7 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ } } void libhtmlpp::print(Element* el, std::string &output) { void libhtmlpp::print(Element* el, HtmlString &output) { std::stack<libhtmlpp::Element*> *cpylist = new std::stack<libhtmlpp::Element*>; Loading
src/html.h +5 −4 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace libhtmlpp { class DocElements; class HtmlElement; class HtmlString; enum ElementType{ TextEl=0, Loading Loading @@ -69,7 +70,7 @@ namespace libhtmlpp { friend class HtmlElement; friend class TextElement; friend class HtmlString; friend void print(Element* el, std::string &output); friend void print(Element* el, HtmlString &output); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading Loading @@ -126,7 +127,7 @@ namespace libhtmlpp { friend class HtmlString; friend class HtmlTable; friend void print(Element* el, std::string &output); friend void print(Element* el, HtmlString &output); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading @@ -146,11 +147,11 @@ namespace libhtmlpp { std::vector<char> _Text; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, std::string &output); friend void print(Element* el, HtmlString &output); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; void print(Element* el, std::string &output); void print(Element* el, HtmlString &output); class HtmlString { public: Loading
test/htmlcopytest.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -46,9 +46,9 @@ public: } void printModify(){ std::string html; libhtmlpp::HtmlString html; libhtmlpp::print(&index2,html); std::cout << html.data() << std::endl; std::cout << html.c_str() << std::endl; } ~HtmlCopy(){ Loading @@ -66,11 +66,11 @@ int main(int arc,char *argv[]){ HtmlCopy cpy(index); std::string html; libhtmlpp::HtmlString html; std::cout << "Orginal html:" << std::endl; libhtmlpp::print(index,html); std::cout << html.data() << std::endl; std::cout << html.c_str() << std::endl; std::cout << "Modified html:" << std::endl; Loading
test/htmlpagetest.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -38,9 +38,9 @@ int main(int arc,char *argv[]){ libhtmlpp::HtmlPage page; try{ libhtmlpp::Element *index=page.loadFile(argv[1]); std::string html; libhtmlpp::HtmlString html; libhtmlpp::print(index,html); std::cout << html.data() << std::endl; std::cout << html.c_str() << std::endl; std::cout << Green << "Test Passed!" << NOCOLOR << std::endl; }catch(libhtmlpp::HTMLException &exp){ std::cout << exp.what() << std::endl; Loading