Loading src/html.cpp +27 −44 Original line number Diff line number Diff line Loading @@ -122,17 +122,12 @@ libhtmlpp::HtmlString::HtmlString(const libhtmlpp::HtmlString* str) : HtmlString } void libhtmlpp::HtmlString::append(const char* src, size_t srcsize){ std::copy(src,src+srcsize,std::insert_iterator<std::vector<char>>(_Data,_Data.end())); } void libhtmlpp::HtmlString::push_back(const char src){ _Data.push_back(src); } void libhtmlpp::HtmlString::append(const char* src) { if(src) append(src,strlen(src)); void libhtmlpp::HtmlString::append(const std::string& src) { std::copy(src.begin(),src.end(),std::insert_iterator<std::vector<char>>(_Data,_Data.end())); } void libhtmlpp::HtmlString::append(libhtmlpp::HtmlString& hstring) { Loading Loading @@ -194,16 +189,11 @@ libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(const char* src) { return *this; } libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(std::string &src) { libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(const std::string &src) { append(src.c_str()); return *this; } libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(std::string *src) { append(src->c_str()); return *this; } libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(HtmlString src) { append(src.c_str()); return *this; Loading Loading @@ -676,10 +666,8 @@ void libhtmlpp::HtmlElement::setTagname(const char* name){ std::copy(name,name+strlen(name),std::insert_iterator<std::vector<char>>(_TagName,_TagName.begin()) ); } const char* libhtmlpp::HtmlElement::getTagname(){ _CStr=_TagName; _CStr.push_back('\0'); return _CStr.data(); const std::string libhtmlpp::HtmlElement::getTagname() const{ return _TagName.data(); } void libhtmlpp::HtmlElement::insertChild(const libhtmlpp::Element* el){ Loading Loading @@ -1131,8 +1119,7 @@ void libhtmlpp::TextElement::setText(const std::string& txt){ } const std::string libhtmlpp::TextElement::getText(){ _CStr=_Text.data(); return _CStr; return _Text.data(); } int libhtmlpp::TextElement::getType() const{ Loading Loading @@ -1161,15 +1148,13 @@ libhtmlpp::CommentElement & libhtmlpp::CommentElement::operator=(const libhtmlpp return *this; } void libhtmlpp::CommentElement::setComment(const char* txt){ std::copy(txt,txt+strlen(txt), void libhtmlpp::CommentElement::setComment(const std::string& txt){ std::copy(txt.begin(),txt.end(), std::insert_iterator<std::vector<char>>(_Comment,_Comment.begin())); } const char * libhtmlpp::CommentElement::getComment(){ _CStr=_Comment; _CStr.push_back('\0'); return _CStr.data(); const std::string libhtmlpp::CommentElement::getComment(){ return _Comment.data(); } int libhtmlpp::CommentElement::getType() const{ Loading Loading @@ -1197,15 +1182,13 @@ libhtmlpp::ScriptElement & libhtmlpp::ScriptElement::operator=(const libhtmlpp:: return *this; } void libhtmlpp::ScriptElement::setScript(const char* txt){ std::copy(txt,txt+strlen(txt), void libhtmlpp::ScriptElement::setScript(const std::string& script){ std::copy(script.begin(),script.end(), std::insert_iterator<std::vector<char>>(_Script,_Script.begin())); } const char * libhtmlpp::ScriptElement::getScript(){ _CStr=_Script; _CStr.push_back('\0'); return _CStr.data(); const std::string libhtmlpp::ScriptElement::getScript(){ return _Script.data(); } int libhtmlpp::ScriptElement::getType() const{ Loading Loading @@ -1348,9 +1331,9 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { auto isContainer = [](const char *tagname) { auto isContainer = [](const std::string &tagname) { for(int i=0; ContainerTypes[i]; ++i){ if(strcmp(ContainerTypes[i],tagname)==0) if(tagname==ContainerTypes[i]) return true; } return false; Loading @@ -1374,10 +1357,10 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { output.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()); output.append(curattr->_Key.data()); if(!curattr->_Value.empty()){ output.append("=\""); output.append(curattr->_Value.data(),curattr->_Value.size()); output.append(curattr->_Value.data()); output.append("\""); } } Loading @@ -1400,7 +1383,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { //Container must be always terminated fuck html5 if(isContainer(((HtmlElement*) el)->getTagname())){ output.append("</"); output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size()); output.append(((HtmlElement*) el)->_TagName.data()); output.append(">"); } Loading @@ -1414,7 +1397,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { }break; case TextEl :{ output.append(((TextElement*)el)->_Text.data(),((TextElement*)el)->_Text.size()); output.append(((TextElement*)el)->_Text.data()); if(formated) output.append("\r\n"); Loading @@ -1425,7 +1408,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { }break; case CommentEl: { output.append("<!--"); output.append(((CommentElement*)el)->_Comment.data(),((CommentElement*)el)->_Comment.size()); output.append(((CommentElement*)el)->_Comment.data()); output.append("-->"); if(formated) output.append("\r\n"); Loading @@ -1440,10 +1423,10 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { output.append(((ScriptElement*) el)->getTagname()); for (ScriptElement::Attributes* curattr = ((ScriptElement*) el)->_firstAttr; curattr; curattr = curattr->_nextAttr) { output.append(" "); output.append(curattr->_Key.data(),curattr->_Key.size()); output.append(curattr->_Key.data()); if(!curattr->_Value.empty()){ output.append("=\""); output.append(curattr->_Value.data(),curattr->_Value.size()); output.append(curattr->_Value.data()); output.append("\""); } } Loading @@ -1455,7 +1438,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { output.append(" "); } } output.append(((ScriptElement*)el)->_Script.data(),((ScriptElement*)el)->_Script.size()); output.append(((ScriptElement*)el)->_Script.data()); if(formated){ output.append("\r\n"); for(int i=0; i<lvl; ++i){ Loading Loading @@ -1492,7 +1475,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { } output.append("</"); output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size()); output.append(((HtmlElement*) el)->_TagName.data()); output.append(">"); if(formated) Loading Loading @@ -1543,8 +1526,8 @@ SEARCHBYTAG: if(((HtmlElement*)curel)->_childElement){ childs.push(((HtmlElement*)curel)->_childElement); } const char *tname=((HtmlElement*)curel)->getTagname(); if(tname && tag==tname){ const std::string tname=((HtmlElement*)curel)->getTagname(); if(!tname.empty() && tag==tname){ return (HtmlElement*)curel; } } Loading src/html.h +7 −13 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ namespace libhtmlpp { void appendChild(const Element& el); void setTagname(const char *name); const char *getTagname(); const std::string getTagname() const; HtmlElement *getElementbyID(const std::string &id) const; HtmlElement *getElementbyTag(const std::string &tag) const; Loading @@ -130,7 +130,6 @@ namespace libhtmlpp { private: //if text tagname must be zero std::vector<char> _TagName; std::vector<char> _CStr; //if text Attributes must be zero Attributes* _firstAttr; Loading Loading @@ -158,7 +157,6 @@ namespace libhtmlpp { int getType() const; protected: std::vector<char> _Text; const char * _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -173,13 +171,12 @@ namespace libhtmlpp { CommentElement& operator=(const Element &hel); CommentElement& operator=(const Element *hel); const char *getComment(); void setComment(const char *txt); const std::string getComment(); void setComment(const std::string &txt); int getType() const; protected: std::vector<char> _Comment; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -194,8 +191,8 @@ namespace libhtmlpp { ScriptElement& operator=(const Element &hel); ScriptElement& operator=(const Element *hel); const char *getScript(); void setScript(const char *txt); const std::string getScript(); void setScript(const std::string &txt); int getType() const; Loading @@ -209,7 +206,6 @@ namespace libhtmlpp { Element* _childElement=nullptr; std::vector<char> _Script; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -230,8 +226,7 @@ namespace libhtmlpp { HtmlString(const std::string &str); ~HtmlString(); void append(const char* src, size_t srcsize); void append(const char* src); void append(const std::string &src); void append(HtmlString& hstring); void push_back(const char src); Loading @@ -246,8 +241,7 @@ namespace libhtmlpp { char operator[](size_t pos) const; HtmlString& operator<<(const char* src); HtmlString& operator<<(std::string &src); HtmlString& operator<<(std::string *src); HtmlString& operator<<(const std::string &src); HtmlString& operator<<(HtmlString src); HtmlString& operator<<(int src); HtmlString& operator<<(unsigned int src); Loading Loading
src/html.cpp +27 −44 Original line number Diff line number Diff line Loading @@ -122,17 +122,12 @@ libhtmlpp::HtmlString::HtmlString(const libhtmlpp::HtmlString* str) : HtmlString } void libhtmlpp::HtmlString::append(const char* src, size_t srcsize){ std::copy(src,src+srcsize,std::insert_iterator<std::vector<char>>(_Data,_Data.end())); } void libhtmlpp::HtmlString::push_back(const char src){ _Data.push_back(src); } void libhtmlpp::HtmlString::append(const char* src) { if(src) append(src,strlen(src)); void libhtmlpp::HtmlString::append(const std::string& src) { std::copy(src.begin(),src.end(),std::insert_iterator<std::vector<char>>(_Data,_Data.end())); } void libhtmlpp::HtmlString::append(libhtmlpp::HtmlString& hstring) { Loading Loading @@ -194,16 +189,11 @@ libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(const char* src) { return *this; } libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(std::string &src) { libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(const std::string &src) { append(src.c_str()); return *this; } libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(std::string *src) { append(src->c_str()); return *this; } libhtmlpp::HtmlString& libhtmlpp::HtmlString::operator<<(HtmlString src) { append(src.c_str()); return *this; Loading Loading @@ -676,10 +666,8 @@ void libhtmlpp::HtmlElement::setTagname(const char* name){ std::copy(name,name+strlen(name),std::insert_iterator<std::vector<char>>(_TagName,_TagName.begin()) ); } const char* libhtmlpp::HtmlElement::getTagname(){ _CStr=_TagName; _CStr.push_back('\0'); return _CStr.data(); const std::string libhtmlpp::HtmlElement::getTagname() const{ return _TagName.data(); } void libhtmlpp::HtmlElement::insertChild(const libhtmlpp::Element* el){ Loading Loading @@ -1131,8 +1119,7 @@ void libhtmlpp::TextElement::setText(const std::string& txt){ } const std::string libhtmlpp::TextElement::getText(){ _CStr=_Text.data(); return _CStr; return _Text.data(); } int libhtmlpp::TextElement::getType() const{ Loading Loading @@ -1161,15 +1148,13 @@ libhtmlpp::CommentElement & libhtmlpp::CommentElement::operator=(const libhtmlpp return *this; } void libhtmlpp::CommentElement::setComment(const char* txt){ std::copy(txt,txt+strlen(txt), void libhtmlpp::CommentElement::setComment(const std::string& txt){ std::copy(txt.begin(),txt.end(), std::insert_iterator<std::vector<char>>(_Comment,_Comment.begin())); } const char * libhtmlpp::CommentElement::getComment(){ _CStr=_Comment; _CStr.push_back('\0'); return _CStr.data(); const std::string libhtmlpp::CommentElement::getComment(){ return _Comment.data(); } int libhtmlpp::CommentElement::getType() const{ Loading Loading @@ -1197,15 +1182,13 @@ libhtmlpp::ScriptElement & libhtmlpp::ScriptElement::operator=(const libhtmlpp:: return *this; } void libhtmlpp::ScriptElement::setScript(const char* txt){ std::copy(txt,txt+strlen(txt), void libhtmlpp::ScriptElement::setScript(const std::string& script){ std::copy(script.begin(),script.end(), std::insert_iterator<std::vector<char>>(_Script,_Script.begin())); } const char * libhtmlpp::ScriptElement::getScript(){ _CStr=_Script; _CStr.push_back('\0'); return _CStr.data(); const std::string libhtmlpp::ScriptElement::getScript(){ return _Script.data(); } int libhtmlpp::ScriptElement::getType() const{ Loading Loading @@ -1348,9 +1331,9 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { auto isContainer = [](const char *tagname) { auto isContainer = [](const std::string &tagname) { for(int i=0; ContainerTypes[i]; ++i){ if(strcmp(ContainerTypes[i],tagname)==0) if(tagname==ContainerTypes[i]) return true; } return false; Loading @@ -1374,10 +1357,10 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { output.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()); output.append(curattr->_Key.data()); if(!curattr->_Value.empty()){ output.append("=\""); output.append(curattr->_Value.data(),curattr->_Value.size()); output.append(curattr->_Value.data()); output.append("\""); } } Loading @@ -1400,7 +1383,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { //Container must be always terminated fuck html5 if(isContainer(((HtmlElement*) el)->getTagname())){ output.append("</"); output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size()); output.append(((HtmlElement*) el)->_TagName.data()); output.append(">"); } Loading @@ -1414,7 +1397,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { }break; case TextEl :{ output.append(((TextElement*)el)->_Text.data(),((TextElement*)el)->_Text.size()); output.append(((TextElement*)el)->_Text.data()); if(formated) output.append("\r\n"); Loading @@ -1425,7 +1408,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { }break; case CommentEl: { output.append("<!--"); output.append(((CommentElement*)el)->_Comment.data(),((CommentElement*)el)->_Comment.size()); output.append(((CommentElement*)el)->_Comment.data()); output.append("-->"); if(formated) output.append("\r\n"); Loading @@ -1440,10 +1423,10 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { output.append(((ScriptElement*) el)->getTagname()); for (ScriptElement::Attributes* curattr = ((ScriptElement*) el)->_firstAttr; curattr; curattr = curattr->_nextAttr) { output.append(" "); output.append(curattr->_Key.data(),curattr->_Key.size()); output.append(curattr->_Key.data()); if(!curattr->_Value.empty()){ output.append("=\""); output.append(curattr->_Value.data(),curattr->_Value.size()); output.append(curattr->_Value.data()); output.append("\""); } } Loading @@ -1455,7 +1438,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { output.append(" "); } } output.append(((ScriptElement*)el)->_Script.data(),((ScriptElement*)el)->_Script.size()); output.append(((ScriptElement*)el)->_Script.data()); if(formated){ output.append("\r\n"); for(int i=0; i<lvl; ++i){ Loading Loading @@ -1492,7 +1475,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { } output.append("</"); output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size()); output.append(((HtmlElement*) el)->_TagName.data()); output.append(">"); if(formated) Loading Loading @@ -1543,8 +1526,8 @@ SEARCHBYTAG: if(((HtmlElement*)curel)->_childElement){ childs.push(((HtmlElement*)curel)->_childElement); } const char *tname=((HtmlElement*)curel)->getTagname(); if(tname && tag==tname){ const std::string tname=((HtmlElement*)curel)->getTagname(); if(!tname.empty() && tag==tname){ return (HtmlElement*)curel; } } Loading
src/html.h +7 −13 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ namespace libhtmlpp { void appendChild(const Element& el); void setTagname(const char *name); const char *getTagname(); const std::string getTagname() const; HtmlElement *getElementbyID(const std::string &id) const; HtmlElement *getElementbyTag(const std::string &tag) const; Loading @@ -130,7 +130,6 @@ namespace libhtmlpp { private: //if text tagname must be zero std::vector<char> _TagName; std::vector<char> _CStr; //if text Attributes must be zero Attributes* _firstAttr; Loading Loading @@ -158,7 +157,6 @@ namespace libhtmlpp { int getType() const; protected: std::vector<char> _Text; const char * _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -173,13 +171,12 @@ namespace libhtmlpp { CommentElement& operator=(const Element &hel); CommentElement& operator=(const Element *hel); const char *getComment(); void setComment(const char *txt); const std::string getComment(); void setComment(const std::string &txt); int getType() const; protected: std::vector<char> _Comment; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -194,8 +191,8 @@ namespace libhtmlpp { ScriptElement& operator=(const Element &hel); ScriptElement& operator=(const Element *hel); const char *getScript(); void setScript(const char *txt); const std::string getScript(); void setScript(const std::string &txt); int getType() const; Loading @@ -209,7 +206,6 @@ namespace libhtmlpp { Element* _childElement=nullptr; std::vector<char> _Script; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -230,8 +226,7 @@ namespace libhtmlpp { HtmlString(const std::string &str); ~HtmlString(); void append(const char* src, size_t srcsize); void append(const char* src); void append(const std::string &src); void append(HtmlString& hstring); void push_back(const char src); Loading @@ -246,8 +241,7 @@ namespace libhtmlpp { char operator[](size_t pos) const; HtmlString& operator<<(const char* src); HtmlString& operator<<(std::string &src); HtmlString& operator<<(std::string *src); HtmlString& operator<<(const std::string &src); HtmlString& operator<<(HtmlString src); HtmlString& operator<<(int src); HtmlString& operator<<(unsigned int src); Loading