Commit 3a2881d5 authored by jan.koester's avatar jan.koester
Browse files

some cleanups

parent 47fb4b24
Loading
Loading
Loading
Loading
+16 −16
Changes for src/html.cpp: 16 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -164,14 +164,16 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(ssize_t &pos){
        bool             terminator;
        struct el*       nextel;
        struct el*       prevel;
        size_t           pos;
        size_t           spos;
        size_t           epos;

        el() {
            nextel = nullptr;
            prevel = nullptr;
            elhtml = nullptr;
            terminator = false;
            pos = 0;
            spos = 0;
            epos = 0;
        }

        ~el() {
@@ -187,7 +189,8 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(ssize_t &pos){
		if (!firstEl) {
			firstEl = new el;
			lastEl = firstEl;
            }else {
		}
		else {

			lastEl->nextel = new el;
			lastEl->nextel->prevel = lastEl;
@@ -199,10 +202,10 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(ssize_t &pos){
		if (lastEl->data[0] == '/')
			lastEl->terminator = true;

            _serialelize(lastEl->data, &lastEl->elhtml);

            lastEl->pos = i;
        lastEl->spos = _HTable[i][0];
        lastEl->epos = _HTable[i][2];

		_serialelize(lastEl->data, &lastEl->elhtml);
    }

    int lvl = 0;
@@ -226,7 +229,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(ssize_t &pos){
	for (el* curel = firstEl; curel; curel = curel->nextel) {
        if (curel->terminator) {
		    for (el* parent = lastEl; parent; parent = parent->prevel) {
                if ((curel->pos-parent->pos)>1 && parent->elhtml->_TagName == curel->elhtml->_TagName){
                if (parent->elhtml->_TagName == curel->elhtml->_TagName){
                        parent->elhtml->_Child = parent->elhtml->_nextElement;
                        if (parent->elhtml->_nextElement)
                            parent->elhtml->_nextElement->_prevElement = nullptr;
@@ -241,6 +244,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(ssize_t &pos){
                            }
                            endcur = endcur->nextel;
                        }

                }
		    }
        }
@@ -251,6 +255,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(ssize_t &pos){
    return firsthel;
}


void libhtmlpp::HtmlString::_serialelize(sys::array<char> in, HtmlElement **out) {
    int i,s=0;

@@ -449,6 +454,7 @@ void libhtmlpp::HtmlPage::loadFile(const char* path){

void libhtmlpp::HtmlElement::_print(HtmlElement* child) {
    for (HtmlElement* cur = child; cur; cur = cur->_nextElement) {
        if (!cur->_TagName.empty() && _Text.empty()) {
            _Cstr.append("<");
            _Cstr.append(cur->_TagName.c_str());
            for (HtmlElement::HtmlAttributes* curattr = cur->_firstAttr; curattr; curattr = curattr->_nextAttr) {
@@ -459,11 +465,13 @@ void libhtmlpp::HtmlElement::_print(HtmlElement* child) {
                _Cstr.append("\"");
            }
            _Cstr.append(">");
        if (cur->_Child) {
            if (cur->_Child)
                _print(cur->_Child);
            _Cstr.append("</");
            _Cstr.append(cur->_TagName.c_str());
            _Cstr.append(">");
        } else {
            _Cstr.append(_Text.c_str());
        }
    }
}
@@ -519,14 +527,6 @@ libhtmlpp::HtmlElement::HtmlAttributes::~HtmlAttributes() {
    delete _nextAttr;
}

libhtmlpp::HtmlText::HtmlText() {

}

libhtmlpp::HtmlText::~HtmlText() {

}

libhtmlpp::HtmlTable::HtmlTable() : HtmlElement("table") {
}

+52 −54
Changes for src/html.h: 52 added lines, 54 removed lines.
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

namespace libhtmlpp {

    class HtmlElement {
    public:
        HtmlElement(const char* tag);
@@ -44,6 +45,11 @@ namespace libhtmlpp {
        int         getIntAtributte(const char* name);

        const char* printHtmlElement();

        void insertText(const char* text) {

        }

    protected:

        void              _print(HtmlElement* child);
@@ -61,8 +67,8 @@ namespace libhtmlpp {

    private:
        sys::array<char> _TagName;
        sys::array<char> _Text;
        sys::array<char> _Cstr;
        sys::array<char> _Text;

        HtmlAttributes* _firstAttr;
        HtmlAttributes* _lastAttr;
@@ -70,6 +76,51 @@ namespace libhtmlpp {
        friend class HtmlString;
    };

    class HtmlText : public HtmlElement {

    };

    class HtmlDivLayer : public HtmlElement {
    public:
        HtmlDivLayer();
        ~HtmlDivLayer();
    private:
    };

    class HtmlTable : public HtmlElement {
    public:
        HtmlTable();
        ~HtmlTable();
        class Row {
        public:
            Row& operator<<(const char* value);
            Row& operator<<(int value);
        private:
            Row();
            ~Row();
            Row* _nextRow;
            friend class HtmlTable;
        };
    private:
    };

    class HtmlPage {
    public:
        HtmlPage();
        ~HtmlPage();
        void loadFile(const char* path);
        void saveFile(const char* path);

        void   fromString(const char* src);
        size_t toString(const char** dest);

        void addElement(HtmlElement* element);
        const char* printHtml();
    private:
        sys::array<char>     _DocType;
        HtmlElement* _RootNode;
    };

    class HtmlString {
    public:
        HtmlString();
@@ -109,57 +160,4 @@ namespace libhtmlpp {
        size_t                  _HTableSize;
        HtmlElement* _RootNode;
    };

    class HtmlPage {
    public:
        HtmlPage();
        ~HtmlPage();
        void loadFile(const char *path);
        void saveFile(const char *path);
        
        void   fromString(const char *src);
        size_t toString(const char **dest);
        
        void addElement(HtmlElement *element);
        const char *printHtml();
    private:
        sys::array<char>     _DocType;
        HtmlElement         *_RootNode;
    };

    class HtmlText{
    public:
        HtmlText();
        ~HtmlText();
        void insertTextBefore();
        void insertTextAfter();
    private:
        sys::array<char>  _Text;
        bool              _Before;
        HtmlElement      *_Element;
    };

    class HtmlDivLayer : public HtmlElement {
    public:
        HtmlDivLayer();
        ~HtmlDivLayer();
    private:
    };

    class HtmlTable : public HtmlElement{
    public:
        HtmlTable();
        ~HtmlTable();
        class Row {
        public:
            Row &operator<<(const char *value);
            Row &operator<<(int value);
        private:
            Row();
            ~Row();
            Row *_nextRow;
            friend class HtmlTable;
        };
    private:
    };
};
+1 −0
Changes for test/htmlfiles/right.html: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
    <script src="script.js"></script>
</head>
<body>
    <!-- body content -->
    <span>test text</span>
    <!-- page content -->
    weiterer text