Loading src/html.cpp +141 −1 Original line number Diff line number Diff line Loading @@ -427,6 +427,38 @@ BUILDTREE_STARTLOOP: } ++ii; } }else if(std::equal(_Data.begin()+ii,_Data.begin()+(ii+7),"<svg")){ size_t start=ii; ii+=7; while(ii<_Data.size()){ if(_Data[ii]==HTMLTAG_CLOSE) { addelement(&firstEl,&lastEl,new SvgElement()); std::vector<char> tel; std::copy(_Data.begin()+start,_Data.begin()+ii,std::back_inserter(tel)); _serialelize(tel,(SvgElement*)lastEl->element); break; } ++ii; } size_t close=++ii; while(ii<_Data.size()){ if( std::equal(_Data.begin()+ii,_Data.begin()+(ii+8),"</svg")) { std::copy(_Data.begin()+close,_Data.begin()+ii, std::back_inserter(((SvgElement*)lastEl->element)->_Svg)); ii+=8; break; } ++ii; } }else { size_t start=++ii; addelement(&firstEl,&lastEl,new HtmlElement()); Loading Loading @@ -529,7 +561,7 @@ GETTAGEND: throw excp[HTMLException::Critical] << "no tag in element found!"; } for(size_t i=et; i<in.size(); ++i){ for(size_t i=et; i<in.size(); i++){ bool value=false; size_t kstart=std::string::npos,kend=std::string::npos; if(in[i]=='>'){ Loading Loading @@ -905,6 +937,9 @@ NEWEL: case ScriptEL: ((libhtmlpp::HtmlElement*)dest)->_childElement = new ScriptElement; break; case SvgEL: ((libhtmlpp::HtmlElement*)dest)->_childElement = new SvgElement; break; default: HTMLException ex; ex[HTMLException::Critical] << "_copy: Unknown html element found !"; Loading Loading @@ -933,6 +968,24 @@ NEWEL: } } ((ScriptElement*)dest)->_Script=(((ScriptElement*)src)->_Script); }else if(src->getType()==libhtmlpp::ScriptEL && dest->getType()== libhtmlpp::SvgEL){ ((libhtmlpp::SvgElement*)dest)->_TagName=(((libhtmlpp::SvgElement*)src)->_TagName); for(libhtmlpp::SvgElement::Attributes *cattr=((libhtmlpp::SvgElement*)src)->_firstAttr; cattr; cattr=cattr->_nextAttr){ if(!cattr->_Value.empty()){ ((libhtmlpp::SvgElement*)dest)->setAttribute( std::string( cattr->_Key.begin(), cattr->_Key.end() ),std::string( cattr->_Value.begin(), cattr->_Value.end() ) ); }else{ ((libhtmlpp::SvgElement*)dest)->setAttribute(std::string(cattr->_Key.begin(),cattr->_Key.end()),""); } } ((SvgElement*)dest)->_Svg=(((SvgElement*)src)->_Svg); }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){ ((TextElement*)dest)->_Text=(((TextElement*)src)->_Text); }else if(src->getType()==libhtmlpp::CommentEl && dest->getType()== libhtmlpp::CommentEl){ Loading Loading @@ -960,6 +1013,9 @@ NEWEL: case ScriptEL: dest->_nextElement= new ScriptElement(); break; case SvgEL: dest->_nextElement= new SvgElement(); break; default: HTMLException ex; ex[HTMLException::Critical] << "_copy: Unknown next html element found !"; Loading Loading @@ -1232,6 +1288,40 @@ int libhtmlpp::ScriptElement::getType() const{ return ElementType::ScriptEL; } libhtmlpp::SvgElement::SvgElement() : HtmlElement("svg"){ } libhtmlpp::SvgElement::SvgElement(const SvgElement &svgsrc) : HtmlElement("script"){ _copy(this,&svgsrc); } libhtmlpp::SvgElement::~SvgElement(){ } libhtmlpp::SvgElement & libhtmlpp::SvgElement::operator=(const libhtmlpp::Element& hel){ _copy(this,&hel); return *this; } libhtmlpp::SvgElement & libhtmlpp::SvgElement::operator=(const libhtmlpp::Element* hel){ _copy(this,hel); return *this; } void libhtmlpp::SvgElement::setSvg(const std::string& script){ std::copy(script.begin(),script.end(), std::insert_iterator<std::vector<char>>(_Svg,_Svg.begin())); } const std::vector<char>libhtmlpp::SvgElement::getSvg(){ return _Svg; } int libhtmlpp::SvgElement::getType() const{ return ElementType::SvgEL; } libhtmlpp::HtmlPage::HtmlPage(){ } Loading Loading @@ -1519,6 +1609,56 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { goto PRINTNEXTEL; } }break; case SvgEL:{ output.append("<"); output.append(((SvgElement*) el)->getTagname()); for (SvgElement::Attributes* curattr = ((SvgElement*) el)->_firstAttr; curattr; curattr = curattr->_nextAttr) { output.append(" "); std::copy( curattr->_Key.begin(), curattr->_Key.end(), std::back_inserter(output) ); if(!curattr->_Value.empty()){ output.append("=\""); std::copy( curattr->_Value.begin(), curattr->_Value.end(), std::back_inserter(output) ); output.append("\""); } } output.append(">"); if(formated){ output.append("\r\n"); for(int i=0; i<lvl+1; ++i){ output.append(" "); } } std::copy( ((SvgElement*)el)->_Svg.begin(), ((SvgElement*)el)->_Svg.end(), std::back_inserter(output) ); if(formated){ output.append("\r\n"); for(int i=0; i<lvl; ++i){ output.append(" "); } } output.append("</"); output.append(((SvgElement*) el)->getTagname()); output.append(">"); if(formated) output.append("\r\n"); if (el->_nextElement) { el=el->_nextElement; goto PRINTNEXTEL; } }break; default: HTMLException excp; excp[HTMLException::Error] << "Unkown Elementtype"; Loading src/html.h +31 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,8 @@ namespace libhtmlpp { TextEl=0, HtmlEl=1, CommentEl=2, ScriptEL=3 ScriptEL=3, SvgEL=4 }; class Element { Loading Loading @@ -211,6 +212,35 @@ namespace libhtmlpp { friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; class SvgElement : public HtmlElement{ public: SvgElement(); SvgElement(const SvgElement &svgsrc); ~SvgElement(); SvgElement& operator=(const Element &hel); SvgElement& operator=(const Element *hel); const std::vector<char> getSvg(); void setSvg(const std::string &svg); int getType() const; void insertChild(const Element* el)=delete; void insertChild(const Element& el)=delete; void appendChild(const Element* el)=delete; void appendChild(const Element& el)=delete; protected: Element* _childElement=nullptr; std::vector<char> _Svg; friend class HtmlString; 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,bool formated=false); class HtmlString { Loading Loading
src/html.cpp +141 −1 Original line number Diff line number Diff line Loading @@ -427,6 +427,38 @@ BUILDTREE_STARTLOOP: } ++ii; } }else if(std::equal(_Data.begin()+ii,_Data.begin()+(ii+7),"<svg")){ size_t start=ii; ii+=7; while(ii<_Data.size()){ if(_Data[ii]==HTMLTAG_CLOSE) { addelement(&firstEl,&lastEl,new SvgElement()); std::vector<char> tel; std::copy(_Data.begin()+start,_Data.begin()+ii,std::back_inserter(tel)); _serialelize(tel,(SvgElement*)lastEl->element); break; } ++ii; } size_t close=++ii; while(ii<_Data.size()){ if( std::equal(_Data.begin()+ii,_Data.begin()+(ii+8),"</svg")) { std::copy(_Data.begin()+close,_Data.begin()+ii, std::back_inserter(((SvgElement*)lastEl->element)->_Svg)); ii+=8; break; } ++ii; } }else { size_t start=++ii; addelement(&firstEl,&lastEl,new HtmlElement()); Loading Loading @@ -529,7 +561,7 @@ GETTAGEND: throw excp[HTMLException::Critical] << "no tag in element found!"; } for(size_t i=et; i<in.size(); ++i){ for(size_t i=et; i<in.size(); i++){ bool value=false; size_t kstart=std::string::npos,kend=std::string::npos; if(in[i]=='>'){ Loading Loading @@ -905,6 +937,9 @@ NEWEL: case ScriptEL: ((libhtmlpp::HtmlElement*)dest)->_childElement = new ScriptElement; break; case SvgEL: ((libhtmlpp::HtmlElement*)dest)->_childElement = new SvgElement; break; default: HTMLException ex; ex[HTMLException::Critical] << "_copy: Unknown html element found !"; Loading Loading @@ -933,6 +968,24 @@ NEWEL: } } ((ScriptElement*)dest)->_Script=(((ScriptElement*)src)->_Script); }else if(src->getType()==libhtmlpp::ScriptEL && dest->getType()== libhtmlpp::SvgEL){ ((libhtmlpp::SvgElement*)dest)->_TagName=(((libhtmlpp::SvgElement*)src)->_TagName); for(libhtmlpp::SvgElement::Attributes *cattr=((libhtmlpp::SvgElement*)src)->_firstAttr; cattr; cattr=cattr->_nextAttr){ if(!cattr->_Value.empty()){ ((libhtmlpp::SvgElement*)dest)->setAttribute( std::string( cattr->_Key.begin(), cattr->_Key.end() ),std::string( cattr->_Value.begin(), cattr->_Value.end() ) ); }else{ ((libhtmlpp::SvgElement*)dest)->setAttribute(std::string(cattr->_Key.begin(),cattr->_Key.end()),""); } } ((SvgElement*)dest)->_Svg=(((SvgElement*)src)->_Svg); }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){ ((TextElement*)dest)->_Text=(((TextElement*)src)->_Text); }else if(src->getType()==libhtmlpp::CommentEl && dest->getType()== libhtmlpp::CommentEl){ Loading Loading @@ -960,6 +1013,9 @@ NEWEL: case ScriptEL: dest->_nextElement= new ScriptElement(); break; case SvgEL: dest->_nextElement= new SvgElement(); break; default: HTMLException ex; ex[HTMLException::Critical] << "_copy: Unknown next html element found !"; Loading Loading @@ -1232,6 +1288,40 @@ int libhtmlpp::ScriptElement::getType() const{ return ElementType::ScriptEL; } libhtmlpp::SvgElement::SvgElement() : HtmlElement("svg"){ } libhtmlpp::SvgElement::SvgElement(const SvgElement &svgsrc) : HtmlElement("script"){ _copy(this,&svgsrc); } libhtmlpp::SvgElement::~SvgElement(){ } libhtmlpp::SvgElement & libhtmlpp::SvgElement::operator=(const libhtmlpp::Element& hel){ _copy(this,&hel); return *this; } libhtmlpp::SvgElement & libhtmlpp::SvgElement::operator=(const libhtmlpp::Element* hel){ _copy(this,hel); return *this; } void libhtmlpp::SvgElement::setSvg(const std::string& script){ std::copy(script.begin(),script.end(), std::insert_iterator<std::vector<char>>(_Svg,_Svg.begin())); } const std::vector<char>libhtmlpp::SvgElement::getSvg(){ return _Svg; } int libhtmlpp::SvgElement::getType() const{ return ElementType::SvgEL; } libhtmlpp::HtmlPage::HtmlPage(){ } Loading Loading @@ -1519,6 +1609,56 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { goto PRINTNEXTEL; } }break; case SvgEL:{ output.append("<"); output.append(((SvgElement*) el)->getTagname()); for (SvgElement::Attributes* curattr = ((SvgElement*) el)->_firstAttr; curattr; curattr = curattr->_nextAttr) { output.append(" "); std::copy( curattr->_Key.begin(), curattr->_Key.end(), std::back_inserter(output) ); if(!curattr->_Value.empty()){ output.append("=\""); std::copy( curattr->_Value.begin(), curattr->_Value.end(), std::back_inserter(output) ); output.append("\""); } } output.append(">"); if(formated){ output.append("\r\n"); for(int i=0; i<lvl+1; ++i){ output.append(" "); } } std::copy( ((SvgElement*)el)->_Svg.begin(), ((SvgElement*)el)->_Svg.end(), std::back_inserter(output) ); if(formated){ output.append("\r\n"); for(int i=0; i<lvl; ++i){ output.append(" "); } } output.append("</"); output.append(((SvgElement*) el)->getTagname()); output.append(">"); if(formated) output.append("\r\n"); if (el->_nextElement) { el=el->_nextElement; goto PRINTNEXTEL; } }break; default: HTMLException excp; excp[HTMLException::Error] << "Unkown Elementtype"; Loading
src/html.h +31 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,8 @@ namespace libhtmlpp { TextEl=0, HtmlEl=1, CommentEl=2, ScriptEL=3 ScriptEL=3, SvgEL=4 }; class Element { Loading Loading @@ -211,6 +212,35 @@ namespace libhtmlpp { friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; class SvgElement : public HtmlElement{ public: SvgElement(); SvgElement(const SvgElement &svgsrc); ~SvgElement(); SvgElement& operator=(const Element &hel); SvgElement& operator=(const Element *hel); const std::vector<char> getSvg(); void setSvg(const std::string &svg); int getType() const; void insertChild(const Element* el)=delete; void insertChild(const Element& el)=delete; void appendChild(const Element* el)=delete; void appendChild(const Element& el)=delete; protected: Element* _childElement=nullptr; std::vector<char> _Svg; friend class HtmlString; 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,bool formated=false); class HtmlString { Loading