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

fixed api

parent 2ba75d0f
Loading
Loading
Loading
Loading
+39 −39
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ namespace libhtmlpp {
        "footer",
        "header",
        "main",
        "html",
        nullptr
    };

@@ -311,8 +312,6 @@ void libhtmlpp::HtmlString::_buildtreenode(DocElements *firstel,
    size_t counter =0;

NEXTDOCEL:
    std::cout << "start" << start->element.get() << std::endl;

    if(!start->element){
         HTMLException e;
         e[HTMLException::Error] << "start not found this shouldn't happend in line: " << counter << "!";
@@ -328,7 +327,6 @@ NEXTDOCEL:
    }

    if(parent && parent!=next){
        std::cout << "child" << parent << std::endl;
        ((HtmlElement*)(start->element.get()))->_childElement=std::move(next->element);
        cpyel childel;
        childel.start=next->nextel.get();
@@ -354,6 +352,9 @@ NEXTDOCEL:

    if(!cpylist.empty()){
        cpyel childel(cpylist.top());

        std::cerr << childel.start->element->getType() << std::endl;

        prev=nullptr;
        start=childel.start;
        end=childel.end;
@@ -361,7 +362,6 @@ NEXTDOCEL:
        cpylist.pop();
        goto NEXTDOCEL;
    }

}

void libhtmlpp::HtmlString::_buildTree() {
@@ -512,13 +512,13 @@ void libhtmlpp::HtmlString::_buildTree() {
        }
    }

    for(DocElements *cur=firstEl.get(); cur; cur=cur->nextel.get()){
        std::cout << cur->element->getType() << std::endl;
    }

    _buildtreenode(firstEl.get(),lastEl);

    _rootEl=std::move(firstEl->element);

    HtmlString test;
    print(*_rootEl,test,true);
    std::cout  << "test" << test.c_str() << "test" << std::endl;
}

