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

fixed wrong formating

parent 9ae2800c
Loading
Loading
Loading
Loading
+93 −36
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define HTMLTAG_OPEN '<'
#define HTMLTAG_TERMINATE '/'
#define HTMLTAG_CLOSE '>'
#define HTMLTAG_COMMENT '!'

namespace libhtmlpp {

@@ -245,7 +246,8 @@ void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libht

    struct cpyel {
        cpyel(){

            start=nullptr;
            end=nullptr;
        };

        cpyel(const cpyel &src){
@@ -379,7 +381,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
                    close = ii;
                }
                break;
            case '!':
            case HTMLTAG_COMMENT:
                if(open!=std::string::npos && close ==std::string::npos){
                    if( ii+3 < _Data.size() && _Data[ii+1]=='-' && _Data[ii+2]=='-'){
                        comment=(ii+=2);
@@ -419,17 +421,7 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
                    ++ctlvl;
                    break;
                    case '>':
                        if(endcomment!=std::string::npos && ctlvl==2)
                            goto ENDCOMMANDTAGDOUND;
                    break;
                    default:
                        ctlvl=0;
                        endcomment=std::string::npos;
                        break;
                }
                ++ii;
            }
            ENDCOMMANDTAGDOUND:
                        if(endcomment!=std::string::npos && ctlvl==2){
                            if(--endcomment!=std::string::npos && ctlvl==2){
                                addelement(&firstEl,&lastEl);
                                lastEl->element=new CommentElement();
@@ -438,11 +430,20 @@ libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree() {
                                std::copy(_Data.begin()+(comment+1),_Data.begin()+endcomment,std::inserter<std::vector<char>>(cel,cel.begin()));
                                ((CommentElement*)lastEl->element)->_Comment=cel;
                            }

                            prevclose=ii;
                            added=true;
                            goto ENDCOMMANDTAGDOUND;
                        }

                        break;
                    default:
                        ctlvl=0;
                        endcomment=std::string::npos;
                        break;
                }
                ++ii;
            }
        }
ENDCOMMANDTAGDOUND:
        if(prevclose!=std::string::npos && open!=std::string::npos
            && int(open-(prevclose+1)) > 0){
            std::vector<char> buf;
@@ -745,11 +746,14 @@ void libhtmlpp::HtmlElement::appendChild(libhtmlpp::Element* el){
                ex[HTMLException::Critical] << "appendChild: Unknown html element found: "<< el->getType() << " !";
                throw ex;
        }

        _copy(curel,el);

        if(prev){
            prev->_nextElement=curel;
            curel->_prevElement=prev;
        }
        _copy(curel,el);

    }else{
        insertChild(el);
    }
@@ -834,8 +838,15 @@ namespace libhtmlpp {
                source=src.source;
            };

            ~cpyel(){
                destin=nullptr;
                source=nullptr;
                delete destin;
                delete source;
            }

            libhtmlpp::Element *destin;
            const libhtmlpp::Element *source;
            libhtmlpp::Element *source;
        };

        std::stack<cpyel> cpylist;
@@ -869,7 +880,7 @@ NEWEL:
                        throw ex;
                }
                cpyel childel;
                childel.destin=((libhtmlpp::HtmlElement*)dest)->_childElement;;
                childel.destin=((libhtmlpp::HtmlElement*)dest)->_childElement;
                childel.source=((libhtmlpp::HtmlElement*)src)->_childElement;
                cpylist.push(childel);
            }
@@ -1055,7 +1066,7 @@ void libhtmlpp::Element::remove(libhtmlpp::Element* el){
libhtmlpp::TextElement::TextElement() : Element(){
}

libhtmlpp::TextElement::TextElement(const TextElement &texel) : Element(){
libhtmlpp::TextElement::TextElement(const TextElement &texel) : TextElement(){
    _copy(this,&texel);
}

@@ -1153,18 +1164,30 @@ void libhtmlpp::HtmlPage::loadFile(libhtmlpp::HtmlElement &html,const char* path
}

void libhtmlpp::HtmlPage::loadString(libhtmlpp::HtmlElement &html,const std::string &src){
    HtmlString buf(src);
    html=(HtmlElement*)buf.parse();
    HtmlString buf=src;
    Element *el=buf.parse();
    _copy(&html,el);
}

void libhtmlpp::HtmlPage::loadString(libhtmlpp::HtmlElement &html,const char *src){
    HtmlString buf=src;
    html=(HtmlElement*)buf.parse();
    Element *el=buf.parse();
    _copy(&html,el);
}

void libhtmlpp::HtmlPage::loadString(libhtmlpp::HtmlElement &html,const HtmlString &node){
    HtmlString buf=node;
    html=(HtmlElement*)buf.parse();
    Element *el=buf.parse();
    _copy(&html,el);
}

void loadString(libhtmlpp::HtmlElement &html,const libhtmlpp::HtmlString *node){
    if(!node){
        libhtmlpp::HTMLException excp;
        throw excp[libhtmlpp::HTMLException::Critical] << "loadstring: node can't be null !";
    }
    libhtmlpp::HtmlString buf=*node;
    html=(libhtmlpp::HtmlElement*)buf.parse();
}

void libhtmlpp::HtmlPage::saveFile(libhtmlpp::HtmlElement &html,const char* path){
@@ -1235,7 +1258,16 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) {

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

    int lvl=0;

    PRINTNEXTEL:

    if(formated){
        for(int i=0; i<lvl; ++i){
            output.append("    ");
        }
    }

    switch(el->getType()){
        case HtmlEl:{
            output.append("<");
@@ -1249,38 +1281,50 @@ PRINTNEXTEL:
                    output.append("\"");
                }
            }
            if(((HtmlElement*) el)->_childElement || el->_nextElement ){
                output.append(">");
            }else{
                output.append("</");
                output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size());

            output.append(">");
            }

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

            if(strcmp(((HtmlElement*) el)->getTagname(),"div")==0){
                output.append("</");
                output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size());
                output.append(">");
            }

            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement;
                goto PRINTNEXTEL;
            }

        }break;

        case TextEl :{
            output.append(((TextElement*)el)->_Text.data(),((TextElement*)el)->_Text.size());
            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement;
                goto PRINTNEXTEL;
            }

        }break;
        case CommentEl: {
            output.append("<!--");
            output.append(((CommentElement*)el)->_Comment.data(),((CommentElement*)el)->_Comment.size());
            output.append("-->");
            if(formated)
                output.append("\r\n");

            if (el->_nextElement) {
                el=el->_nextElement;
@@ -1293,19 +1337,32 @@ PRINTNEXTEL:
            throw excp;
            break;
    }

    while(!cpylist.empty()){
        el=cpylist.top();

        if(formated){
            for(int i=0; i<lvl; ++i){
                output.append("    ");
            }
        }

        output.append("</");
        output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size());
        output.append(">");

        if(formated)
                output.append("\r\n");

        --lvl;

        cpylist.pop();
        if (el->_nextElement) {
            el=el->_nextElement;
            goto PRINTNEXTEL;
        }
    }

}

libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyID(const char *id) const{
+1 −0
Original line number Diff line number Diff line
@@ -230,6 +230,7 @@ namespace libhtmlpp {
        std::vector<char>    _CStr;
        std::stack<Element*> _Childs;
        friend void HtmlEncode(const char *input,HtmlString *output);
        friend class HtmlPage;
    };

    void HtmlEncode(const char *input,HtmlString *output);