Commit 6a77738b authored by jan.koester's avatar jan.koester
Browse files

new possiblebiliteis

parent d7ea4825
Loading
Loading
Loading
Loading
+97 −41
Original line number Diff line number Diff line
@@ -97,10 +97,23 @@ libhtmlpp::HtmlString::~HtmlString(){
}

libhtmlpp::HtmlString::HtmlString(const libhtmlpp::HtmlString& str) : HtmlString(){
    _Data=str._Data;
    *_Data=*str._Data;
}

libhtmlpp::HtmlString::HtmlString(const libhtmlpp::HtmlString* str) : HtmlString(){
    *_Data=*str->_Data;
}

libhtmlpp::HtmlString::HtmlString(const char* str) : HtmlString(){
    *_Data=str;
}

libhtmlpp::HtmlString::HtmlString(std::string* str) : HtmlString(){
    *_Data=*str;
}



void libhtmlpp::HtmlString::append(const char* src, size_t srcsize){
    _Data->append(src,srcsize);
}
@@ -145,13 +158,13 @@ libhtmlpp::HtmlString & libhtmlpp::HtmlString::operator+=(libhtmlpp::HtmlString&

libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator=(const char *src){
    clear();
    *_Data=src;
    _Data->append(src);
    return *this;
}

libhtmlpp::HtmlString & libhtmlpp::HtmlString::operator=(std::string src){
    clear();
    *_Data=src;
    _Data->append(src);
    return *this;
}

@@ -520,9 +533,15 @@ void libhtmlpp::HtmlEncode(const char* input, HtmlString* output){
}


libhtmlpp::HtmlElement::HtmlElement(const char *tagname) : HtmlElement(){
libhtmlpp::HtmlElement::HtmlElement(const char *tagname) : Element(){
    _childElement=nullptr;
    _firstAttr=nullptr;
    _lastAttr=nullptr;
    _Type=HtmlEl;
    if(tagname)
        _TagName = new std::string(tagname);
    else
        _TagName = nullptr;
}

libhtmlpp::HtmlElement::HtmlElement() : Element() {
@@ -552,11 +571,14 @@ libhtmlpp::HtmlElement::~HtmlElement(){
void libhtmlpp::HtmlElement::setTagname(const char* name){
    if(_TagName)
        delete _TagName;
    if(name)
        _TagName=new std::string(name);
}

const char* libhtmlpp::HtmlElement::getTagname() const{
    if(_TagName)
        return _TagName->c_str();
    return nullptr;
}

void libhtmlpp::HtmlElement::insertChild(libhtmlpp::Element* el){
@@ -596,6 +618,10 @@ libhtmlpp::HtmlElement & libhtmlpp::HtmlElement::operator=(const libhtmlpp::Elem
    delete _childElement;
    delete _nextElement;

    _firstAttr=nullptr;
    _childElement=nullptr;
    _nextElement=nullptr;

    _copy(nullptr,this,&hel);
    return *this;
}
@@ -605,6 +631,10 @@ libhtmlpp::HtmlElement & libhtmlpp::HtmlElement::operator=(const libhtmlpp::Elem
    delete _childElement;
    delete _nextElement;

    _firstAttr=nullptr;
    _childElement=nullptr;
    _nextElement=nullptr;

    _copy(nullptr,this,&hel);
    return *this;
}
@@ -614,14 +644,19 @@ libhtmlpp::HtmlElement & libhtmlpp::HtmlElement::operator=(const libhtmlpp::Elem
    delete _childElement;
    delete _nextElement;

    _firstAttr=nullptr;
    _childElement=nullptr;
    _nextElement=nullptr;

    _copy(nullptr,this,hel);
    return *this;
}
#include <iostream>

namespace libhtmlpp {

    void _copy(const libhtmlpp::Element* prev,libhtmlpp::Element *dest,const libhtmlpp::Element *src){

        if(!src || !dest)
            return;
        struct cpyel {
            cpyel(){

@@ -665,6 +700,7 @@ NEWEL:
            ((TextElement*)dest)->setText(((TextElement*)src)->getText());
        }

        if(prev)
            dest->_prevElement=(Element*)prev;

        Element* next=src->nextElement();
@@ -678,13 +714,15 @@ NEWEL:
             src=next;
             dest=dest->_nextElement;
             goto NEWEL;
        }else{
            dest->_nextElement=nullptr;
        }

        if(!cpylist->empty()){
            cpyel childel(cpylist->top());
            prev=nullptr;
            dest=childel.destin;
            src=childel.source;;
            src=childel.source;
            cpylist->pop();
            goto NEWEL;
        }
@@ -765,11 +803,13 @@ int libhtmlpp::Element::getType() const{
libhtmlpp::Element::Element(){
    _prevElement=nullptr;
    _nextElement=nullptr;
    _Type=-1;
}

libhtmlpp::Element::Element(const libhtmlpp::Element& el){
    _prevElement=nullptr;
    _nextElement=nullptr;
    _Type=-1;
    _copy(nullptr,this,&el);
}

@@ -827,36 +867,42 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadFile(const char* path){
        throw excp[HTMLException::Critical] << e.what();
    }

    while (fs.good()) {
        fs.read(tmp,HTML_BLOCKSIZE);
        data->append(tmp,fs.gcount());
    while (!fs.eof()) {
        size_t rd= fs.readsome(tmp,HTML_BLOCKSIZE);
        data->append(tmp,rd);
    }
    fs.close();

    libhtmlpp::HtmlElement *el=loadString(data);
    delete data;
    return el;
}

libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(const std::string *src){
    _Page=src->c_str();
    _Page = new HtmlString(src->c_str());
    return loadString(_Page);
}

libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(const char *src){
    _Page=src;
    _Page= new HtmlString(src);
    return loadString(_Page);
}

libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(HtmlString node){
libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(const HtmlString &node){
    _CheckHeader(node);
    return _Page->parse();
}

libhtmlpp::HtmlElement *libhtmlpp::HtmlPage::loadString(const HtmlString *node){
    _CheckHeader(node);
    return _Page.parse();
    return _Page->parse();
}

void libhtmlpp::HtmlPage::saveFile(const char* path){
    std::string *data=new std::string;;
    std::ofstream fs;

    print(_Page.parse(),data);
    print(_Page->parse(),data);

    try{
        fs.open(path);
@@ -994,7 +1040,6 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyID(const char *id) c
    std::stack <Element*> *childs=new std::stack <Element*>;
    const Element *curel=this;
SEARCHBYID:
    while( (curel=curel->nextElement()) ) {
    if(curel->getType()==HtmlEl){
        if(((HtmlElement*)curel)->_childElement){
            childs->push(((HtmlElement*)curel)->_childElement);
@@ -1005,12 +1050,18 @@ SEARCHBYID:
            return (HtmlElement*)curel;
        }
    }

    if(curel->nextElement()){
        curel=curel->nextElement();
        goto SEARCHBYID;
    }

    if(!childs->empty()){
        curel=childs->top();
        childs->pop();
        goto SEARCHBYID;
    }

    delete childs;
    return nullptr;
}
@@ -1019,7 +1070,6 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyTag(const char *tag)
    std::stack <Element*> *childs=new std::stack <Element*>;
    const Element *curel=this;
SEARCHBYTAG:
    while( (curel=curel->nextElement()) ) {
    if(curel->getType()==HtmlEl){
        if(((HtmlElement*)curel)->_childElement){
            HtmlElement *find=((HtmlElement*)((HtmlElement*)curel)->_childElement)->getElementbyTag(tag);
@@ -1031,12 +1081,18 @@ SEARCHBYTAG:
            return (HtmlElement*)curel;
        }
    }

    if(curel->nextElement()){
        curel=curel->nextElement();
        goto SEARCHBYTAG;
    }

    if(!childs->empty()){
        curel=childs->top();
        childs->pop();
        goto SEARCHBYTAG;
    }

    delete childs;
    return nullptr;
}
+6 −2
Original line number Diff line number Diff line
@@ -148,6 +148,9 @@ namespace libhtmlpp {
    public:
        HtmlString();
        HtmlString(const HtmlString &str);
        HtmlString(const HtmlString *str);
        HtmlString(const char *str);
        HtmlString(std::string *str);
        ~HtmlString();

        void append(const char* src, size_t srcsize);
@@ -202,10 +205,11 @@ namespace libhtmlpp {
        void         saveFile(const char* path);
        HtmlElement *loadString(const std::string *src);
        HtmlElement *loadString(const char *src);
        HtmlElement *loadString(HtmlString node);
        HtmlElement *loadString(const HtmlString &node);
        HtmlElement *loadString(const HtmlString *node);
    private:
        void         _CheckHeader(const HtmlString& page);
        HtmlString   _Page;
        HtmlString  *_Page;
    };

    class HtmlTable {