void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlElement *out) {
@@ -1284,7 +1284,7 @@ void libhtmlpp::HtmlPage::saveFile(libhtmlpp::HtmlElement &html,const std::strin
    HtmlString data;
    std::ofstream fs;

    print(&html,data);
    print(html,data);

    try{
        fs.open(path);
@@ -1384,7 +1384,7 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){

}

void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
    auto isContainer = [](const std::string &tagname) {
        for(int i=0; ContainerTypes[i]; ++i){
            if(std::equal(tagname.begin(),tagname.end(),ContainerTypes[i]))
@@ -1407,9 +1407,9 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
        }
    }

    switch(el->getType()){
    switch(el.getType()){
        case HtmlEl:{
            HtmlElement* htmlel = dynamic_cast<HtmlElement*>(el);
            HtmlElement* htmlel = dynamic_cast<HtmlElement*>(&el);
            output.append("<");
            output.append(htmlel->getTagname());
            for (HtmlElement::Attributes* curattr = htmlel->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
@@ -1440,7 +1440,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
            if (htmlel->_childElement) {
                if(formated)
                    output.append("\r\n");
                cpylist.push(el);
                cpylist.push(&el);
                el=htmlel->_childElement.get();
                ++lvl;
                goto PRINTNEXTEL;
@@ -1468,38 +1468,38 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {

        case TextEl :{
            std::copy(
                ((TextElement*)el)->_Text.begin(),
                      ((TextElement*)el)->_Text.end(),
                ((TextElement*)&el)->_Text.begin(),
                      ((TextElement*)&el)->_Text.end(),
                      std::back_inserter(output)
            );
            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement.get();
            if (el._nextElement) {
                el=el._nextElement.get();
                goto PRINTNEXTEL;
            }
        }break;
        case CommentEl: {
            output.append("<!--");
            std::copy(
                ((CommentElement*)el)->_Comment.begin(),
                      ((CommentElement*)el)->_Comment.end(),
                ((CommentElement*)&el)->_Comment.begin(),
                      ((CommentElement*)&el)->_Comment.end(),
                      std::back_inserter(output)
            );
            output.append("-->");
            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement.get();
            if (el._nextElement) {
                el=el._nextElement.get();
                goto PRINTNEXTEL;
            }
        }break;
        case ScriptEL:{
            output.append("<");
            output.append(((ScriptElement*) el)->getTagname());
            for (ScriptElement::Attributes* curattr = ((ScriptElement*) el)->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
            output.append(((ScriptElement*) &el)->getTagname());
            for (ScriptElement::Attributes* curattr = ((ScriptElement*) &el)->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
                output.append(" ");
                std::copy(
                    curattr->_Key.begin(),
@@ -1525,8 +1525,8 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
                }
            }
            std::copy(
                ((ScriptElement*)el)->_Script.begin(),
                      ((ScriptElement*)el)->_Script.end(),
                ((ScriptElement*)&el)->_Script.begin(),
                      ((ScriptElement*)&el)->_Script.end(),
                      std::back_inserter(output)
            );
            if(formated){
@@ -1536,20 +1536,20 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
                }
            }
            output.append("</");
            output.append(((ScriptElement*) el)->getTagname());
            output.append(((ScriptElement*) &el)->getTagname());
            output.append(">");
            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement.get();
            if (el._nextElement) {
                el=el._nextElement.get();
                goto PRINTNEXTEL;
            }
        }break;
        case SvgEL:{
            output.append("<");
            output.append(((SvgElement*) el)->getTagname());
            for (SvgElement::Attributes* curattr = ((SvgElement*) el)->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
            output.append(((SvgElement*) &el)->getTagname());
            for (SvgElement::Attributes* curattr = ((SvgElement*)&el)->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
                output.append(" ");
                std::copy(
                    curattr->_Key.begin(),
@@ -1575,8 +1575,8 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
                }
            }
            std::copy(
                ((SvgElement*)el)->_Svg.begin(),
                      ((SvgElement*)el)->_Svg.end(),
                ((SvgElement*)&el)->_Svg.begin(),
                      ((SvgElement*)&el)->_Svg.end(),
                      std::back_inserter(output)
            );
            if(formated){
@@ -1586,13 +1586,13 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
                }
            }
            output.append("</");
            output.append(((SvgElement*) el)->getTagname());
            output.append(((SvgElement*) &el)->getTagname());
            output.append(">");
            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement.get();
            if (el._nextElement) {
                el=el._nextElement.get();
                goto PRINTNEXTEL;
            }
        }break;
@@ -1616,8 +1616,8 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {

        output.append("</");
        std::copy(
            ((HtmlElement*) el)->_TagName.begin(),
                  ((HtmlElement*) el)->_TagName.end(),
            ((HtmlElement*) &el)->_TagName.begin(),
                  ((HtmlElement*) &el)->_TagName.end(),
                  std::back_inserter(output)
        );
        output.append(">");
@@ -1626,8 +1626,8 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {
            output.append("\r\n");

        cpylist.pop();
        if (el->_nextElement) {
            el=el->_nextElement.get();
        if (el._nextElement) {
            el=el._nextElement.get();
            goto PRINTNEXTEL;
        }
    }
+7 −7
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ namespace libhtmlpp {
        friend class HtmlElement;
        friend class TextElement;
        friend class HtmlString;
        friend void  print(Element* el, HtmlString &output,bool formated);
        friend void  print(Element& el, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

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

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

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

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

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

        std::vector<char> _Script;
        friend class HtmlString;
        friend void  print(Element* el, HtmlString &output,bool formated);
        friend void  print(Element& el, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

@@ -236,11 +236,11 @@ namespace libhtmlpp {

        std::vector<char> _Svg;
        friend class HtmlString;
        friend void  print(Element* el, HtmlString &output,bool formated);
        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,bool formated=false);
    void print(Element& el, HtmlString &output,bool formated=false);

    class HtmlString {
    public:
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public:

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

@@ -71,7 +71,7 @@ int main(int arc,char *argv[]){
        libhtmlpp::HtmlString html;

        std::cout << "Orginal html:" << std::endl;
        libhtmlpp::print(&index,html,true);
        libhtmlpp::print(index,html,true);
        std::cout << html.str() << std::endl;

        std::cout << "Modified html:" << std::endl;
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public:

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

@@ -71,7 +71,7 @@ int main(int arc,char *argv[]){
        libhtmlpp::HtmlString html;

        std::cout << "Orginal html:" << std::endl;
        libhtmlpp::print(&index,html,true);
        libhtmlpp::print(index,html,true);
        std::cout << html.str() << std::endl;

        std::cout << "Modified html:" << std::endl;
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ int main(int arc,char *argv[]){
        libhtmlpp::HtmlElement index;
        page.loadFile(index,argv[1]);
        libhtmlpp::HtmlString html;
        libhtmlpp::print(&index,html,true);
        libhtmlpp::print(index,html,true);
        std::cout << html.str() << std::endl;
        std::cout << Green << "Test Passed!" << NOCOLOR << std::endl;
        if(page.isHtml5()){