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

more operators

parent 9a312540
Loading
Loading
Loading
Loading
+32 −19
Changes for src/html.cpp: 32 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -500,11 +500,12 @@ void libhtmlpp::HtmlElement::appendChild(libhtmlpp::Element* el){
    }
}

libhtmlpp::Element& libhtmlpp::HtmlElement::operator=(const Element &hel){
libhtmlpp::HtmlElement & libhtmlpp::HtmlElement::operator=(const libhtmlpp::Element& hel){
    _copy(nullptr,this,&hel);
    return *this;
}


namespace libhtmlpp {
    void _copy(const libhtmlpp::Element* prev,libhtmlpp::Element *dest,const libhtmlpp::Element *src){
        if(src->getType()==libhtmlpp::HtmlEl && dest->getType()==libhtmlpp::HtmlEl){
@@ -542,37 +543,49 @@ namespace libhtmlpp {
void libhtmlpp::Element::insertBefore(libhtmlpp::Element* el){
    if(el->getType()==HtmlEl){
        HtmlElement *nel=new HtmlElement();
        *nel=*((libhtmlpp::HtmlElement*)el);
        _copy(nullptr,nel,el);
        _prevElement->_nextElement=nel;

    }else if(el->getType()==TextEl){
        TextElement *txt= new TextElement;
        *txt=*el;
        _copy(nullptr,txt,el);
        _prevElement->_nextElement=txt;
    }
    Element *nexel;
    do{
        nexel=el->_nextElement;
    }while(nexel!=nullptr);
    Element *nexel=_prevElement->_nextElement,*prev=nullptr;

    while(nexel){
        prev=nexel;
        nexel=nexel->nextElement();
    }

    nexel->_nextElement=_nextElement;
    nexel=this;
    _prevElement=prev;
}

void libhtmlpp::Element::insertAfter(libhtmlpp::Element* el){
    Element *nexel=nullptr,*prev=_nextElement;

    if(el->getType()==HtmlEl){
        HtmlElement *nel=new HtmlElement();
        *nel=*((libhtmlpp::HtmlElement*)el);
        nel->_nextElement=_nextElement;
        _nextElement=nel;
        _copy(this,nel,el);
        nexel=nel;
    }else if(el->getType()==TextEl){
        TextElement *txt= new TextElement;
        *txt=*el;
        _nextElement=txt;
        _copy(this,txt,el);
        nexel=txt;
    }

    _nextElement=nexel;

    while(nexel){
        nexel=nexel->nextElement();
    }

    nexel=prev;

}

libhtmlpp::Element& libhtmlpp::Element::operator=(const Element &hel){
    _copy(nullptr,this,&hel);
    return *this;
}

@@ -584,16 +597,16 @@ libhtmlpp::Element *libhtmlpp::Element::prevElement() const{
    return _prevElement;
}

libhtmlpp::Element & libhtmlpp::TextElement::operator=(const libhtmlpp::Element& hel){
int libhtmlpp::Element::getType() const{
    return _Type;
}

libhtmlpp::TextElement & libhtmlpp::TextElement::operator=(const libhtmlpp::Element& hel){
    _copy(nullptr,this,&hel);
    return *this;
}


int libhtmlpp::Element::getType() const{
    return _Type;
}

void libhtmlpp::TextElement::setText(const char* txt){
    _Text=txt;
}
+3 −3
Changes for src/html.h: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ namespace libhtmlpp {
        void insertAfter(Element* el);
        void insertBefore(Element* el);

        virtual Element& operator=(const Element &hel)=0;
        Element& operator=(const Element &hel);

        Element*       nextElement() const;
        Element*       prevElement() const;
@@ -82,7 +82,7 @@ namespace libhtmlpp {
        HtmlElement(const HtmlElement &hel) = delete;
        ~HtmlElement();

        Element&     operator=(const Element &hel);
        HtmlElement& operator=(const Element &hel);

        void         setAttribute(const char* name, const char* value);
        void         setIntAttribute(const char* name, int value);
@@ -130,7 +130,7 @@ namespace libhtmlpp {
        TextElement(const TextElement &texel) = delete;
        ~TextElement();

        Element&    operator=(const Element &hel);
        TextElement& operator=(const Element &hel);

        const char *getText();
        void        setText(const char *txt);
+5 −3
Changes for test/htmlcopytest.cpp: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -65,15 +65,17 @@ int main(int arc,char *argv[]){

        HtmlCopy cpy(index);

        std::cout << "Modified html:" << std::endl;

        cpy.printModify();

        std::string html;

        std::cout << "Orginal html:" << std::endl;
        libhtmlpp::print(index,nullptr,html);

        std::cout << "Modified html:" << std::endl;

        cpy.printModify();


        std::cout << html << std::endl;
        std::cout << Green << "Test Passed!" << NOCOLOR << std::endl;
    }catch(libhtmlpp::HTMLException &exp){