Commit a87776d2 authored by jan.koester's avatar jan.koester
Browse files

some fixes

parent 80999c21
Loading
Loading
Loading
Loading
+41 −33
Original line number Diff line number Diff line
@@ -324,12 +324,9 @@ void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libht
    };

NEXTDOCEL:
    DocElements *parent;
    if(start==firstel){
        parent=lastel;
    }else{
        parent=checkterminator(start,end);
    }

    DocElements *parent=checkterminator(start,end);


    if(prev && !start->terminator){
        start->element->_prevElement=prev->element;
@@ -342,6 +339,7 @@ NEXTDOCEL:
        childel.end=parent;
        cpylist.push(childel);
        next=parent;
        parent=nullptr;
    }

    if(!next){
@@ -420,19 +418,19 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) {
                        std::inserter<std::vector<char>>(((CommentElement*) lastEl->element)->_Comment,((CommentElement*) lastEl->element)->_Comment.begin()));
        }

        if(!lastEl->terminator){
            lastEl->element->_firstElement=firstEl->element;
        }

        size_t epos = i+1 < _HTableSize ? _HTable[i+1][0] :  _Data.size();

        size_t spos = _HTable[i][2]+1;

        if(int(epos - spos) > 0){
            addelement(&firstEl,&lastEl);
            lastEl->element=new TextElement();
            lastEl->spos = spos;
            lastEl->epos = epos;
            std::vector<char> buf;

            bool start=false;

            for(size_t i = lastEl->spos; i<lastEl->epos; ++i){
            for(size_t i = spos; i<epos; ++i){
                switch(_Data[i]){
                    case '\r':
                        continue;
@@ -443,10 +441,20 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) {
                            continue;
                    default:
                        start=true;
                        ((TextElement*)lastEl->element)->_Text.push_back(_Data[i]);
                        buf.push_back(_Data[i]);
                        continue;
                }
            }
            if(!buf.empty()){
                addelement(&firstEl,&lastEl);

                lastEl->element=new TextElement();
                lastEl->element->_firstElement=firstEl->element;
                lastEl->spos = spos;
                lastEl->epos = epos;

                ((TextElement*)lastEl->element)->_Text=buf;
            }
        }
    }

@@ -456,6 +464,8 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) {

    while(firstEl){
        DocElements *next=firstEl->nextel;
        if(firstEl->terminator)
            delete firstEl->element;
        delete firstEl;
        firstEl=next;
    }
@@ -672,9 +682,9 @@ libhtmlpp::HtmlElement::~HtmlElement(){
        cur->_prevElement=nullptr;
        if(cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement){
            childs.push(((HtmlElement*)cur)->_childElement);
            delelm.push(((HtmlElement*)cur)->_childElement);
            ((HtmlElement*)cur)->_childElement=nullptr;
        }
        delelm.push(cur);
        cur=next;
    }
    if(!childs.empty()){
@@ -685,9 +695,12 @@ libhtmlpp::HtmlElement::~HtmlElement(){

    while(!delelm.empty()){
        Element *itm=delelm.top();
        if(itm!=this)
           delete itm;
        delelm.pop();
    }

    _childElement=nullptr;
}

void libhtmlpp::HtmlElement::setTagname(const char* name){
@@ -976,15 +989,19 @@ libhtmlpp::Element::Element(const libhtmlpp::Element& el){
}

libhtmlpp::Element::~Element(){
    if(this==_firstElement){
        Element *curel=this;
   Element *curel=_firstElement;
   while(curel){
     Element *next=curel->_nextElement;
     curel->_firstElement=nullptr;
     curel->_prevElement=nullptr;
     curel->_nextElement=nullptr;
     if(curel!=this)
        delete curel;
     curel=next;
    }
    }
    _firstElement=nullptr;
    _prevElement=nullptr;
    _nextElement=nullptr;
};

libhtmlpp::TextElement::TextElement() : Element(){
@@ -1154,7 +1171,7 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){
    }
}

void libhtmlpp::print(Element* el, HtmlString &output) {
void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
    std::stack<libhtmlpp::Element*> cpylist;

    auto printag = [](Element *el,HtmlString &tag){
@@ -1173,11 +1190,6 @@ void libhtmlpp::print(Element* el, HtmlString &output) {
        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:{
@@ -1187,10 +1199,6 @@ PRINTNEXTEL:
                cpylist.push(el);
                el=((HtmlElement*) el)->_childElement;
                goto PRINTNEXTEL;
            }else {
                output.append("</");
                output.append(((HtmlElement*) el)->getTagname());
                output.append(">");
            }

            if (el->_nextElement) {
+5 −5
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ namespace libhtmlpp {
        friend class HtmlElement;
        friend class TextElement;
        friend class HtmlString;
        friend void  print(Element* el, HtmlString &output);
        friend void  print(Element* el, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

@@ -131,7 +131,7 @@ namespace libhtmlpp {

        friend class HtmlString;
        friend class HtmlTable;
        friend void  print(Element* el, HtmlString &output);
        friend void  print(Element* el, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

@@ -151,7 +151,7 @@ namespace libhtmlpp {
        std::vector<char> _Text;
        std::vector<char> _CStr;
        friend class HtmlString;
        friend void  print(Element* el, HtmlString &output);
        friend void  print(Element* el, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

@@ -171,11 +171,11 @@ namespace libhtmlpp {
        std::vector<char> _Comment;
        std::vector<char> _CStr;
        friend class HtmlString;
        friend void  print(Element* el, HtmlString &output);
        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);
    void print(Element* el, HtmlString &output,bool formated=false);

    class HtmlString {
    public: