Commit 1c8044ce authored by jan.koester's avatar jan.koester
Browse files

some fixes

parent 74d6d030
Loading
Loading
Loading
Loading
+50 −27
Original line number Diff line number Diff line
@@ -345,7 +345,7 @@ NEXTDOCEL:
        goto NEXTDOCEL;
    }
}

#include <iostream>
libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
    DocElements *firstEl = nullptr, *lastEl = nullptr;

@@ -411,9 +411,9 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
        if(open!=std::string::npos &&  close !=std::string::npos && starttag!=std::string::npos){
            addelement(&firstEl,&lastEl,new HtmlElement());

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

            }
            std::vector<char> tel;

            ++close;
@@ -495,7 +495,7 @@ ENDCOMMANDTAGDOUND:
        }
    }

    Element *first = firstEl->element;
    HtmlElement *first = (HtmlElement*)firstEl->element;

    _buildtreenode(firstEl,lastEl);

@@ -638,37 +638,40 @@ libhtmlpp::HtmlElement::~HtmlElement(){
        cura=next;
    }

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

    std::stack<Element*> childs;
    std::stack<HtmlElement*> parents;
    std::stack<Element*> delelm;

DELETEELEMENT:

    while(cur){
        Element *next=cur->_nextElement;
        if(cur->getType()==HtmlEl){
            if(((HtmlElement*)cur)->_childElement){
                childs.push(((HtmlElement*)cur)->_childElement);
                ((HtmlElement*)cur)->_childElement=nullptr;
                parents.push((HtmlElement*)cur);
                cur=((HtmlElement*)cur)->_childElement;
            }
        }
        Element *next=cur->_nextElement;
        cur->_firstElement=nullptr;
        cur->_prevElement=nullptr;
        cur->_nextElement=nullptr;
        delelm.push(cur);

        cur=next;
    }
    if(!childs.empty()){
        cur=childs.top();
        childs.pop();

    if(!parents.empty()){
        cur=parents.top();
        ((HtmlElement*)cur)->_childElement=nullptr;
        parents.pop();
        goto DELETEELEMENT;
    }

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

}

@@ -773,31 +776,43 @@ libhtmlpp::HtmlElement & libhtmlpp::HtmlElement::operator=(const libhtmlpp::Html
void libhtmlpp::HtmlElement::remove(libhtmlpp::Element* el){
    Element *cur=_firstElement;

    std::stack<Element*> childs,dels;
    std::stack<Element*> parents;

DELETEELEMENT:
    while(cur){
        Element *next=cur->_nextElement;
        if(cur->_firstElement==el)
            cur->_firstElement=el->_nextElement;

        if(cur->getType()==HtmlEl){
            if(((HtmlElement*)cur)->_childElement){
                childs.push(((HtmlElement*)cur)->_childElement);
                dels.push(((HtmlElement*)cur)->_childElement);
                parents.push(cur);
                cur=((HtmlElement*)cur)->_childElement;
            }
        }

        if(cur==el){
            if(cur->_prevElement)
                cur->_prevElement->_nextElement=cur->_nextElement;
            if(cur->_nextElement)
                cur->_nextElement->_prevElement=cur->_prevElement;
            cur->_nextElement=nullptr;
            cur->_prevElement=nullptr;
            cur->_firstElement=nullptr;
            delete cur;
            return;
        }

        Element *next=cur->_nextElement;
        cur=next;
    }
    if(!childs.empty()){
        cur=childs.top();
        childs.pop();

    if(!parents.empty()){
        cur=parents.top()->nextElement();
        parents.pop();
        if(cur!=el)
            goto DELETEELEMENT;
    }

    while(!dels.empty()){
        Element::remove(dels.top());
        dels.pop();
    }

}

@@ -1048,6 +1063,10 @@ 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;
@@ -1081,6 +1100,10 @@ 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;
+2 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ namespace libhtmlpp {
    public:
        TextElement();
        TextElement(const TextElement &texel);
        ~TextElement();

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

        CommentElement& operator=(const Element &hel);
        CommentElement& operator=(const Element *hel);