Loading src/html.cpp +23 −13 Original line number Diff line number Diff line Loading @@ -238,7 +238,9 @@ const size_t libhtmlpp::HtmlString::size() const{ } const char * libhtmlpp::HtmlString::c_str(){ return _Data.data(); _CStr=_Data; _CStr.push_back('\0'); return _CStr.data(); } libhtmlpp::HtmlElement* libhtmlpp::HtmlString::parse() { Loading Loading @@ -350,6 +352,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { std::vector<char> tmp; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos,std::insert_iterator<std::vector<char>>(tmp,tmp.begin())); tmp.push_back('\0'); _serialelize(tmp, (HtmlElement**) &lastEl->element); size_t epos=0; Loading Loading @@ -385,7 +388,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { return firsthel; } #include <iostream> void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlElement **out) { size_t st=0,et=0; Loading Loading @@ -414,6 +417,8 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl std::copy(in.begin()+st,in.begin()+et,std::insert_iterator<std::vector<char>>(tag,tag.begin()) ); tag.push_back('\0'); *out = new HtmlElement(tag.data()); if (!*out) { Loading @@ -429,6 +434,7 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl 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()) ); key.push_back('\0'); (*out)->setAttribute(key.data(),nullptr); startpos=-1; } Loading @@ -441,6 +447,7 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl }else if(!key.empty()){ std::vector<char> val; std::copy(in.begin()+vst+1,in.begin()+(et-1),std::insert_iterator<std::vector<char>>(val,val.begin()) ); val.push_back('\0'); (*out)->setAttribute(key.data(),val.data()); key.clear(); vst=-1; Loading Loading @@ -468,7 +475,7 @@ void libhtmlpp::HtmlString::_parseTree(){ for (size_t i = 0; i < size(); ++i) { switch (_Data[i]) { case HTMLTAG_CLOSE: if(negs<1){ if(negs<2){ ++closetag; } break; Loading Loading @@ -515,7 +522,7 @@ void libhtmlpp::HtmlString::_parseTree(){ _HTable[ip][1]=ii; break; case HTMLTAG_CLOSE: if ( negs <1 && open) { if ( negs <2 && open) { _HTable[ip][2] = ii; ++ip; open = false; Loading Loading @@ -566,6 +573,7 @@ libhtmlpp::HtmlElement::HtmlElement(const char *tagname) : Element(){ _lastAttr=nullptr; _Type=HtmlEl; std::copy(tagname,tagname+strlen(tagname),std::insert_iterator<std::vector<char>>(_TagName,_TagName.begin()) ); _TagName.push_back('\0'); } libhtmlpp::HtmlElement::HtmlElement() : Element() { Loading @@ -592,6 +600,7 @@ libhtmlpp::HtmlElement::~HtmlElement(){ void libhtmlpp::HtmlElement::setTagname(const char* name){ std::copy(name,name+strlen(name),std::insert_iterator<std::vector<char>>(_TagName,_TagName.begin()) ); _TagName.push_back('\0'); } const char* libhtmlpp::HtmlElement::getTagname() const{ Loading Loading @@ -691,7 +700,7 @@ namespace libhtmlpp { const libhtmlpp::Element *source; }; std::stack<cpyel> *cpylist = new std::stack<cpyel>; std::stack<cpyel> cpylist; NEWEL: if(src->getType()==libhtmlpp::HtmlEl && dest->getType()==libhtmlpp::HtmlEl){ Loading @@ -717,7 +726,7 @@ NEWEL: cpyel childel; childel.destin=hdest->_childElement;; childel.source=hsrc->_childElement; cpylist->push(childel); cpylist.push(childel); } }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){ ((TextElement*)dest)->setText(((TextElement*)src)->getText()); Loading @@ -739,16 +748,15 @@ NEWEL: goto NEWEL; } if(!cpylist->empty()){ cpyel childel(cpylist->top()); if(!cpylist.empty()){ cpyel childel(cpylist.top()); prev=nullptr; dest=childel.destin; src=childel.source; cpylist->pop(); cpylist.pop(); goto NEWEL; } delete cpylist; } }; Loading Loading @@ -1126,7 +1134,7 @@ void libhtmlpp::HtmlElement::setAttribute(const char* name, const char* value) { for (Attributes* curattr = _firstAttr; curattr; curattr=curattr->_nextAttr) { if(curattr->_Key.size() >= strlen(name)){ if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()) ==0 ) { if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()-1) ==0 ) { cattr = curattr; } } Loading @@ -1141,11 +1149,13 @@ void libhtmlpp::HtmlElement::setAttribute(const char* name, const char* value) { } cattr = _lastAttr; std::copy(name,name+strlen(name),std::insert_iterator<std::vector<char>>(cattr->_Key,cattr->_Key.begin()) ); cattr->_Key.push_back('\0'); } if(value) std::copy(value,value+strlen(value),std::insert_iterator<std::vector<char>>(cattr->_Value ,cattr->_Value .begin()) ); else cattr->_Value.clear(); cattr->_Value.push_back('\0'); } void libhtmlpp::HtmlElement::setIntAttribute(const char* name, int value) { Loading @@ -1156,9 +1166,9 @@ void libhtmlpp::HtmlElement::setIntAttribute(const char* name, int value) { const char* libhtmlpp::HtmlElement::getAtributte(const char* name) const{ for (Attributes* curattr = _firstAttr; curattr; curattr = curattr->_nextAttr) { if(curattr->_Key.size() > strlen(name)) if(curattr->_Key.size()-1 > strlen(name)) return nullptr; if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()) == 0 ) { if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()-1) == 0 ) { return curattr->_Value.data(); } } Loading src/html.h +1 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,7 @@ namespace libhtmlpp { Element* _buildTree(ssize_t& pos); DocElements *_buildtreenode(DocElements* prev,DocElements* next,DocElements *start,DocElements *end); std::vector<char> _Data; std::vector<char> _CStr; ssize_t** _HTable; size_t _HTableSize; HtmlElement* _RootNode; Loading Loading
src/html.cpp +23 −13 Original line number Diff line number Diff line Loading @@ -238,7 +238,9 @@ const size_t libhtmlpp::HtmlString::size() const{ } const char * libhtmlpp::HtmlString::c_str(){ return _Data.data(); _CStr=_Data; _CStr.push_back('\0'); return _CStr.data(); } libhtmlpp::HtmlElement* libhtmlpp::HtmlString::parse() { Loading Loading @@ -350,6 +352,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { std::vector<char> tmp; std::copy(_Data.begin()+lastEl->spos,_Data.begin()+lastEl->epos,std::insert_iterator<std::vector<char>>(tmp,tmp.begin())); tmp.push_back('\0'); _serialelize(tmp, (HtmlElement**) &lastEl->element); size_t epos=0; Loading Loading @@ -385,7 +388,7 @@ libhtmlpp::Element* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { return firsthel; } #include <iostream> void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlElement **out) { size_t st=0,et=0; Loading Loading @@ -414,6 +417,8 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl std::copy(in.begin()+st,in.begin()+et,std::insert_iterator<std::vector<char>>(tag,tag.begin()) ); tag.push_back('\0'); *out = new HtmlElement(tag.data()); if (!*out) { Loading @@ -429,6 +434,7 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl 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()) ); key.push_back('\0'); (*out)->setAttribute(key.data(),nullptr); startpos=-1; } Loading @@ -441,6 +447,7 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl }else if(!key.empty()){ std::vector<char> val; std::copy(in.begin()+vst+1,in.begin()+(et-1),std::insert_iterator<std::vector<char>>(val,val.begin()) ); val.push_back('\0'); (*out)->setAttribute(key.data(),val.data()); key.clear(); vst=-1; Loading Loading @@ -468,7 +475,7 @@ void libhtmlpp::HtmlString::_parseTree(){ for (size_t i = 0; i < size(); ++i) { switch (_Data[i]) { case HTMLTAG_CLOSE: if(negs<1){ if(negs<2){ ++closetag; } break; Loading Loading @@ -515,7 +522,7 @@ void libhtmlpp::HtmlString::_parseTree(){ _HTable[ip][1]=ii; break; case HTMLTAG_CLOSE: if ( negs <1 && open) { if ( negs <2 && open) { _HTable[ip][2] = ii; ++ip; open = false; Loading Loading @@ -566,6 +573,7 @@ libhtmlpp::HtmlElement::HtmlElement(const char *tagname) : Element(){ _lastAttr=nullptr; _Type=HtmlEl; std::copy(tagname,tagname+strlen(tagname),std::insert_iterator<std::vector<char>>(_TagName,_TagName.begin()) ); _TagName.push_back('\0'); } libhtmlpp::HtmlElement::HtmlElement() : Element() { Loading @@ -592,6 +600,7 @@ libhtmlpp::HtmlElement::~HtmlElement(){ void libhtmlpp::HtmlElement::setTagname(const char* name){ std::copy(name,name+strlen(name),std::insert_iterator<std::vector<char>>(_TagName,_TagName.begin()) ); _TagName.push_back('\0'); } const char* libhtmlpp::HtmlElement::getTagname() const{ Loading Loading @@ -691,7 +700,7 @@ namespace libhtmlpp { const libhtmlpp::Element *source; }; std::stack<cpyel> *cpylist = new std::stack<cpyel>; std::stack<cpyel> cpylist; NEWEL: if(src->getType()==libhtmlpp::HtmlEl && dest->getType()==libhtmlpp::HtmlEl){ Loading @@ -717,7 +726,7 @@ NEWEL: cpyel childel; childel.destin=hdest->_childElement;; childel.source=hsrc->_childElement; cpylist->push(childel); cpylist.push(childel); } }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){ ((TextElement*)dest)->setText(((TextElement*)src)->getText()); Loading @@ -739,16 +748,15 @@ NEWEL: goto NEWEL; } if(!cpylist->empty()){ cpyel childel(cpylist->top()); if(!cpylist.empty()){ cpyel childel(cpylist.top()); prev=nullptr; dest=childel.destin; src=childel.source; cpylist->pop(); cpylist.pop(); goto NEWEL; } delete cpylist; } }; Loading Loading @@ -1126,7 +1134,7 @@ void libhtmlpp::HtmlElement::setAttribute(const char* name, const char* value) { for (Attributes* curattr = _firstAttr; curattr; curattr=curattr->_nextAttr) { if(curattr->_Key.size() >= strlen(name)){ if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()) ==0 ) { if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()-1) ==0 ) { cattr = curattr; } } Loading @@ -1141,11 +1149,13 @@ void libhtmlpp::HtmlElement::setAttribute(const char* name, const char* value) { } cattr = _lastAttr; std::copy(name,name+strlen(name),std::insert_iterator<std::vector<char>>(cattr->_Key,cattr->_Key.begin()) ); cattr->_Key.push_back('\0'); } if(value) std::copy(value,value+strlen(value),std::insert_iterator<std::vector<char>>(cattr->_Value ,cattr->_Value .begin()) ); else cattr->_Value.clear(); cattr->_Value.push_back('\0'); } void libhtmlpp::HtmlElement::setIntAttribute(const char* name, int value) { Loading @@ -1156,9 +1166,9 @@ void libhtmlpp::HtmlElement::setIntAttribute(const char* name, int value) { const char* libhtmlpp::HtmlElement::getAtributte(const char* name) const{ for (Attributes* curattr = _firstAttr; curattr; curattr = curattr->_nextAttr) { if(curattr->_Key.size() > strlen(name)) if(curattr->_Key.size()-1 > strlen(name)) return nullptr; if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()) == 0 ) { if ( memcmp(curattr->_Key.data(),name,curattr->_Key.size()-1) == 0 ) { return curattr->_Value.data(); } } Loading
src/html.h +1 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,7 @@ namespace libhtmlpp { Element* _buildTree(ssize_t& pos); DocElements *_buildtreenode(DocElements* prev,DocElements* next,DocElements *start,DocElements *end); std::vector<char> _Data; std::vector<char> _CStr; ssize_t** _HTable; size_t _HTableSize; HtmlElement* _RootNode; Loading