Commit a853eda8 authored by Jan Köster's avatar Jan Köster
Browse files

added to utils

parent efa528c1
Loading
Loading
Loading
Loading
+3 −3
Changes for CMakeSettings.json: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "linux_clang_x64" ],
      "remoteMachineName": "${defaultRemoteMachineName}",
      "remoteMachineName": "-1986845808;10.1.1.12 (username=root, port=22, authentication=Password)",
      "remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
      "remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
      "remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
@@ -48,14 +48,14 @@
    {
      "name": "Linux-Clang-Release",
      "generator": "Ninja",
      "configurationType": "RelWithDebInfo",
      "configurationType": "Release",
      "cmakeExecutable": "cmake",
      "remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
      "cmakeCommandArgs": "",
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "linux_clang_x64" ],
      "remoteMachineName": "${defaultRemoteMachineName}",
      "remoteMachineName": "-1986845808;10.1.1.12 (username=root, port=22, authentication=Password)",
      "remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
      "remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
      "remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
+60 −42
Changes for src/html.cpp: 60 added lines, 42 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,32 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define HTMLCOMMENT 2
#define HTMLHEADER 3

namespace libhtmlpp {
    struct DocElements {
        sys::array<char>        data;
        libhtmlpp::HtmlElement* elhtml;
        bool                    terminator;
        struct DocElements* nextel;
        struct DocElements* prevel;
        int                     spos;
        int                     epos;

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

        ~DocElements() {
            if (nextel)
                delete nextel;
        }
    };
};

libhtmlpp::HtmlString::HtmlString(){
    _InitString();
}
@@ -158,39 +184,16 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::parse() {
}

libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) {
    struct el {
        sys::array<char> data;
        HtmlElement*     elhtml;
        bool             terminator;
        struct el*       nextel;
        struct el*       prevel;
        int              spos;
        int              epos;

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

        ~el() {
            if (nextel)
                delete nextel;
        }

    }*firstEl = nullptr, * lastEl = nullptr, * before = nullptr;
    DocElements *firstEl = nullptr, *lastEl = nullptr, *before = nullptr;

	for (int i = 0; i < _HTableSize; ++i) {
		if (!firstEl) {
			firstEl = new el;
			firstEl = new DocElements;
			lastEl = firstEl;
		}
		else {

			lastEl->nextel = new el;
			lastEl->nextel = new DocElements;
			lastEl->nextel->prevel = lastEl;
			lastEl = lastEl->nextel;
		}
@@ -205,9 +208,9 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) {

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

        if (i + 1 < _HTableSize && _HTable[i + 1][0] - _HTable[i][2] > 0) {
        if ((i + 1) < _HTableSize && _HTable[i + 1][0] - _HTable[i][2] > 0) {

            lastEl->nextel = new el;
            lastEl->nextel = new DocElements;
            lastEl->nextel->prevel = lastEl;
            lastEl = lastEl->nextel;

@@ -228,7 +231,7 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) {
    
    HtmlElement* firsthel = nullptr, * lasthel = nullptr;

    for (el* curel = firstEl->nextel; curel; curel = curel->nextel) {
    for (DocElements* curel = firstEl->nextel; curel; curel = curel->nextel) {
        if (!curel->terminator) {
            if (lasthel) {
                lasthel->_nextElement = curel->elhtml;
@@ -242,36 +245,51 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) {
        }
    }

	for (el* curel = firstEl; curel; curel = curel->nextel) {
	for (DocElements* curel = firstEl; curel; curel = curel->nextel) {
        if (curel->terminator) {
		    for (el* parent = lastEl; parent; parent = parent->prevel) {
		    for (DocElements* parent = curel->prevel; parent; parent = parent->prevel) {
                if (parent->elhtml->_TagName == curel->elhtml->_TagName) {
                    parent->elhtml->_childElement = parent->elhtml->_nextElement;
                    if (parent->elhtml->_nextElement)
                        parent->elhtml->_nextElement->_prevElement = nullptr;
                    parent->elhtml->_nextElement = nullptr;
                    el* endcur = curel;
                    while(endcur) {
                        if (!endcur->terminator) {
                            parent->elhtml->_nextElement = endcur->elhtml;
                            if (endcur->elhtml->_prevElement)
                                endcur->elhtml->_prevElement->_nextElement =nullptr;
                            break;

                    parent->elhtml->_childElement = parent->elhtml->_nextElement;
                    
                    DocElements* endcurel = nullptr;

                    while (endcurel) {
                        if (!curel->terminator) {
                            endcurel = curel;
                        }
                        endcur = endcur->prevel;                            
                        curel = curel->nextel;
                    }

                    if (endcurel)
                        parent->elhtml->_nextElement = endcurel->elhtml;
                    break;
                }
		    }
        }
	}

    _buildTreeElement(firstEl,firstEl->nextel,firsthel);

    delete firstEl;

    return firsthel;
}

libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTreeElement(libhtmlpp::DocElements* curel,
                                                                 libhtmlpp::DocElements* nexel,
                                                                 libhtmlpp::HtmlElement* parent) {
    if (curel->elhtml && !curel->elhtml->_TagName.empty()) {
        if (!parent) {
            parent=curel->elhtml;
        }
    }
    
}

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

    for (i = 0; i < in.length(); ++i) {
+7 −5
Changes for src/html.h: 7 added lines, 5 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 DocElements;

    class HtmlElement {
    public:
@@ -46,10 +47,6 @@ namespace libhtmlpp {

        const char* printHtmlElement();

        void insertText(const char* text) {

        }

    protected:

        static void       _print(HtmlElement* el, HtmlElement* parent,sys::array<char> &output);
@@ -68,7 +65,6 @@ namespace libhtmlpp {
    private:
        //if text tagname must be zero
        sys::array<char> _TagName;
        sys::array<char> _Cstr;

        //for text and comment fields
        sys::array<char> _Text;
@@ -77,6 +73,9 @@ namespace libhtmlpp {
        Attributes*    _firstAttr;
        Attributes*    _lastAttr;

        //buffer for c_str() function
        sys::array<char> _Cstr;

        friend class HtmlString;
    };

@@ -154,6 +153,9 @@ namespace libhtmlpp {
        void              _parseTree();
        void              _serialelize(sys::array<char> in, HtmlElement** out);
        HtmlElement*      _buildTree(ssize_t& pos);

        HtmlElement*      _buildTreeElement(libhtmlpp::DocElements* curel, libhtmlpp::DocElements* nexel, 
                                            HtmlElement* parent);
        sys::array<char>        _Data;
        sys::array<char>        _Cstr;
        ssize_t**               _HTable;
+23 −0
Changes for src/utils.h: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -89,4 +89,27 @@ namespace libhtmlpp {
        *dest=buf;
        return true;
    }  

    inline bool setter(const char* src, int srcsize, sys::array<char> &dest, const char* ssigns = nullptr) {
        char* buf = new char[srcsize + 1];
        bool nallowd = false;
        for (int i = 0; i < srcsize; ++i) {
            if (!isdigit(src[i]) || !isalpha(src[i]) || ssigns) {
                nallowd = true;
                for (size_t pos = 0; pos < strlen(ssigns); ++pos) {
                    if (ssigns[pos] == src[i]) {
                        nallowd = false;
                    }
                }
                if (nallowd) {
                    delete[] buf;
                    return false;
                }
            }
            buf[i] = src[i];
        }
        buf[srcsize] = '\0';
        dest.write(buf,srcsize);
        return true;
    }
};