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

now parser parse text und structur

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

        el() {
            nextel = nullptr;
@@ -204,8 +204,26 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) {
        lastEl->epos = _HTable[i][2];

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

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

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

            lastEl->terminator = false;

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

            lastEl->elhtml = new HtmlElement(nullptr);
            lastEl->elhtml->_Text = _Data.substr(lastEl->spos, (lastEl->epos-lastEl->spos)+1);
        }

    }



    int lvl = 0;
    
    HtmlElement* firsthel = nullptr, * lasthel = nullptr;
@@ -240,7 +258,7 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) {
                                endcur->elhtml->_prevElement->_nextElement =nullptr;
                            break;
                        }
                        endcur = endcur->nextel;                            
                        endcur = endcur->prevel;                            
                    }
                }
		    }
@@ -398,7 +416,6 @@ libhtmlpp::HtmlElement::HtmlElement(const char *tagname){
    _firstAttr = nullptr;
    _lastAttr = nullptr;
    _TagName = tagname;
    
}

libhtmlpp::HtmlElement::~HtmlElement(){
@@ -493,10 +510,7 @@ void libhtmlpp::HtmlPage::loadFile(const char* path){

void libhtmlpp::HtmlElement::_print(HtmlElement* child) {
    for (HtmlElement* cur = child; cur; cur = cur->_nextElement) {
        if (!_beforeText.empty()) {
            _Cstr.append(_beforeText.c_str());
        }

        if (!cur->_TagName.empty()) {
            _Cstr.append("<");
            _Cstr.append(cur->_TagName.c_str());
            for (HtmlElement::Attributes* curattr = cur->_firstAttr; curattr; curattr = curattr->_nextAttr) {
@@ -508,18 +522,19 @@ void libhtmlpp::HtmlElement::_print(HtmlElement* child) {
            }
            _Cstr.append(">");

        if (!_afterText.empty()) {
            _Cstr.append(_afterText.c_str());
        }

            if (cur->_childElement) {
                _print(cur->_childElement);
            }

            if (cur->_childElement) {
                _Cstr.append("</");
                _Cstr.append(cur->_TagName.c_str());
                _Cstr.append(">");
            }
        } else if (!cur->_Text.empty()) {
            _Cstr.append(cur->_Text.c_str());
        }
    }
}


+4 −3
Changes for src/html.h: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -66,13 +66,14 @@ namespace libhtmlpp {
        };

    private:
        //if text tagname must be zero
        sys::array<char> _TagName;
        sys::array<char> _Cstr;
        sys::array<char> _Text;

        sys::array<char> _beforeText;
        sys::array<char> _afterText;
        //for text and comment fields
        sys::array<char> _Text;

        //if text Attributes must be zero
        Attributes*    _firstAttr;
        Attributes*    _lastAttr;