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

test

parent 9c3ad78d
Loading
Loading
Loading
Loading
+24 −19
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <algorithm>
#include <fstream>
#include <stack>

#include "utils.h"
#include "html.h"
@@ -96,6 +95,11 @@ libhtmlpp::HtmlString::~HtmlString(){
        }
    }
    delete[]   _HTable;

    while(!_Childs.empty()){
        delete _Childs.top();
        _Childs.pop();
    }
}

libhtmlpp::HtmlString::HtmlString(const libhtmlpp::HtmlString& str) : HtmlString() {
@@ -235,28 +239,29 @@ const char * libhtmlpp::HtmlString::c_str(){
    return _CStr.data();
}

void libhtmlpp::HtmlString::parse(HtmlElement &dest) {
libhtmlpp::Element *libhtmlpp::HtmlString::parse() {
    HTMLException excp;
    _parseTree();
    long pos = 0;
    HtmlElement *buf;
    _buildTree(&buf,pos);
    dest=buf;
    delete buf;
    Element *el=_buildTree(pos);
    _Childs.push(el);
    return el;
}

bool libhtmlpp::HtmlString::validate(std::string *err){
    bool erg=false;
    try{
        _parseTree();
        long pos = 0;
        HtmlElement *buf;
        _buildTree(&buf,pos);
        Element *buf=_buildTree(pos);
        if(buf){
            erg=true;
        }
        delete buf;
        return true;
    }catch(HTMLException &e){
        *err=e.what();
    }
    return false;
    return erg;
}

void libhtmlpp::HtmlString::_buildtreenode(libhtmlpp::DocElements *firstel,libhtmlpp::DocElements *lastel){
@@ -369,7 +374,7 @@ NEXTDOCEL:
    lastel=nullptr;
}

void libhtmlpp::HtmlString::_buildTree(HtmlElement **html,long& pos) {
libhtmlpp::Element *libhtmlpp::HtmlString::_buildTree(long& pos) {
    DocElements *firstEl = nullptr, *lastEl = nullptr;

    auto addelement = [](DocElements **first,DocElements **last){
@@ -447,9 +452,9 @@ void libhtmlpp::HtmlString::_buildTree(HtmlElement **html,long& pos) {
        }
    }

    *html=(HtmlElement*)firstEl->element;
    _buildtreenode(firstEl,lastEl);

    return _buildtreenode(firstEl,lastEl);
    return firstEl->element;
}

void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlElement *out) {
@@ -1070,17 +1075,17 @@ void libhtmlpp::HtmlPage::loadFile(libhtmlpp::HtmlElement &html,const char* path

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

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

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

void libhtmlpp::HtmlPage::saveFile(libhtmlpp::HtmlElement &html,const char* path){
@@ -1423,12 +1428,12 @@ void libhtmlpp::HtmlTable::insert(libhtmlpp::HtmlElement* element){

        for(Column *ccol=crow->_firstColumn; ccol; ccol=ccol->_nextColumn ){
            HtmlString buf;
            HtmlElement element;
            Element *element;
            buf << "<td>";
            buf << ccol->Data.c_str();
            buf << "</td>";
            buf.parse(element);
            hrow.appendChild(&element);
            element=buf.parse();
            hrow.appendChild(element);
        }

        element->appendChild(&hrow);
+16 −14
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <cstring>
#include <vector>
#include <stack>

#pragma once

@@ -213,15 +214,16 @@ namespace libhtmlpp {
        void                clear();
        bool                empty();
        const char *        c_str();
        void               parse(HtmlElement &dest);
        libhtmlpp::Element *parse();
        bool                validate(std::string *err);
    private:
        void                 _parseTree();
        void                 _serialelize(std::vector<char> in, HtmlElement* out);
        void               _buildTree(HtmlElement **html,long& pos);
        Element             *_buildTree(long& pos);
        void                 _buildtreenode(DocElements *firstel,DocElements *lastel);
        std::vector<char>    _Data;
        std::vector<char>    _CStr;
        std::stack<Element*> _Childs;
        long**               _HTable;
        size_t               _HTableSize;
        friend void HtmlEncode(const char *input,HtmlString *output);