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 Original line Diff line number Diff line
@@ -324,12 +324,9 @@ void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libht
    };
    };


NEXTDOCEL:
NEXTDOCEL:
    DocElements *parent;

    if(start==firstel){
    DocElements *parent=checkterminator(start,end);
        parent=lastel;

    }else{
        parent=checkterminator(start,end);
    }


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


    if(!next){
    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()));
                        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 epos = i+1 < _HTableSize ? _HTable[i+1][0] :  _Data.size();


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


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


            bool start=false;
            bool start=false;

            for(size_t i = spos; i<epos; ++i){
            for(size_t i = lastEl->spos; i<lastEl->epos; ++i){
                switch(_Data[i]){
                switch(_Data[i]){
                    case '\r':
                    case '\r':
                        continue;
                        continue;
@@ -443,10 +441,20 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) {
                            continue;
                            continue;
                    default:
                    default:
                        start=true;
                        start=true;
                        ((TextElement*)lastEl->element)->_Text.push_back(_Data[i]);
                        buf.push_back(_Data[i]);
                        continue;
                        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){
    while(firstEl){
        DocElements *next=firstEl->nextel;
        DocElements *next=firstEl->nextel;
        if(firstEl->terminator)
            delete firstEl->element;
        delete firstEl;
        delete firstEl;
        firstEl=next;
        firstEl=next;
    }
    }
@@ -672,9 +682,9 @@ libhtmlpp::HtmlElement::~HtmlElement(){
        cur->_prevElement=nullptr;
        cur->_prevElement=nullptr;
        if(cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement){
        if(cur->_Type==HtmlEl && ((HtmlElement*)cur)->_childElement){
            childs.push(((HtmlElement*)cur)->_childElement);
            childs.push(((HtmlElement*)cur)->_childElement);
            delelm.push(((HtmlElement*)cur)->_childElement);
            ((HtmlElement*)cur)->_childElement=nullptr;
            ((HtmlElement*)cur)->_childElement=nullptr;
        }
        }
        delelm.push(cur);
        cur=next;
        cur=next;
    }
    }
    if(!childs.empty()){
    if(!childs.empty()){
@@ -685,9 +695,12 @@ libhtmlpp::HtmlElement::~HtmlElement(){


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

    _childElement=nullptr;
}
}


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


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


libhtmlpp::TextElement::TextElement() : Element(){
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;
    std::stack<libhtmlpp::Element*> cpylist;


    auto printag = [](Element *el,HtmlString &tag){
    auto printag = [](Element *el,HtmlString &tag){
@@ -1173,11 +1190,6 @@ void libhtmlpp::print(Element* el, HtmlString &output) {
        tag.append(">");
        tag.append(">");
    };
    };


    if(el->_Type==HtmlEl && strcmp(((HtmlElement*) el)->getTagname(),"!DOCTYPE") ==0 ){
        printag(el,output);
        el=((HtmlElement*) el)->_childElement;
    }

PRINTNEXTEL:
PRINTNEXTEL:
    switch(el->_Type){
    switch(el->_Type){
        case HtmlEl:{
        case HtmlEl:{
@@ -1187,10 +1199,6 @@ PRINTNEXTEL:
                cpylist.push(el);
                cpylist.push(el);
                el=((HtmlElement*) el)->_childElement;
                el=((HtmlElement*) el)->_childElement;
                goto PRINTNEXTEL;
                goto PRINTNEXTEL;
            }else {
                output.append("</");
                output.append(((HtmlElement*) el)->getTagname());
                output.append(">");
            }
            }


            if (el->_nextElement) {
            if (el->_nextElement) {
+5 −5
Original line number Original line Diff line number Diff line
@@ -72,7 +72,7 @@ namespace libhtmlpp {
        friend class HtmlElement;
        friend class HtmlElement;
        friend class TextElement;
        friend class TextElement;
        friend class HtmlString;
        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);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
    };


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


        friend class HtmlString;
        friend class HtmlString;
        friend class HtmlTable;
        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);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
    };


@@ -151,7 +151,7 @@ namespace libhtmlpp {
        std::vector<char> _Text;
        std::vector<char> _Text;
        std::vector<char> _CStr;
        std::vector<char> _CStr;
        friend class HtmlString;
        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);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
    };


@@ -171,11 +171,11 @@ namespace libhtmlpp {
        std::vector<char> _Comment;
        std::vector<char> _Comment;
        std::vector<char> _CStr;
        std::vector<char> _CStr;
        friend class HtmlString;
        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);
        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 {
    class HtmlString {
    public:
    public: