Loading src/html.cpp +73 −64 Original line number Diff line number Diff line Loading @@ -317,7 +317,12 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements }; NEXTDOCEL: DocElements *parent=checkterminator(start,end); DocElements *parent; if(start==firstel){ parent=lastel; }else{ parent=checkterminator(start,end); } if(prev && !start->terminator){ start->element->_prevElement=prev->element; Loading Loading @@ -359,16 +364,16 @@ NEXTDOCEL: goto NEXTDOCEL; } while(lastel){ DocElements *prev=lastel->prevel; lastel->prevel=nullptr; if(!lastel->terminator) lastel->element=nullptr; delete lastel; lastel=prev; while(firstel){ DocElements *next=firstel->nextel; firstel->prevel=nullptr; firstel->nextel=nullptr; firstel->element=nullptr; delete firstel; firstel=next; } firstel=nullptr; lastel=nullptr; return first; } Loading Loading @@ -411,14 +416,13 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(long& pos) { } if(!comment){ lastEl->element=new HtmlElement(); std::vector<char> el; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+(lastEl->epos+1),std::inserter<std::vector<char>>(el,el.begin())); lastEl->element=new HtmlElement(); _serialelize(el,(HtmlElement*)lastEl->element); }else{ lastEl->element=new CommentElement(); std::copy(_Data.begin()+lastEl->spos+4,_Data.begin()+lastEl->epos-2, std::copy(_Data.begin()+lastEl->spos+4,_Data.begin()+lastEl->epos-3, std::inserter<std::vector<char>>(((CommentElement*) lastEl->element)->_Comment,((CommentElement*) lastEl->element)->_Comment.begin())); } Loading @@ -432,8 +436,23 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(long& pos) { lastEl->spos = spos; lastEl->epos = epos; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos, std::inserter<std::vector<char>>(((TextElement*) lastEl->element)->_Text,((TextElement*) lastEl->element)->_Text.begin())); bool start=false; for(size_t i = lastEl->spos; i<lastEl->epos; ++i){ switch(_Data[i]){ case '\r': continue; case '\n': continue; case ' ': if(!start) continue; default: start=true; ((TextElement*)lastEl->element)->_Text.push_back(_Data[i]); continue; } } } } Loading Loading @@ -641,8 +660,6 @@ libhtmlpp::HtmlElement::~HtmlElement(){ std::stack<Element*> delelm; DELETEELEMENT: if(cur){ if((cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement) ){ while(cur){ Element *next=cur->nextElement(); cur->_nextElement=nullptr; Loading @@ -654,31 +671,15 @@ libhtmlpp::HtmlElement::~HtmlElement(){ delelm.push(cur); cur=next; } } if(!childs.empty()){ cur=childs.top(); childs.pop(); goto DELETEELEMENT; } } while(!delelm.empty()){ Element *itm=delelm.top(); if(itm!=this){ switch(itm->getType()){ case HtmlEl: delete (HtmlElement*)itm; break; case TextEl: delete (TextElement*)itm; break; case CommentEl: delete (CommentElement*)itm; break; default: break; } } delete itm; delelm.pop(); } } Loading Loading @@ -1156,31 +1157,39 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ } void libhtmlpp::print(Element* el, HtmlString &output) { std::stack<libhtmlpp::Element*> cpylist; PRINTNEXTEL: switch(el->_Type){ case HtmlEl:{ output.append("<"); output.append(((HtmlElement*) el)->getTagname()); auto printag = [](Element *el,HtmlString &tag){ tag.append("<"); tag.append(((HtmlElement*) el)->getTagname()); for (HtmlElement::Attributes* curattr = ((HtmlElement*) el)->_firstAttr; curattr; curattr = curattr->_nextAttr) { output.append(" "); output.append(curattr->_Key.data(),curattr->_Key.size()); tag.append(" "); tag.append(curattr->_Key.data(),curattr->_Key.size()); if(!curattr->_Value.empty()){ output.append("=\""); output.append(curattr->_Value.data(),curattr->_Value.size()); output.append("\""); tag.append("=\""); tag.append(curattr->_Value.data(),curattr->_Value.size()); tag.append("\""); } } output.append(">"); 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:{ printag(el,output); if (((HtmlElement*) el)->_childElement) { cpylist.push(el); el=((HtmlElement*) el)->_childElement; goto PRINTNEXTEL; }else if(strcmp(((HtmlElement*) el)->getTagname(),"!DOCTYPE")!=0){ }else { output.append("</"); output.append(((HtmlElement*) el)->getTagname()); output.append(">"); Loading Loading
src/html.cpp +73 −64 Original line number Diff line number Diff line Loading @@ -317,7 +317,12 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements }; NEXTDOCEL: DocElements *parent=checkterminator(start,end); DocElements *parent; if(start==firstel){ parent=lastel; }else{ parent=checkterminator(start,end); } if(prev && !start->terminator){ start->element->_prevElement=prev->element; Loading Loading @@ -359,16 +364,16 @@ NEXTDOCEL: goto NEXTDOCEL; } while(lastel){ DocElements *prev=lastel->prevel; lastel->prevel=nullptr; if(!lastel->terminator) lastel->element=nullptr; delete lastel; lastel=prev; while(firstel){ DocElements *next=firstel->nextel; firstel->prevel=nullptr; firstel->nextel=nullptr; firstel->element=nullptr; delete firstel; firstel=next; } firstel=nullptr; lastel=nullptr; return first; } Loading Loading @@ -411,14 +416,13 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(long& pos) { } if(!comment){ lastEl->element=new HtmlElement(); std::vector<char> el; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+(lastEl->epos+1),std::inserter<std::vector<char>>(el,el.begin())); lastEl->element=new HtmlElement(); _serialelize(el,(HtmlElement*)lastEl->element); }else{ lastEl->element=new CommentElement(); std::copy(_Data.begin()+lastEl->spos+4,_Data.begin()+lastEl->epos-2, std::copy(_Data.begin()+lastEl->spos+4,_Data.begin()+lastEl->epos-3, std::inserter<std::vector<char>>(((CommentElement*) lastEl->element)->_Comment,((CommentElement*) lastEl->element)->_Comment.begin())); } Loading @@ -432,8 +436,23 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(long& pos) { lastEl->spos = spos; lastEl->epos = epos; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos, std::inserter<std::vector<char>>(((TextElement*) lastEl->element)->_Text,((TextElement*) lastEl->element)->_Text.begin())); bool start=false; for(size_t i = lastEl->spos; i<lastEl->epos; ++i){ switch(_Data[i]){ case '\r': continue; case '\n': continue; case ' ': if(!start) continue; default: start=true; ((TextElement*)lastEl->element)->_Text.push_back(_Data[i]); continue; } } } } Loading Loading @@ -641,8 +660,6 @@ libhtmlpp::HtmlElement::~HtmlElement(){ std::stack<Element*> delelm; DELETEELEMENT: if(cur){ if((cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement) ){ while(cur){ Element *next=cur->nextElement(); cur->_nextElement=nullptr; Loading @@ -654,31 +671,15 @@ libhtmlpp::HtmlElement::~HtmlElement(){ delelm.push(cur); cur=next; } } if(!childs.empty()){ cur=childs.top(); childs.pop(); goto DELETEELEMENT; } } while(!delelm.empty()){ Element *itm=delelm.top(); if(itm!=this){ switch(itm->getType()){ case HtmlEl: delete (HtmlElement*)itm; break; case TextEl: delete (TextElement*)itm; break; case CommentEl: delete (CommentElement*)itm; break; default: break; } } delete itm; delelm.pop(); } } Loading Loading @@ -1156,31 +1157,39 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ } void libhtmlpp::print(Element* el, HtmlString &output) { std::stack<libhtmlpp::Element*> cpylist; PRINTNEXTEL: switch(el->_Type){ case HtmlEl:{ output.append("<"); output.append(((HtmlElement*) el)->getTagname()); auto printag = [](Element *el,HtmlString &tag){ tag.append("<"); tag.append(((HtmlElement*) el)->getTagname()); for (HtmlElement::Attributes* curattr = ((HtmlElement*) el)->_firstAttr; curattr; curattr = curattr->_nextAttr) { output.append(" "); output.append(curattr->_Key.data(),curattr->_Key.size()); tag.append(" "); tag.append(curattr->_Key.data(),curattr->_Key.size()); if(!curattr->_Value.empty()){ output.append("=\""); output.append(curattr->_Value.data(),curattr->_Value.size()); output.append("\""); tag.append("=\""); tag.append(curattr->_Value.data(),curattr->_Value.size()); tag.append("\""); } } output.append(">"); 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:{ printag(el,output); if (((HtmlElement*) el)->_childElement) { cpylist.push(el); el=((HtmlElement*) el)->_childElement; goto PRINTNEXTEL; }else if(strcmp(((HtmlElement*) el)->getTagname(),"!DOCTYPE")!=0){ }else { output.append("</"); output.append(((HtmlElement*) el)->getTagname()); output.append(">"); Loading