Loading src/html.cpp +49 −8 Changes for src/html.cpp: 49 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -210,7 +210,7 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { HtmlElement* firsthel = nullptr, * lasthel = nullptr; for (el* curel = firstEl; curel; curel = curel->nextel) { for (el* curel = firstEl->nextel; curel; curel = curel->nextel) { if (!curel->terminator) { if (lasthel) { lasthel->_nextElement = curel->elhtml; Loading Loading @@ -420,7 +420,10 @@ void libhtmlpp::HtmlPage::addElement(HtmlElement *element){ } const char* libhtmlpp::HtmlPage::printHtml(){ return _RootNode->printHtmlElement(); _C_str.clear(); _C_str.append("<!DOCTYPE html>"); _C_str.append(_RootNode->printHtmlElement()); return _C_str.c_str(); } void libhtmlpp::HtmlPage::loadFile(const char* path){ Loading @@ -447,11 +450,53 @@ void libhtmlpp::HtmlPage::loadFile(const char* path){ throw excp[HTMLException::Critical] << "Could not read file"; } } const char type[] = { '!','D','O','C','T','Y','P','E' }; int i = 0; while (i < 8) { if (tmp[i+1] != type[i]) { HTMLException excp; excp[HTMLException::Critical] << "No Doctype found arborting"; throw excp; } ++i; } do{ ++i; } while (tmp[i] == ' '); const char typevalue[] = { 'h','t','m','l' }; int tpvl = 4; if ((i + tpvl) > tmp.length()) { HTMLException excp; excp[HTMLException::Critical] << "Doctype header broken or wrong type"; throw excp; } int ii = 0,ie=i+tpvl; while (i < ie) { if (tmp[i] != typevalue[ii]) { HTMLException excp; excp[HTMLException::Critical] << "wrong Doctype"; throw excp; } ++i; ++ii; } _RootNode=tmp.parse(); } void libhtmlpp::HtmlElement::_print(HtmlElement* child) { for (HtmlElement* cur = child; cur; cur = cur->_nextElement) { if (!_beforeText.empty()) { _Cstr.append(_beforeText.c_str()); } _Cstr.append("<"); _Cstr.append(cur->_TagName.c_str()); for (HtmlElement::Attributes* curattr = cur->_firstAttr; curattr; curattr = curattr->_nextAttr) { Loading @@ -463,18 +508,14 @@ void libhtmlpp::HtmlElement::_print(HtmlElement* child) { } _Cstr.append(">"); if (!_beforeText.empty()) { _Cstr.append(_beforeText.c_str()); if (!_afterText.empty()) { _Cstr.append(_afterText.c_str()); } if (cur->_childElement) { _print(cur->_childElement); } if (!_afterText.empty()) { _Cstr.append(_afterText.c_str()); } _Cstr.append("</"); _Cstr.append(cur->_TagName.c_str()); _Cstr.append(">"); Loading src/html.h +1 −1 Changes for src/html.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ namespace libhtmlpp { void addElement(HtmlElement* element); const char* printHtml(); private: sys::array<char> _DocType; sys::array<char> _C_str; HtmlElement* _RootNode; }; Loading Loading
src/html.cpp +49 −8 Changes for src/html.cpp: 49 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -210,7 +210,7 @@ libhtmlpp::HtmlElement* libhtmlpp::HtmlString::_buildTree(ssize_t& pos) { HtmlElement* firsthel = nullptr, * lasthel = nullptr; for (el* curel = firstEl; curel; curel = curel->nextel) { for (el* curel = firstEl->nextel; curel; curel = curel->nextel) { if (!curel->terminator) { if (lasthel) { lasthel->_nextElement = curel->elhtml; Loading Loading @@ -420,7 +420,10 @@ void libhtmlpp::HtmlPage::addElement(HtmlElement *element){ } const char* libhtmlpp::HtmlPage::printHtml(){ return _RootNode->printHtmlElement(); _C_str.clear(); _C_str.append("<!DOCTYPE html>"); _C_str.append(_RootNode->printHtmlElement()); return _C_str.c_str(); } void libhtmlpp::HtmlPage::loadFile(const char* path){ Loading @@ -447,11 +450,53 @@ void libhtmlpp::HtmlPage::loadFile(const char* path){ throw excp[HTMLException::Critical] << "Could not read file"; } } const char type[] = { '!','D','O','C','T','Y','P','E' }; int i = 0; while (i < 8) { if (tmp[i+1] != type[i]) { HTMLException excp; excp[HTMLException::Critical] << "No Doctype found arborting"; throw excp; } ++i; } do{ ++i; } while (tmp[i] == ' '); const char typevalue[] = { 'h','t','m','l' }; int tpvl = 4; if ((i + tpvl) > tmp.length()) { HTMLException excp; excp[HTMLException::Critical] << "Doctype header broken or wrong type"; throw excp; } int ii = 0,ie=i+tpvl; while (i < ie) { if (tmp[i] != typevalue[ii]) { HTMLException excp; excp[HTMLException::Critical] << "wrong Doctype"; throw excp; } ++i; ++ii; } _RootNode=tmp.parse(); } void libhtmlpp::HtmlElement::_print(HtmlElement* child) { for (HtmlElement* cur = child; cur; cur = cur->_nextElement) { if (!_beforeText.empty()) { _Cstr.append(_beforeText.c_str()); } _Cstr.append("<"); _Cstr.append(cur->_TagName.c_str()); for (HtmlElement::Attributes* curattr = cur->_firstAttr; curattr; curattr = curattr->_nextAttr) { Loading @@ -463,18 +508,14 @@ void libhtmlpp::HtmlElement::_print(HtmlElement* child) { } _Cstr.append(">"); if (!_beforeText.empty()) { _Cstr.append(_beforeText.c_str()); if (!_afterText.empty()) { _Cstr.append(_afterText.c_str()); } if (cur->_childElement) { _print(cur->_childElement); } if (!_afterText.empty()) { _Cstr.append(_afterText.c_str()); } _Cstr.append("</"); _Cstr.append(cur->_TagName.c_str()); _Cstr.append(">"); Loading
src/html.h +1 −1 Changes for src/html.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ namespace libhtmlpp { void addElement(HtmlElement* element); const char* printHtml(); private: sys::array<char> _DocType; sys::array<char> _C_str; HtmlElement* _RootNode; }; Loading