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

needs rework

parent a97cdf88
Loading
Loading
Loading
Loading
+38 −37
Original line number Diff line number Diff line
@@ -1384,7 +1384,10 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){

}

void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
void libhtmlpp::print(const Element &element, HtmlString &output,bool formated) {

    const Element *el=&element;

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

    std::stack<libhtmlpp::Element*> cpylist;
    std::stack<const libhtmlpp::Element*> cpylist;

    int lvl=0;

@@ -1407,12 +1410,11 @@ void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
        }
    }

    switch(el.getType()){
    switch(el->getType()){
        case HtmlEl:{
            HtmlElement* htmlel = dynamic_cast<HtmlElement*>(&el);
            output.append("<");
            output.append(htmlel->getTagname());
            for (HtmlElement::Attributes* curattr = htmlel->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
            output.append(reinterpret_cast<const HtmlElement*>(el)->getTagname());
            for (HtmlElement::Attributes* curattr = reinterpret_cast<const HtmlElement*>(el)->_firstAttr.get(); curattr; curattr = curattr->_nextAttr.get()) {
                output.append(" ");
                std::copy(
                    curattr->_Key.begin(),
@@ -1437,21 +1439,21 @@ void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
                virgin=false;
            }

            if (htmlel->_childElement) {
            if (reinterpret_cast<const HtmlElement*>(el)->_childElement) {
                if(formated)
                    output.append("\r\n");
                cpylist.push(&el);
                el=htmlel->_childElement.get();
                cpylist.push(el);
                el=reinterpret_cast<const HtmlElement*>(el)->_childElement.get();
                ++lvl;
                goto PRINTNEXTEL;
            }

            //Container must be always terminated fuck html5
            if(isContainer(htmlel->getTagname())){
            if(isContainer(reinterpret_cast<const HtmlElement*>(el)->getTagname())){
                output.append("</");
                std::copy(
                    htmlel->_TagName.begin(),
                          htmlel->_TagName.end(),
                    reinterpret_cast<const HtmlElement*>(el)->_TagName.begin(),
                          reinterpret_cast<const HtmlElement*>(el)->_TagName.end(),
                          std::back_inserter(output)
                );
                output.append(">");
@@ -1460,46 +1462,46 @@ void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
            if(formated)
                output.append("\r\n");

            if (htmlel->_nextElement) {
                el=htmlel->_nextElement.get();
            if (el->_nextElement) {
                el=el->_nextElement.get();
                goto PRINTNEXTEL;
            }
        }break;

        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 +1527,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){
@@ -1541,8 +1543,8 @@ void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
            if(formated)
                output.append("\r\n");

            if (el._nextElement) {
                el=el._nextElement.get();
            if (el->_nextElement) {
                el=el->_nextElement.get();
                goto PRINTNEXTEL;
            }
        }break;
@@ -1575,8 +1577,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){
@@ -1591,8 +1593,8 @@ void libhtmlpp::print(Element &el, HtmlString &output,bool formated) {
            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 +1618,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,12 +1628,11 @@ 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;
        }
    }

}

libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyID(const std::string &id) const{
+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(const Element& element, 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(const Element& element, 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(const Element& element, 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(const Element& element, 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(const Element& element, 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(const Element& element, 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(const Element& element, HtmlString &output,bool formated=false);

    class HtmlString {
    public: