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

bugfixes bugfixes bugfixes

parent 2ca7fdb5
Loading
Loading
Loading
Loading
+46 −69
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ bool libhtmlpp::HtmlString::validate(std::string *err){
    return erg;
}

void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libhtmlpp::DocElements *lastel){
void libhtmlpp::HtmlString::_buildtreenode(const libhtmlpp::DocElements *firstel,const libhtmlpp::DocElements *lastel){

    struct cpyel {
        cpyel(){
@@ -262,18 +262,18 @@ void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libht
            end=src.end;
        };

        libhtmlpp::DocElements *start;
        libhtmlpp::DocElements *end;
        const libhtmlpp::DocElements *start;
        const libhtmlpp::DocElements *end;
    };

    std::stack<cpyel> cpylist;

    DocElements *prev=nullptr;
    DocElements *start=firstel;
    DocElements *next=firstel->nextel;
    DocElements *end=lastel;
    const DocElements *prev=nullptr;
    const DocElements *start=firstel;
    const DocElements *next=firstel->nextel;
    const DocElements *end=lastel;

    auto checkterminator = [](DocElements *termel, DocElements *end){
    auto checkterminator = [](const DocElements *termel, const DocElements *end){
        int i=0;

        if(((Element*)(termel->element))->getType()!=HtmlEl)
@@ -349,14 +349,18 @@ NEXTDOCEL:
libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
    DocElements *firstEl = nullptr, *lastEl = nullptr;

    auto addelement = [](DocElements **first,DocElements **last){
    auto addelement = [](DocElements **first,DocElements **last,Element *element){
        if (!*first) {
            *first = new DocElements;
            (*last) = (*first);
            (*first)->element=element;
            (*first)->element->_firstElement=(*first)->element;
            *last = *first;
        } else {
            (*last)->nextel = new DocElements;
            (*last)->nextel->prevel = *last;
            (*last) = (*last)->nextel;
            (*last)->element = element;
            (*last)->element->_firstElement=(*first)->element;
        }
    };

@@ -405,13 +409,11 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
        }

        if(open!=std::string::npos &&  close !=std::string::npos && starttag!=std::string::npos){
            addelement(&firstEl,&lastEl);
            addelement(&firstEl,&lastEl,new HtmlElement());

            if(terminate!=std::string::npos)
                lastEl->terminator=true;

            lastEl->element=new HtmlElement();
            lastEl->element->_firstElement=firstEl->element;
            std::vector<char> tel;

            ++close;
@@ -432,15 +434,13 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
                    break;
                    case '>':
                        if(endcomment!=std::string::npos && ctlvl==2){
                            if(--endcomment!=std::string::npos && ctlvl==2){
                                addelement(&firstEl,&lastEl);
                                lastEl->element=new CommentElement();
                                lastEl->element->_firstElement=firstEl->element;
                            if(endcomment!=std::string::npos && ctlvl==2){
                                addelement(&firstEl,&lastEl,new CommentElement());
                                std::vector<char> cel;
                                std::copy(_Data.begin()+(comment+1),_Data.begin()+endcomment,std::inserter<std::vector<char>>(cel,cel.begin()));
                                ((CommentElement*)lastEl->element)->_Comment=cel;
                            }
                            prevclose=ii;
                            prevclose=++ii;
                            added=true;
                            goto ENDCOMMANDTAGDOUND;
                        }
@@ -477,9 +477,7 @@ ENDCOMMANDTAGDOUND:
                }
            }
            if(!buf.empty()){
                addelement(&firstEl,&lastEl);
                lastEl->element=new TextElement();
                lastEl->element->_firstElement=firstEl->element;
                addelement(&firstEl,&lastEl,new TextElement());
                std::copy(buf.begin(),buf.end(),std::inserter<std::vector<char>>(((TextElement*)(lastEl->element))->_Text,
                          ((TextElement*)lastEl->element)->_Text.begin()));
                lastEl->terminator=false;
@@ -505,23 +503,13 @@ ENDCOMMANDTAGDOUND:

    while(ft){
        DocElements *next=ft->nextel;
        Element *el=ft->element;
        switch(el->getType()){
            case HtmlEl:
                break;
            case TextEl:
                break;
            case CommentEl:
                break;
        }
        if(ft->terminator)
             first->remove(ft->element);
        ft->nextel=nullptr;
        ft->element=nullptr;
        delete ft;
        ft=next;
    }

    firstEl=nullptr;
    lastEl=nullptr;

    return first;
@@ -650,7 +638,7 @@ libhtmlpp::HtmlElement::~HtmlElement(){
        cura=next;
    }

    Element *cur=_firstElement;
    Element *cur=_childElement;

    std::stack<Element*> childs;
    std::stack<Element*> delelm;
@@ -659,16 +647,16 @@ DELETEELEMENT:
    while(cur){
        Element *next=cur->_nextElement;
        if(cur!=this){
            cur->_firstElement=nullptr;
            cur->_nextElement=nullptr;
            cur->_prevElement=nullptr;
            if(cur->getType()==HtmlEl){
                if(((HtmlElement*)cur)->_childElement){
                    childs.push(((HtmlElement*)cur)->_childElement);
                    ((HtmlElement*)cur)->_childElement=nullptr;
                }
                delelm.push(cur);
            }
            cur->_firstElement=nullptr;
            cur->_prevElement=nullptr;
            cur->_nextElement=nullptr;
            delelm.push(cur);
        }
        cur=next;
    }
@@ -678,24 +666,15 @@ DELETEELEMENT:
        goto DELETEELEMENT;
    }

    _nextElement=nullptr;
    _prevElement=nullptr;
    _childElement=nullptr;
    _firstElement=nullptr;

    if(delelm.empty())
        return;

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

    delete _nextElement;
    delete _prevElement;
    delete _childElement;
    delete _firstElement;
    _childElement=nullptr;
}

int libhtmlpp::Element::getType() const{
@@ -804,6 +783,11 @@ void libhtmlpp::HtmlElement::remove(libhtmlpp::Element* el){
DELETEELEMENT:
    while(cur){
        Element *next=cur->_nextElement;


        if(_firstElement==el)
            cur->_firstElement=_firstElement->_nextElement;

        if(cur->getType()==HtmlEl){
            if(((HtmlElement*)cur)->_childElement){
                childs.push(((HtmlElement*)cur)->_childElement);
@@ -812,7 +796,7 @@ DELETEELEMENT:
            }
        }
        if(cur==el){
            cur->_firstElement=this;
            cur->_firstElement=nullptr;
            if(cur->_prevElement)
                cur->_prevElement->_nextElement=cur->_nextElement;
            if(cur->_nextElement)
@@ -900,6 +884,8 @@ NEWEL:
            ((CommentElement*)dest)->_Comment=(((CommentElement*)src)->_Comment);
        }

        dest->_firstElement=firstdest;

        if(prev)
            dest->_prevElement=(Element*)prev;

@@ -1024,37 +1010,35 @@ libhtmlpp::Element *libhtmlpp::Element::prevElement() const{
libhtmlpp::Element::Element(){
    _prevElement=nullptr;
    _nextElement=nullptr;
    _firstElement=nullptr;
    _firstElement=this;
}

libhtmlpp::Element::Element(const libhtmlpp::Element& el) : Element() {
    _copy(this,&el);
}

#include <iostream>
libhtmlpp::Element::~Element(){
     Element *curel=_firstElement;
    _firstElement=nullptr;
    _prevElement=nullptr;
    _nextElement=nullptr;

     std::cout << "el" << this << " rm: " << _firstElement << std::endl;

     while(curel){
        Element *next=curel->_nextElement;
        curel->_firstElement=nullptr;
        curel->_prevElement=nullptr;
        curel->_nextElement=nullptr;
        if(curel!=this && curel->getType()!=HtmlEl)
            delete curel;
        if(curel!=this)
            _firstElement->remove(curel);
        curel=next;
    }
    delete _firstElement;
    delete _prevElement;
    delete _nextElement;
};

void libhtmlpp::Element::remove(libhtmlpp::Element* el){
     Element *curel=_firstElement;

     while(curel){
         Element *next=curel->_nextElement;

        if(_firstElement==el)
            curel->_firstElement=_firstElement->_nextElement;

         if(curel==el){
                curel->_firstElement=nullptr;

@@ -1066,7 +1050,6 @@ void libhtmlpp::Element::remove(libhtmlpp::Element* el){
                curel->_prevElement=nullptr;
                curel->_nextElement=nullptr;
                delete curel;
                break;
         }
        curel=next;
    }
@@ -1080,9 +1063,6 @@ libhtmlpp::TextElement::TextElement(const TextElement &texel) : TextElement(){
    _copy(this,&texel);
}

libhtmlpp::TextElement::~TextElement(){
}

libhtmlpp::TextElement & libhtmlpp::TextElement::operator=(const libhtmlpp::Element& hel){
    _copy(this,&hel);
    return *this;
@@ -1116,9 +1096,6 @@ libhtmlpp::CommentElement::CommentElement(const CommentElement &comel) : Element
    _copy(this,&comel);
}

libhtmlpp::CommentElement::~CommentElement(){
}

libhtmlpp::CommentElement & libhtmlpp::CommentElement::operator=(const libhtmlpp::Element& hel){
    _copy(this,&hel);
    return *this;
+4 −5
Original line number Diff line number Diff line
@@ -47,8 +47,6 @@ namespace libhtmlpp {

    class Element {
    public:
        Element();

        virtual ~Element();

        Element(const Element &el);
@@ -66,6 +64,9 @@ namespace libhtmlpp {

        virtual int    getType() const=0;
    protected:

        Element();

        Element*      _prevElement;
        Element*      _nextElement;
        Element*      _firstElement;
@@ -143,7 +144,6 @@ namespace libhtmlpp {
    public:
        TextElement();
        TextElement(const TextElement &texel);
        ~TextElement();

        TextElement& operator=(const Element &hel);
        TextElement& operator=(const Element *hel);
@@ -164,7 +164,6 @@ namespace libhtmlpp {
    public:
        CommentElement();
        CommentElement(const CommentElement &comel);
        ~CommentElement();

        CommentElement& operator=(const Element &hel);
        CommentElement& operator=(const Element *hel);
@@ -225,7 +224,7 @@ namespace libhtmlpp {
    private:
        void                 _serialelize(std::vector<char> in, HtmlElement* out);
        Element             *_buildTree();
        void                 _buildtreenode(DocElements *firstel,DocElements *lastel);
        void                 _buildtreenode(const DocElements *firstel,const DocElements *lastel);
        std::vector<char>    _Data;
        std::vector<char>    _CStr;
        std::stack<Element*> _Childs;
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public:

    void printModify(){
        libhtmlpp::HtmlString html;
        libhtmlpp::print(&index2,html);
        libhtmlpp::print(&index2,html,true);
        std::cout << html.c_str() << std::endl;
    }