Commit 9dc72a9e authored by jan.koester's avatar jan.koester
Browse files

tes

parent f3d827dd
Loading
Loading
Loading
Loading
+71 −14
Original line number Diff line number Diff line
@@ -100,9 +100,6 @@ libhtmlpp::HtmlString::HtmlString(const std::string& str) : HtmlString(){
}

libhtmlpp::HtmlString::~HtmlString(){
    while(!_Childs.empty()){
        _Childs.pop();
    }
}

libhtmlpp::HtmlString::HtmlString(const libhtmlpp::HtmlString& str) : HtmlString() {
@@ -128,10 +125,6 @@ void libhtmlpp::HtmlString::insert(size_t pos, char src){
}

void libhtmlpp::HtmlString::clear(){
    while(!_Childs.empty()){
        _Childs.pop();
    }
    _Data.clear();
}

bool libhtmlpp::HtmlString::empty(){
@@ -235,8 +228,68 @@ const std::vector<char>& libhtmlpp::HtmlString::data() {

libhtmlpp::Element &libhtmlpp::HtmlString::parse() {
    HTMLException excp;
    Element &el=_buildTree();
    return el;
    _buildTree();
    return *rootEl;
}

void printElement(libhtmlpp::Element* el, int depth, std::ostream& out) {
    if (!el) {
        return;
    }

    // 1. Print Indentation
    for (int i = 0; i < depth; ++i) {
        out << "|   "; // Use a pipe and spaces for visual depth
    }

    // 2. Print Node Information
    if (el->isHtmlElement()) {
        libhtmlpp::HtmlElement* html_el = static_cast<libhtmlpp::HtmlElement*>(el);
        out << "├── <" << html_el->getTag() << ">";

        // Print attributes (optional, but helpful for debugging)
        const auto& attrs = html_el->getAttributeList();
        if (!attrs.empty()) {
            out << " [Attrs: " << attrs.size() << "]";
        }
        out << std::endl;

    } else if (el->isTextElement()) {
        libhtmlpp::TextElement* text_el = static_cast<libhtmlpp::TextElement*>(el);
        // Print a snippet of text content, trimming whitespace
        std::string content = text_el->getContent();
        // Remove leading/trailing whitespace for clean output
        size_t first = content.find_first_not_of(" \t\n\r");
        size_t last = content.find_last_not_of(" \t\n\r");
        if (first != std::string::npos) {
            content = content.substr(first, (last - first + 1));
        }

        out << "├── #TEXT: \"";
        if (content.length() > 30) {
            out << content.substr(0, 27) << "...\"";
        } else if (!content.empty()) {
            out << content << "\"";
        } else {
            out << "(whitespace only)\"";
        }
        out << std::endl;

    } else {
        out << "├── Unknown Element Type" << std::endl;
    }

    // 3. Recursive Traversal

    // A. Recurse into the first child
    if (el->_childElement) {
        printElement(el->_childElement.get(), depth + 1, out);
    }

    // B. Move to the next sibling
    if (el->_nextElement) {
        printElement(el->_nextElement.get(), depth, out);
    }
}

void libhtmlpp::HtmlString::_buildtreenode(std::unique_ptr<libhtmlpp::DocElements> &firstel,libhtmlpp::DocElements *lastel){
@@ -328,10 +381,13 @@ NEXTDOCEL:
        childel.start=next->nextel.get();
        childel.end=parent;
        cpylist.push(childel);
        next=parent;
        next=parent->nextel.get();
    }

    while(next){
    if(next && next->element)
        std::cout << next->element->getType() << std::endl;

    while(next && next->element){
        if(!next->terminator){
            start->element->_nextElement=std::move(next->element);
            prev=start;
@@ -356,10 +412,11 @@ NEXTDOCEL:
    }
}

libhtmlpp::Element &libhtmlpp::HtmlString::_buildTree() {
void libhtmlpp::HtmlString::_buildTree() {
    DocElements *lastEl = nullptr;
    std::unique_ptr<DocElements> firstEl=nullptr;

    auto addelement = [this](DocElements **last){
    auto addelement = [&firstEl](DocElements **last){
        if (!firstEl.get()) {
            firstEl = std::make_unique<DocElements>();
            *last = firstEl.get();
@@ -499,7 +556,7 @@ BUILDTREE_STARTLOOP:

    _buildtreenode(firstEl,lastEl);

    return *firstEl->element;
    rootEl=std::move(firstEl->element);
}

void libhtmlpp::HtmlString::_serialelize(std::vector<char> in, libhtmlpp::HtmlElement *out) {
+2 −3
Original line number Diff line number Diff line
@@ -288,13 +288,12 @@ namespace libhtmlpp {
        libhtmlpp::Element &parse();

    private:
        std::unique_ptr<DocElements> firstEl;
        std::unique_ptr<Element> rootEl;
        void                 _serialelize(std::vector<char> in, HtmlElement* out);
        Element             &_buildTree();
        void                 _buildTree();
        void                 _buildtreenode(std::unique_ptr<DocElements> &firstel,DocElements *lastel);
        std::vector<char>    _Data;
        std::string                 _Str;
        std::stack<Element*> _Childs;
        friend void HtmlEncode(const std::string &input,HtmlString *output);
        friend class HtmlPage;
    };