Loading src/html.cpp +72 −48 Original line number Diff line number Diff line Loading @@ -368,7 +368,7 @@ NEXTDOCEL: goto NEXTDOCEL; } } #include <iostream> libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { DocElements *firstEl = nullptr, *lastEl = nullptr; Loading Loading @@ -421,7 +421,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { ++ii; } size_t close=ii; size_t close=++ii; while(ii<_Data.size()){ if( strncmp(_Data.data()+ii,"</script",8)==0 ) { Loading @@ -438,8 +438,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { while(ii<_Data.size()){ if(_Data[ii]==HTMLTAG_TERMINATE){ lastEl->terminator=true; } if(_Data[ii]==HTMLTAG_CLOSE) { }else if(_Data[ii]==HTMLTAG_CLOSE) { std::vector<char> tel; std::copy(_Data.begin()+start,_Data.begin()+ii,std::back_inserter(tel)); _serialelize(tel,(HtmlElement*)lastEl->element); Loading @@ -448,15 +447,15 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { ++ii; } } }else if(_Data[ii]!='\r' || _Data[ii]!='\n' || _Data[ii]!=' '){ }else if(_Data[ii]!='\r' && _Data[ii]!='\n' && _Data[ii]!=' '){ size_t start=ii; while(ii<_Data.size()){ if(_Data[ii]==HTMLTAG_OPEN) { --ii; std::vector<char> buf; std::copy(_Data.begin()+start,_Data.begin()+ii,std::back_inserter(buf)); addelement(&firstEl,&lastEl,new TextElement()); std::copy(buf.begin(),buf.end(),std::back_inserter(((TextElement*)(lastEl->element))->_Text)); --ii; break; } ++ii; Loading @@ -464,11 +463,6 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { } } int iii=0; for(DocElements *cext=firstEl; cext; cext=cext->nextel){ std::cout << iii++ << std::endl; } Element *first = firstEl->element; _buildtreenode(firstEl,lastEl); Loading @@ -481,7 +475,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { ft->element->_firstElement=nullptr; ft->element->_prevElement=nullptr; ft->element->_nextElement=nullptr; delete ft->element; // delete ft->element; } delete ft; ft=next; Loading Loading @@ -519,7 +513,7 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl std::vector<char> tag; std::copy(in.begin()+st,in.begin()+et,std::insert_iterator<std::vector<char>>(tag,tag.begin()) ); std::copy(in.begin()+st,in.begin()+et,std::back_inserter(tag)); tag.push_back('\0'); out->setTagname(tag.data()); Loading @@ -529,38 +523,46 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl throw excp[HTMLException::Critical] << "no tag in element found!"; } int startpos =-1,vst=-1; for(size_t i=et; i<in.size(); ++i){ bool value=false; std::vector<char> key; while(et < in.size()) { if(in[et]==' ' || in[et]=='>' || in[et]=='=') { if(startpos!=-1 && !value){ std::copy(in.begin()+startpos,in.begin()+et,std::insert_iterator<std::vector<char>>(key,key.begin()) ); out->setAttribute(key.data(),key.size(),nullptr,0); startpos=-1; } if(in[et]=='='){ if(in[i]!=' '){ size_t kstart=i,kend=in.size(),vstart=0,vend=0; for(size_t ii=i; ii<in.size(); ++ii){ if (in[ii]=='='){ value=true; i=ii; kend=ii; break; } }else if(in[et]=='\"') { if( vst==-1 ){ vst=et; }else if(!key.empty() && value){ std::vector<char> val; ++vst; std::copy(in.begin()+vst,in.begin()+et,std::insert_iterator<std::vector<char>>(val,val.begin()) ); out->setAttribute(key.data(),key.size(),val.data(),val.size()); key.clear(); vst=-1; value=false; } if(value){ while(i<in.size()){ if(in[i]=='\"'){ if (vstart==0){ vstart=++i; continue; } vend=i; break; } ++i; } }else{ if(startpos==-1 && !value){ startpos=et; while(i<in.size()){ if(in[i] == '>' || in[i] == ' '){ kend=i; break; } ++i; } } std::vector<char> key,val; std::copy(in.begin()+kstart,in.begin()+kend,std::back_inserter(key)); if(vend!=0){ std::copy(in.begin()+vstart,in.begin()+vend,std::back_inserter(val)); } out->setAttribute(key.data(),key.size(),val.data(),val.size()); } }; ++et; } } Loading Loading @@ -965,6 +967,12 @@ void libhtmlpp::Element::insertBefore(libhtmlpp::Element* el){ _prevElement->_nextElement=cmt; break; } case ScriptEL:{ ScriptElement *script= new ScriptElement; _copy(script,el); _prevElement->_nextElement=script; break; } } Element *nexel=_prevElement->_nextElement,*prev=nullptr; Loading Loading @@ -993,6 +1001,10 @@ void libhtmlpp::Element::insertAfter(libhtmlpp::Element* el){ _nextElement=new CommentElement;; break; } case ScriptEL:{ _nextElement=new ScriptElement;; break; } } _copy(_nextElement,el); Loading Loading @@ -1428,12 +1440,24 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { } output.append(">"); if(formated){ output.append("\r\n"); for(int i=0; i<lvl+1; ++i){ output.append(" "); } } output.append(((ScriptElement*)el)->_Script.data(),((ScriptElement*)el)->_Script.size()); if(formated){ output.append("\r\n"); for(int i=0; i<lvl; ++i){ output.append(" "); } } output.append("</"); output.append(((HtmlElement*) el)->getTagname()); output.append(((ScriptElement*) el)->getTagname()); output.append(">"); if(formated) output.append("\r\n"); }break; default: HTMLException excp; Loading Loading @@ -1473,7 +1497,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyID(const char *id) c std::stack <Element*> childs; const Element *curel=this; SEARCHBYID: if(curel->getType()==HtmlEl){ if(curel->getType()==HtmlEl || curel->getType()== ScriptEL){ if(((HtmlElement*)curel)->_childElement){ childs.push(((HtmlElement*)curel)->_childElement); } Loading Loading @@ -1501,7 +1525,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyTag(const char *tag) std::stack <Element*> childs; const Element *curel=this; SEARCHBYTAG: if(curel->getType()==HtmlEl){ if(curel->getType()==HtmlEl || curel->getType()== ScriptEL){ if(((HtmlElement*)curel)->_childElement){ childs.push(((HtmlElement*)curel)->_childElement); } Loading Loading
src/html.cpp +72 −48 Original line number Diff line number Diff line Loading @@ -368,7 +368,7 @@ NEXTDOCEL: goto NEXTDOCEL; } } #include <iostream> libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { DocElements *firstEl = nullptr, *lastEl = nullptr; Loading Loading @@ -421,7 +421,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { ++ii; } size_t close=ii; size_t close=++ii; while(ii<_Data.size()){ if( strncmp(_Data.data()+ii,"</script",8)==0 ) { Loading @@ -438,8 +438,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { while(ii<_Data.size()){ if(_Data[ii]==HTMLTAG_TERMINATE){ lastEl->terminator=true; } if(_Data[ii]==HTMLTAG_CLOSE) { }else if(_Data[ii]==HTMLTAG_CLOSE) { std::vector<char> tel; std::copy(_Data.begin()+start,_Data.begin()+ii,std::back_inserter(tel)); _serialelize(tel,(HtmlElement*)lastEl->element); Loading @@ -448,15 +447,15 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { ++ii; } } }else if(_Data[ii]!='\r' || _Data[ii]!='\n' || _Data[ii]!=' '){ }else if(_Data[ii]!='\r' && _Data[ii]!='\n' && _Data[ii]!=' '){ size_t start=ii; while(ii<_Data.size()){ if(_Data[ii]==HTMLTAG_OPEN) { --ii; std::vector<char> buf; std::copy(_Data.begin()+start,_Data.begin()+ii,std::back_inserter(buf)); addelement(&firstEl,&lastEl,new TextElement()); std::copy(buf.begin(),buf.end(),std::back_inserter(((TextElement*)(lastEl->element))->_Text)); --ii; break; } ++ii; Loading @@ -464,11 +463,6 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { } } int iii=0; for(DocElements *cext=firstEl; cext; cext=cext->nextel){ std::cout << iii++ << std::endl; } Element *first = firstEl->element; _buildtreenode(firstEl,lastEl); Loading @@ -481,7 +475,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() { ft->element->_firstElement=nullptr; ft->element->_prevElement=nullptr; ft->element->_nextElement=nullptr; delete ft->element; // delete ft->element; } delete ft; ft=next; Loading Loading @@ -519,7 +513,7 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl std::vector<char> tag; std::copy(in.begin()+st,in.begin()+et,std::insert_iterator<std::vector<char>>(tag,tag.begin()) ); std::copy(in.begin()+st,in.begin()+et,std::back_inserter(tag)); tag.push_back('\0'); out->setTagname(tag.data()); Loading @@ -529,38 +523,46 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl throw excp[HTMLException::Critical] << "no tag in element found!"; } int startpos =-1,vst=-1; for(size_t i=et; i<in.size(); ++i){ bool value=false; std::vector<char> key; while(et < in.size()) { if(in[et]==' ' || in[et]=='>' || in[et]=='=') { if(startpos!=-1 && !value){ std::copy(in.begin()+startpos,in.begin()+et,std::insert_iterator<std::vector<char>>(key,key.begin()) ); out->setAttribute(key.data(),key.size(),nullptr,0); startpos=-1; } if(in[et]=='='){ if(in[i]!=' '){ size_t kstart=i,kend=in.size(),vstart=0,vend=0; for(size_t ii=i; ii<in.size(); ++ii){ if (in[ii]=='='){ value=true; i=ii; kend=ii; break; } }else if(in[et]=='\"') { if( vst==-1 ){ vst=et; }else if(!key.empty() && value){ std::vector<char> val; ++vst; std::copy(in.begin()+vst,in.begin()+et,std::insert_iterator<std::vector<char>>(val,val.begin()) ); out->setAttribute(key.data(),key.size(),val.data(),val.size()); key.clear(); vst=-1; value=false; } if(value){ while(i<in.size()){ if(in[i]=='\"'){ if (vstart==0){ vstart=++i; continue; } vend=i; break; } ++i; } }else{ if(startpos==-1 && !value){ startpos=et; while(i<in.size()){ if(in[i] == '>' || in[i] == ' '){ kend=i; break; } ++i; } } std::vector<char> key,val; std::copy(in.begin()+kstart,in.begin()+kend,std::back_inserter(key)); if(vend!=0){ std::copy(in.begin()+vstart,in.begin()+vend,std::back_inserter(val)); } out->setAttribute(key.data(),key.size(),val.data(),val.size()); } }; ++et; } } Loading Loading @@ -965,6 +967,12 @@ void libhtmlpp::Element::insertBefore(libhtmlpp::Element* el){ _prevElement->_nextElement=cmt; break; } case ScriptEL:{ ScriptElement *script= new ScriptElement; _copy(script,el); _prevElement->_nextElement=script; break; } } Element *nexel=_prevElement->_nextElement,*prev=nullptr; Loading Loading @@ -993,6 +1001,10 @@ void libhtmlpp::Element::insertAfter(libhtmlpp::Element* el){ _nextElement=new CommentElement;; break; } case ScriptEL:{ _nextElement=new ScriptElement;; break; } } _copy(_nextElement,el); Loading Loading @@ -1428,12 +1440,24 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { } output.append(">"); if(formated){ output.append("\r\n"); for(int i=0; i<lvl+1; ++i){ output.append(" "); } } output.append(((ScriptElement*)el)->_Script.data(),((ScriptElement*)el)->_Script.size()); if(formated){ output.append("\r\n"); for(int i=0; i<lvl; ++i){ output.append(" "); } } output.append("</"); output.append(((HtmlElement*) el)->getTagname()); output.append(((ScriptElement*) el)->getTagname()); output.append(">"); if(formated) output.append("\r\n"); }break; default: HTMLException excp; Loading Loading @@ -1473,7 +1497,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyID(const char *id) c std::stack <Element*> childs; const Element *curel=this; SEARCHBYID: if(curel->getType()==HtmlEl){ if(curel->getType()==HtmlEl || curel->getType()== ScriptEL){ if(((HtmlElement*)curel)->_childElement){ childs.push(((HtmlElement*)curel)->_childElement); } Loading Loading @@ -1501,7 +1525,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyTag(const char *tag) std::stack <Element*> childs; const Element *curel=this; SEARCHBYTAG: if(curel->getType()==HtmlEl){ if(curel->getType()==HtmlEl || curel->getType()== ScriptEL){ if(((HtmlElement*)curel)->_childElement){ childs.push(((HtmlElement*)curel)->_childElement); } Loading