Loading src/html.cpp +41 −33 Original line number Diff line number Diff line Loading @@ -324,12 +324,9 @@ void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libht }; NEXTDOCEL: DocElements *parent; if(start==firstel){ parent=lastel; }else{ parent=checkterminator(start,end); } DocElements *parent=checkterminator(start,end); if(prev && !start->terminator){ start->element->_prevElement=prev->element; Loading @@ -342,6 +339,7 @@ NEXTDOCEL: childel.end=parent; cpylist.push(childel); next=parent; parent=nullptr; } if(!next){ Loading Loading @@ -420,19 +418,19 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) { std::inserter<std::vector<char>>(((CommentElement*) lastEl->element)->_Comment,((CommentElement*) lastEl->element)->_Comment.begin())); } if(!lastEl->terminator){ lastEl->element->_firstElement=firstEl->element; } size_t epos = i+1 < _HTableSize ? _HTable[i+1][0] : _Data.size(); size_t spos = _HTable[i][2]+1; if(int(epos - spos) > 0){ addelement(&firstEl,&lastEl); lastEl->element=new TextElement(); lastEl->spos = spos; lastEl->epos = epos; std::vector<char> buf; bool start=false; for(size_t i = lastEl->spos; i<lastEl->epos; ++i){ for(size_t i = spos; i<epos; ++i){ switch(_Data[i]){ case '\r': continue; Loading @@ -443,10 +441,20 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) { continue; default: start=true; ((TextElement*)lastEl->element)->_Text.push_back(_Data[i]); buf.push_back(_Data[i]); continue; } } if(!buf.empty()){ addelement(&firstEl,&lastEl); lastEl->element=new TextElement(); lastEl->element->_firstElement=firstEl->element; lastEl->spos = spos; lastEl->epos = epos; ((TextElement*)lastEl->element)->_Text=buf; } } } Loading @@ -456,6 +464,8 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) { while(firstEl){ DocElements *next=firstEl->nextel; if(firstEl->terminator) delete firstEl->element; delete firstEl; firstEl=next; } Loading Loading @@ -672,9 +682,9 @@ libhtmlpp::HtmlElement::~HtmlElement(){ cur->_prevElement=nullptr; if(cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement){ childs.push(((HtmlElement*)cur)->_childElement); delelm.push(((HtmlElement*)cur)->_childElement); ((HtmlElement*)cur)->_childElement=nullptr; } delelm.push(cur); cur=next; } if(!childs.empty()){ Loading @@ -685,9 +695,12 @@ libhtmlpp::HtmlElement::~HtmlElement(){ while(!delelm.empty()){ Element *itm=delelm.top(); if(itm!=this) delete itm; delelm.pop(); } _childElement=nullptr; } void libhtmlpp::HtmlElement::setTagname(const char* name){ Loading Loading @@ -976,15 +989,19 @@ libhtmlpp::Element::Element(const libhtmlpp::Element& el){ } libhtmlpp::Element::~Element(){ if(this==_firstElement){ Element *curel=this; Element *curel=_firstElement; while(curel){ Element *next=curel->_nextElement; curel->_firstElement=nullptr; curel->_prevElement=nullptr; curel->_nextElement=nullptr; if(curel!=this) delete curel; curel=next; } } _firstElement=nullptr; _prevElement=nullptr; _nextElement=nullptr; }; libhtmlpp::TextElement::TextElement() : Element(){ Loading Loading @@ -1154,7 +1171,7 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ } } void libhtmlpp::print(Element* el, HtmlString &output) { void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { std::stack<libhtmlpp::Element*> cpylist; auto printag = [](Element *el,HtmlString &tag){ Loading @@ -1173,11 +1190,6 @@ void libhtmlpp::print(Element* el, HtmlString &output) { tag.append(">"); }; if(el->_Type==HtmlEl && strcmp(((HtmlElement*) el)->getTagname(),"!DOCTYPE") ==0 ){ printag(el,output); el=((HtmlElement*) el)->_childElement; } PRINTNEXTEL: switch(el->_Type){ case HtmlEl:{ Loading @@ -1187,10 +1199,6 @@ PRINTNEXTEL: cpylist.push(el); el=((HtmlElement*) el)->_childElement; goto PRINTNEXTEL; }else { output.append("</"); output.append(((HtmlElement*) el)->getTagname()); output.append(">"); } if (el->_nextElement) { Loading src/html.h +5 −5 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ namespace libhtmlpp { friend class HtmlElement; friend class TextElement; friend class HtmlString; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading Loading @@ -131,7 +131,7 @@ namespace libhtmlpp { friend class HtmlString; friend class HtmlTable; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading @@ -151,7 +151,7 @@ namespace libhtmlpp { std::vector<char> _Text; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading @@ -171,11 +171,11 @@ namespace libhtmlpp { std::vector<char> _Comment; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; void print(Element* el, HtmlString &output); void print(Element* el, HtmlString &output,bool formated=false); class HtmlString { public: Loading Loading
src/html.cpp +41 −33 Original line number Diff line number Diff line Loading @@ -324,12 +324,9 @@ void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libht }; NEXTDOCEL: DocElements *parent; if(start==firstel){ parent=lastel; }else{ parent=checkterminator(start,end); } DocElements *parent=checkterminator(start,end); if(prev && !start->terminator){ start->element->_prevElement=prev->element; Loading @@ -342,6 +339,7 @@ NEXTDOCEL: childel.end=parent; cpylist.push(childel); next=parent; parent=nullptr; } if(!next){ Loading Loading @@ -420,19 +418,19 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) { std::inserter<std::vector<char>>(((CommentElement*) lastEl->element)->_Comment,((CommentElement*) lastEl->element)->_Comment.begin())); } if(!lastEl->terminator){ lastEl->element->_firstElement=firstEl->element; } size_t epos = i+1 < _HTableSize ? _HTable[i+1][0] : _Data.size(); size_t spos = _HTable[i][2]+1; if(int(epos - spos) > 0){ addelement(&firstEl,&lastEl); lastEl->element=new TextElement(); lastEl->spos = spos; lastEl->epos = epos; std::vector<char> buf; bool start=false; for(size_t i = lastEl->spos; i<lastEl->epos; ++i){ for(size_t i = spos; i<epos; ++i){ switch(_Data[i]){ case '\r': continue; Loading @@ -443,10 +441,20 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) { continue; default: start=true; ((TextElement*)lastEl->element)->_Text.push_back(_Data[i]); buf.push_back(_Data[i]); continue; } } if(!buf.empty()){ addelement(&firstEl,&lastEl); lastEl->element=new TextElement(); lastEl->element->_firstElement=firstEl->element; lastEl->spos = spos; lastEl->epos = epos; ((TextElement*)lastEl->element)->_Text=buf; } } } Loading @@ -456,6 +464,8 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) { while(firstEl){ DocElements *next=firstEl->nextel; if(firstEl->terminator) delete firstEl->element; delete firstEl; firstEl=next; } Loading Loading @@ -672,9 +682,9 @@ libhtmlpp::HtmlElement::~HtmlElement(){ cur->_prevElement=nullptr; if(cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement){ childs.push(((HtmlElement*)cur)->_childElement); delelm.push(((HtmlElement*)cur)->_childElement); ((HtmlElement*)cur)->_childElement=nullptr; } delelm.push(cur); cur=next; } if(!childs.empty()){ Loading @@ -685,9 +695,12 @@ libhtmlpp::HtmlElement::~HtmlElement(){ while(!delelm.empty()){ Element *itm=delelm.top(); if(itm!=this) delete itm; delelm.pop(); } _childElement=nullptr; } void libhtmlpp::HtmlElement::setTagname(const char* name){ Loading Loading @@ -976,15 +989,19 @@ libhtmlpp::Element::Element(const libhtmlpp::Element& el){ } libhtmlpp::Element::~Element(){ if(this==_firstElement){ Element *curel=this; Element *curel=_firstElement; while(curel){ Element *next=curel->_nextElement; curel->_firstElement=nullptr; curel->_prevElement=nullptr; curel->_nextElement=nullptr; if(curel!=this) delete curel; curel=next; } } _firstElement=nullptr; _prevElement=nullptr; _nextElement=nullptr; }; libhtmlpp::TextElement::TextElement() : Element(){ Loading Loading @@ -1154,7 +1171,7 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ } } void libhtmlpp::print(Element* el, HtmlString &output) { void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { std::stack<libhtmlpp::Element*> cpylist; auto printag = [](Element *el,HtmlString &tag){ Loading @@ -1173,11 +1190,6 @@ void libhtmlpp::print(Element* el, HtmlString &output) { tag.append(">"); }; if(el->_Type==HtmlEl && strcmp(((HtmlElement*) el)->getTagname(),"!DOCTYPE") ==0 ){ printag(el,output); el=((HtmlElement*) el)->_childElement; } PRINTNEXTEL: switch(el->_Type){ case HtmlEl:{ Loading @@ -1187,10 +1199,6 @@ PRINTNEXTEL: cpylist.push(el); el=((HtmlElement*) el)->_childElement; goto PRINTNEXTEL; }else { output.append("</"); output.append(((HtmlElement*) el)->getTagname()); output.append(">"); } if (el->_nextElement) { Loading
src/html.h +5 −5 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ namespace libhtmlpp { friend class HtmlElement; friend class TextElement; friend class HtmlString; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading Loading @@ -131,7 +131,7 @@ namespace libhtmlpp { friend class HtmlString; friend class HtmlTable; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading @@ -151,7 +151,7 @@ namespace libhtmlpp { std::vector<char> _Text; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; Loading @@ -171,11 +171,11 @@ namespace libhtmlpp { std::vector<char> _Comment; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output); friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; void print(Element* el, HtmlString &output); void print(Element* el, HtmlString &output,bool formated=false); class HtmlString { public: Loading