Commit 63efdaec authored by jan.koester's avatar jan.koester
Browse files

it works

parent 1924e549
Loading
Loading
Loading
Loading
+51 −25
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ size_t libhtmlpp::HtmlString::size() const{
}

const std::string libhtmlpp::HtmlString::str(){
    return std::string(_Data.data(),_Data.size());
    return std::string(_Data.begin(),_Data.end());
}

const std::vector<char>& libhtmlpp::HtmlString::data() {
@@ -542,14 +542,18 @@ void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlEl
                    }
                }
                std::vector<char> key,val;

                std::copy(in.begin()+kstart,in.begin()+kend,std::back_inserter(key));

                if(vend!=0){
                    std::copy(in.begin()+vstart,in.begin()+vend,std::back_inserter(val));

                }

                if(val.empty())
                    out->setAttribute(std::string(key.data(),key.size()),"");
                    out->setAttribute(std::string(key.begin(), key.end()), "");
                else
                    out->setAttribute(std::string(key.data(),key.size()),std::string(val.data(),val.size()));
                    out->setAttribute(std::string(key.begin(), key.end()), std::string(val.begin(), val.end()));
            }
    }
}
@@ -656,7 +660,7 @@ void libhtmlpp::HtmlElement::setTagname(const std::string &name){
const std::string libhtmlpp::HtmlElement::getTagname() const{
    if(_TagName.empty())
        return "";
    return std::string(_TagName.data(),_TagName.size());
    return std::string(_TagName.begin(),_TagName.end());
}

void libhtmlpp::HtmlElement::insertChild(const libhtmlpp::Element* el){
@@ -776,9 +780,10 @@ DELETEELEMENT:
            cur->_prevElement=nullptr;
            cur->_firstElement=nullptr;
            delete cur;
            cur=nullptr;
        }

        if(cur->_firstElement==el)
        if(cur && cur->_firstElement==el)
            cur->_firstElement=el->_nextElement;

        if(cur->getType()==HtmlEl){
@@ -846,10 +851,19 @@ NEWEL:
        if(src->getType()==HtmlEl && dest->getType()==HtmlEl){
            ((libhtmlpp::HtmlElement*)dest)->_TagName=(((libhtmlpp::HtmlElement*)src)->_TagName);
            for(libhtmlpp::HtmlElement::Attributes *cattr=((libhtmlpp::HtmlElement*)src)->_firstAttr; cattr; cattr=cattr->_nextAttr){
                if(!cattr->_Value.empty())
                    ((libhtmlpp::HtmlElement*)dest)->setAttribute(cattr->_Key.data(),cattr->_Value.data());
                else
                    ((libhtmlpp::HtmlElement*)dest)->setAttribute(cattr->_Key.data(),"");
                if(!cattr->_Value.empty()){
                    ((libhtmlpp::HtmlElement*)dest)->setAttribute(
                        std::string(
                            cattr->_Key.begin(),
                            cattr->_Key.end()
                        ),std::string(
                            cattr->_Value.begin(),
                            cattr->_Value.end()
                        )
                    );
                }else{
                    ((libhtmlpp::HtmlElement*)dest)->setAttribute(std::string(cattr->_Key.data(),cattr->_Key.size()),"");
                }
            }

            if(((libhtmlpp::HtmlElement*)src)->_childElement){
@@ -879,10 +893,19 @@ NEWEL:
        }else if(src->getType()==libhtmlpp::ScriptEL && dest->getType()== libhtmlpp::ScriptEL){
            ((libhtmlpp::ScriptElement*)dest)->_TagName=(((libhtmlpp::ScriptElement*)src)->_TagName);
            for(libhtmlpp::ScriptElement::Attributes *cattr=((libhtmlpp::ScriptElement*)src)->_firstAttr; cattr; cattr=cattr->_nextAttr){
                if(!cattr->_Value.empty())
                    ((libhtmlpp::ScriptElement*)dest)->setAttribute(cattr->_Key.data(),cattr->_Value.data());
                else
                    ((libhtmlpp::ScriptElement*)dest)->setAttribute(cattr->_Key.data(),"");
                if(!cattr->_Value.empty()){
                    ((libhtmlpp::ScriptElement*)dest)->setAttribute(
                        std::string(
                            cattr->_Key.begin(),
                            cattr->_Key.end()
                        ),std::string(
                            cattr->_Value.begin(),
                            cattr->_Value.end()
                        )
                    );
                }else{
                    ((libhtmlpp::ScriptElement*)dest)->setAttribute(std::string(cattr->_Key.begin(),cattr->_Key.end()),"");
                }
            }
            ((ScriptElement*)dest)->_Script=(((ScriptElement*)src)->_Script);
        }else if(src->getType()==libhtmlpp::TextEl && dest->getType()== libhtmlpp::TextEl){
@@ -1108,7 +1131,7 @@ void libhtmlpp::TextElement::setText(const std::string& txt){
}

const std::string libhtmlpp::TextElement::getText(){
    return _Text.data();
    return std::string(_Text.begin(),_Text.end());
}

int libhtmlpp::TextElement::getType() const{
@@ -1143,7 +1166,7 @@ void libhtmlpp::CommentElement::setComment(const std::string& txt){
}

const std::string libhtmlpp::CommentElement::getComment(){
    return _Comment.data();
    return std::string(_Comment.begin(),_Comment.end());
}

int libhtmlpp::CommentElement::getType() const{
@@ -1517,8 +1540,9 @@ SEARCHBYID:
        if(((HtmlElement*)curel)->_childElement){
            childs.push(((HtmlElement*)curel)->_childElement);
        }
        const std::string key=((HtmlElement*)curel)->getAtributte("id");
        if(!key.empty() && key==id){
        std::string idname=((HtmlElement*)curel)->getAtributte("id");
        if(!idname.empty() && std::equal(id.begin(),id.end(),idname.begin()) ){
            std::cout << id << std::endl;
            return (HtmlElement*)curel;
        }
    }
@@ -1533,7 +1557,6 @@ SEARCHBYID:
        childs.pop();
        goto SEARCHBYID;
    }

    return nullptr;
}

@@ -1568,7 +1591,7 @@ void libhtmlpp::HtmlElement::setAttribute(const std::string &name, const std::st
    Attributes* cattr = nullptr;

    for (Attributes* curattr = _firstAttr; curattr; curattr=curattr->_nextAttr) {
        if ( std::equal(curattr->_Key.begin(),curattr->_Key.end(),name.begin()) ) {
        if ( std::equal(name.begin(),name.end(),curattr->_Key.begin()) ) {
            cattr = curattr;
        }
    }
@@ -1581,11 +1604,9 @@ void libhtmlpp::HtmlElement::setAttribute(const std::string &name, const std::st
            _lastAttr = _firstAttr;
        }
        cattr = _lastAttr;
        cattr->_Key.resize(name.length());
        std::copy(name.begin(),name.end(),std::insert_iterator<std::vector<char>>(cattr->_Key,cattr->_Key.begin()) );
    }
    cattr->_Value.resize(value.length());
    if(value.length()>0)
    std::copy(value.begin(),value.end(),std::insert_iterator<std::vector<char>>(cattr->_Value ,cattr->_Value .begin()) );
}

@@ -1597,8 +1618,13 @@ void libhtmlpp::HtmlElement::setIntAttribute(const std::string& name, int value)

const std::string libhtmlpp::HtmlElement::getAtributte(const std::string& name) const {
    for (Attributes* curattr = _firstAttr; curattr; curattr = curattr->_nextAttr) {
        if ( std::equal(curattr->_Key.begin(),curattr->_Key.end(),name.begin()) ){
            return std::string(curattr->_Value.data(),curattr->_Value.size());

        if (curattr->_Key.size() != name.length() ) {
            continue;
        }

        if (!curattr->_Key.empty() && std::equal(name.begin(), name.end(), curattr->_Key.begin())) {
            return std::string(curattr->_Value.begin(), curattr->_Value.end());
        }
    }
    return "";
+3 −0
Original line number Diff line number Diff line
@@ -15,3 +15,6 @@ target_link_libraries(htmlcopytest htmlpp-static)
#add_test(htmlcopytest_right htmlcopytest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html)

#set_tests_properties(htmlpagetest_wrong PROPERTIES WILL_FAIL TRUE)

add_executable(htmlinserttest htmlinserttest.cpp)
target_link_libraries(htmlinserttest htmlpp-static)