Loading src/html.cpp +27 −62 Original line number Diff line number Diff line Loading @@ -327,61 +327,43 @@ void libhtmlpp::HtmlString::_buildtreenode( prev_el_in_tree = opener_el; if (fr.outer_prev_el) { // Link the parent's previous element (fr.outer_prev_el) to the completed parent container (opener_el). prev_el_in_tree->_prevElement = fr.outer_prev_el; // Link the parent to its previous sibling fr.outer_prev_el->_nextElement = std::move(fr.open->element); // Transfer ownership of the PARENT container prev_el_in_tree = fr.outer_prev_el->_nextElement.get(); // Update to the new last element in the parent's chain prev_el_in_tree->_prevElement = fr.outer_prev_el; fr.outer_prev_el->_nextElement = std::move(fr.open->element); prev_el_in_tree = fr.outer_prev_el->_nextElement.get(); } // Continue traversal after the container's closing tag prev_el_in_tree = opener_el; start = fr.close->nextel.get(); // Start after the closing tag end = fr.outer_end; // Restore parent's boundary start = fr.close->nextel.get(); end = fr.outer_end; continue; // Go to the next element in the parent's scope (sibling of container) continue; } // B. NEW CONTAINER FOUND (Recursive call/Push to stack) if (start->element && !start->terminator && start->element->getType() == HtmlEl) { if (DocElements *close = find_terminator(start, end)) { // Push the current scope onto the stack stack.push(Frame{start, close, end, prev_el_in_tree}); // Set up the new, deeper scope (child span) prev_el_in_tree = nullptr; start = start->nextel.get(); end = close; // New boundary is the closing tag end = close; continue; // Restart the loop to process the first child continue; } } // C. SIBLING LINKING (Normal Forward Progress) // Only link elements that still exist in the DocElements node. if (start->element && !start->terminator) { Element *current_el = start->element.get(); if (prev_el_in_tree) { // Link the previous element's next pointer to the current element, // transferring ownership from the DocElements list to the tree. current_el->_prevElement = prev_el_in_tree; prev_el_in_tree->_nextElement = std::move(start->element); // Update the end of the sibling chain to the newly moved element prev_el_in_tree = prev_el_in_tree->_nextElement.get(); } else { // This is the first element in the current sibling chain. // The element stays in start->element (firstel->element for the root, // or fr.open->nextel->element for children) until a subsequent sibling // is found, or the scope closes (in A). prev_el_in_tree = current_el; } } // Advance to the next DocElement node start = start->nextel.get(); } } Loading Loading @@ -1775,27 +1757,22 @@ int libhtmlpp::HtmlElement::getType() const{ libhtmlpp::HtmlTable::HtmlTable(){ _firstRow=nullptr; _firstRow=std::make_unique<Row>(); _lastRow=nullptr; _count = 0; } libhtmlpp::HtmlTable::~HtmlTable(){ Row *next=_firstRow,*curel=nullptr; while(next){ curel=next->_nextRow; next->_nextRow=nullptr; next=curel; } } libhtmlpp::HtmlTable::Row &libhtmlpp::HtmlTable::operator<<(const libhtmlpp::HtmlTable::Row row){ std::unique_ptr<Row> ptr=std::make_unique<Row> (row); if(_firstRow){ _lastRow->_nextRow=new Row(row); _lastRow=_lastRow->_nextRow; _lastRow->_nextRow=std::move(ptr); _lastRow=_lastRow->_nextRow.get(); }else{ _firstRow= new Row(row); _lastRow=_firstRow; _firstRow= std::move(ptr); _lastRow=_firstRow.get(); } ++_count; return *_lastRow; Loading @@ -1809,7 +1786,7 @@ libhtmlpp::HtmlTable::Row & libhtmlpp::HtmlTable::operator[](size_t pos){ } size_t cpos=0; Row *curel=nullptr; for(curel=_firstRow; curel; curel=curel->_nextRow){ for(curel=_firstRow.get(); curel; curel=curel->_nextRow.get()){ if(cpos==pos) return *curel; ++cpos; Loading @@ -1819,10 +1796,10 @@ libhtmlpp::HtmlTable::Row & libhtmlpp::HtmlTable::operator[](size_t pos){ void libhtmlpp::HtmlTable::insert(libhtmlpp::HtmlElement* element){ element->setTagname("table"); for(Row *crow=_firstRow; crow; crow=crow->_nextRow){ for(Row *crow=_firstRow.get(); crow; crow=crow->_nextRow.get()){ HtmlElement hrow("tr"); for(Column *ccol=crow->_firstColumn; ccol; ccol=ccol->_nextColumn ){ for(Column *ccol=crow->_firstColumn.get(); ccol; ccol=ccol->_nextColumn.get() ){ HtmlString buf; buf << "<td>"; buf << ccol->Data.str(); Loading Loading @@ -1852,8 +1829,7 @@ void libhtmlpp::HtmlTable::deleteRow(size_t pos){ Row *drow=&(*this)[pos]; try{ Row *prev=&(*this)[pos-1]; prev->_nextRow=drow->_nextRow; drow->_nextRow=nullptr; prev->_nextRow=std::move(drow->_nextRow); --_count; }catch(...){} } Loading Loading @@ -1883,12 +1859,6 @@ libhtmlpp::HtmlTable::Row::Row(){ } libhtmlpp::HtmlTable::Row::~Row(){ Column *cnext=_firstColumn,*ccurel=nullptr; while(cnext){ ccurel=cnext->_nextColumn; cnext->_nextColumn=nullptr; cnext=ccurel; } } libhtmlpp::HtmlTable::Row::Row(const libhtmlpp::HtmlTable::Row& row){ Loading @@ -1897,18 +1867,19 @@ libhtmlpp::HtmlTable::Row::Row(const libhtmlpp::HtmlTable::Row& row){ _nextRow=nullptr; _count=0; for(Column *curel=row._firstColumn; curel; curel=curel->_nextColumn){ for(Column *curel=row._firstColumn.get(); curel; curel=curel->_nextColumn.get()){ *this << curel->Data; } } libhtmlpp::HtmlTable::Row& libhtmlpp::HtmlTable::Row::operator<<(Column &col){ std::unique_ptr<Column> ptr=std::make_unique<Column>(col); if(_firstColumn){ _lastColumn->_nextColumn=new Column(col); _lastColumn=_lastColumn->_nextColumn; _lastColumn->_nextColumn=std::move(ptr); _lastColumn=_lastColumn->_nextColumn.get(); }else{ _firstColumn= new Column(col); _lastColumn=_firstColumn; _firstColumn= std::move(ptr); _lastColumn=_firstColumn.get(); } ++_count; return *this; Loading Loading @@ -1941,7 +1912,7 @@ libhtmlpp::HtmlTable::Column & libhtmlpp::HtmlTable::Row::operator[](size_t pos) } size_t cpos=0; Column *curel=nullptr; for(curel=_firstColumn; curel; curel=curel->_nextColumn){ for(curel=_firstColumn.get(); curel; curel=curel->_nextColumn.get()){ if(cpos==pos) return *curel; ++cpos; Loading @@ -1953,19 +1924,13 @@ void libhtmlpp::HtmlTable::Row::delColumn(size_t pos){ Column *dcol=&(*this)[pos]; try{ Column *prev=&(*this)[pos-1]; prev->_nextColumn=dcol->_nextColumn; prev->_nextColumn=std::move(dcol->_nextColumn); }catch(...){} dcol->_nextColumn=nullptr; --_count; } void libhtmlpp::HtmlTable::Row::clear(){ Column *cnext=_firstColumn,*ccurel=nullptr; while(cnext){ ccurel=cnext; cnext=cnext->_nextColumn; } _firstColumn = nullptr; _firstColumn.get_deleter(); _lastColumn = nullptr; _count = 0; } src/html.h +9 −9 Original line number Diff line number Diff line Loading @@ -323,13 +323,13 @@ namespace libhtmlpp { class Column { public: HtmlString Data; ~Column(); Column(const Column &col); private: Column(); Column(const Column &col); Column(const HtmlString &data); ~Column(); Column *_nextColumn; std::unique_ptr<Column> _nextColumn; friend class HtmlTable; }; Loading @@ -349,9 +349,9 @@ namespace libhtmlpp { void delColumn(size_t pos); void clear(); private: Column *_firstColumn; std::unique_ptr<Column> _firstColumn; Column *_lastColumn; Row *_nextRow; std::unique_ptr<Row> _nextRow; size_t _count; friend class HtmlTable; }; Loading @@ -365,7 +365,7 @@ namespace libhtmlpp { void setHeader(int count,...); void deleteRow(size_t pos); private: Row *_firstRow; std::unique_ptr<Row> _firstRow; Row *_lastRow; Row _header; size_t _count; Loading Loading
src/html.cpp +27 −62 Original line number Diff line number Diff line Loading @@ -327,61 +327,43 @@ void libhtmlpp::HtmlString::_buildtreenode( prev_el_in_tree = opener_el; if (fr.outer_prev_el) { // Link the parent's previous element (fr.outer_prev_el) to the completed parent container (opener_el). prev_el_in_tree->_prevElement = fr.outer_prev_el; // Link the parent to its previous sibling fr.outer_prev_el->_nextElement = std::move(fr.open->element); // Transfer ownership of the PARENT container prev_el_in_tree = fr.outer_prev_el->_nextElement.get(); // Update to the new last element in the parent's chain prev_el_in_tree->_prevElement = fr.outer_prev_el; fr.outer_prev_el->_nextElement = std::move(fr.open->element); prev_el_in_tree = fr.outer_prev_el->_nextElement.get(); } // Continue traversal after the container's closing tag prev_el_in_tree = opener_el; start = fr.close->nextel.get(); // Start after the closing tag end = fr.outer_end; // Restore parent's boundary start = fr.close->nextel.get(); end = fr.outer_end; continue; // Go to the next element in the parent's scope (sibling of container) continue; } // B. NEW CONTAINER FOUND (Recursive call/Push to stack) if (start->element && !start->terminator && start->element->getType() == HtmlEl) { if (DocElements *close = find_terminator(start, end)) { // Push the current scope onto the stack stack.push(Frame{start, close, end, prev_el_in_tree}); // Set up the new, deeper scope (child span) prev_el_in_tree = nullptr; start = start->nextel.get(); end = close; // New boundary is the closing tag end = close; continue; // Restart the loop to process the first child continue; } } // C. SIBLING LINKING (Normal Forward Progress) // Only link elements that still exist in the DocElements node. if (start->element && !start->terminator) { Element *current_el = start->element.get(); if (prev_el_in_tree) { // Link the previous element's next pointer to the current element, // transferring ownership from the DocElements list to the tree. current_el->_prevElement = prev_el_in_tree; prev_el_in_tree->_nextElement = std::move(start->element); // Update the end of the sibling chain to the newly moved element prev_el_in_tree = prev_el_in_tree->_nextElement.get(); } else { // This is the first element in the current sibling chain. // The element stays in start->element (firstel->element for the root, // or fr.open->nextel->element for children) until a subsequent sibling // is found, or the scope closes (in A). prev_el_in_tree = current_el; } } // Advance to the next DocElement node start = start->nextel.get(); } } Loading Loading @@ -1775,27 +1757,22 @@ int libhtmlpp::HtmlElement::getType() const{ libhtmlpp::HtmlTable::HtmlTable(){ _firstRow=nullptr; _firstRow=std::make_unique<Row>(); _lastRow=nullptr; _count = 0; } libhtmlpp::HtmlTable::~HtmlTable(){ Row *next=_firstRow,*curel=nullptr; while(next){ curel=next->_nextRow; next->_nextRow=nullptr; next=curel; } } libhtmlpp::HtmlTable::Row &libhtmlpp::HtmlTable::operator<<(const libhtmlpp::HtmlTable::Row row){ std::unique_ptr<Row> ptr=std::make_unique<Row> (row); if(_firstRow){ _lastRow->_nextRow=new Row(row); _lastRow=_lastRow->_nextRow; _lastRow->_nextRow=std::move(ptr); _lastRow=_lastRow->_nextRow.get(); }else{ _firstRow= new Row(row); _lastRow=_firstRow; _firstRow= std::move(ptr); _lastRow=_firstRow.get(); } ++_count; return *_lastRow; Loading @@ -1809,7 +1786,7 @@ libhtmlpp::HtmlTable::Row & libhtmlpp::HtmlTable::operator[](size_t pos){ } size_t cpos=0; Row *curel=nullptr; for(curel=_firstRow; curel; curel=curel->_nextRow){ for(curel=_firstRow.get(); curel; curel=curel->_nextRow.get()){ if(cpos==pos) return *curel; ++cpos; Loading @@ -1819,10 +1796,10 @@ libhtmlpp::HtmlTable::Row & libhtmlpp::HtmlTable::operator[](size_t pos){ void libhtmlpp::HtmlTable::insert(libhtmlpp::HtmlElement* element){ element->setTagname("table"); for(Row *crow=_firstRow; crow; crow=crow->_nextRow){ for(Row *crow=_firstRow.get(); crow; crow=crow->_nextRow.get()){ HtmlElement hrow("tr"); for(Column *ccol=crow->_firstColumn; ccol; ccol=ccol->_nextColumn ){ for(Column *ccol=crow->_firstColumn.get(); ccol; ccol=ccol->_nextColumn.get() ){ HtmlString buf; buf << "<td>"; buf << ccol->Data.str(); Loading Loading @@ -1852,8 +1829,7 @@ void libhtmlpp::HtmlTable::deleteRow(size_t pos){ Row *drow=&(*this)[pos]; try{ Row *prev=&(*this)[pos-1]; prev->_nextRow=drow->_nextRow; drow->_nextRow=nullptr; prev->_nextRow=std::move(drow->_nextRow); --_count; }catch(...){} } Loading Loading @@ -1883,12 +1859,6 @@ libhtmlpp::HtmlTable::Row::Row(){ } libhtmlpp::HtmlTable::Row::~Row(){ Column *cnext=_firstColumn,*ccurel=nullptr; while(cnext){ ccurel=cnext->_nextColumn; cnext->_nextColumn=nullptr; cnext=ccurel; } } libhtmlpp::HtmlTable::Row::Row(const libhtmlpp::HtmlTable::Row& row){ Loading @@ -1897,18 +1867,19 @@ libhtmlpp::HtmlTable::Row::Row(const libhtmlpp::HtmlTable::Row& row){ _nextRow=nullptr; _count=0; for(Column *curel=row._firstColumn; curel; curel=curel->_nextColumn){ for(Column *curel=row._firstColumn.get(); curel; curel=curel->_nextColumn.get()){ *this << curel->Data; } } libhtmlpp::HtmlTable::Row& libhtmlpp::HtmlTable::Row::operator<<(Column &col){ std::unique_ptr<Column> ptr=std::make_unique<Column>(col); if(_firstColumn){ _lastColumn->_nextColumn=new Column(col); _lastColumn=_lastColumn->_nextColumn; _lastColumn->_nextColumn=std::move(ptr); _lastColumn=_lastColumn->_nextColumn.get(); }else{ _firstColumn= new Column(col); _lastColumn=_firstColumn; _firstColumn= std::move(ptr); _lastColumn=_firstColumn.get(); } ++_count; return *this; Loading Loading @@ -1941,7 +1912,7 @@ libhtmlpp::HtmlTable::Column & libhtmlpp::HtmlTable::Row::operator[](size_t pos) } size_t cpos=0; Column *curel=nullptr; for(curel=_firstColumn; curel; curel=curel->_nextColumn){ for(curel=_firstColumn.get(); curel; curel=curel->_nextColumn.get()){ if(cpos==pos) return *curel; ++cpos; Loading @@ -1953,19 +1924,13 @@ void libhtmlpp::HtmlTable::Row::delColumn(size_t pos){ Column *dcol=&(*this)[pos]; try{ Column *prev=&(*this)[pos-1]; prev->_nextColumn=dcol->_nextColumn; prev->_nextColumn=std::move(dcol->_nextColumn); }catch(...){} dcol->_nextColumn=nullptr; --_count; } void libhtmlpp::HtmlTable::Row::clear(){ Column *cnext=_firstColumn,*ccurel=nullptr; while(cnext){ ccurel=cnext; cnext=cnext->_nextColumn; } _firstColumn = nullptr; _firstColumn.get_deleter(); _lastColumn = nullptr; _count = 0; }
src/html.h +9 −9 Original line number Diff line number Diff line Loading @@ -323,13 +323,13 @@ namespace libhtmlpp { class Column { public: HtmlString Data; ~Column(); Column(const Column &col); private: Column(); Column(const Column &col); Column(const HtmlString &data); ~Column(); Column *_nextColumn; std::unique_ptr<Column> _nextColumn; friend class HtmlTable; }; Loading @@ -349,9 +349,9 @@ namespace libhtmlpp { void delColumn(size_t pos); void clear(); private: Column *_firstColumn; std::unique_ptr<Column> _firstColumn; Column *_lastColumn; Row *_nextRow; std::unique_ptr<Row> _nextRow; size_t _count; friend class HtmlTable; }; Loading @@ -365,7 +365,7 @@ namespace libhtmlpp { void setHeader(int count,...); void deleteRow(size_t pos); private: Row *_firstRow; std::unique_ptr<Row> _firstRow; Row *_lastRow; Row _header; size_t _count; Loading