Loading src/exception.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ const char* libhtmlpp::HTMLException::what(){ return msg.c_str(); } libhtmlpp::HTMLException& libhtmlpp::HTMLException::append(const char *src){ libhtmlpp::HTMLException& libhtmlpp::HTMLException::append(const std::string &src){ msg.append(src); return *this; } Loading @@ -62,7 +62,7 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator[](int errtype){ return *this; } libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const char *src){ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const std::string &src){ return append(src); }; Loading src/exception.h +2 −2 Original line number Diff line number Diff line Loading @@ -57,9 +57,9 @@ namespace libhtmlpp { enum Type {Note,Warning,Error,Critical}; HTMLException& append(const char *src); HTMLException& append(const std::string &src); HTMLException& operator[](int errtype); HTMLException& operator<<(const char *src); HTMLException& operator<<(const std::string &src); HTMLException& operator<<(int src); private: int curCType; Loading src/html.cpp +612 −504 File changed.Preview size limit exceeded, changes collapsed. Show changes src/html.h +73 −52 Original line number Diff line number Diff line Loading @@ -44,7 +44,8 @@ namespace libhtmlpp { TextEl=0, HtmlEl=1, CommentEl=2, ScriptEL=3 ScriptEL=3, SvgEL=4 }; class Element { Loading @@ -69,9 +70,9 @@ namespace libhtmlpp { Element(); std::unique_ptr<Element> _nextElement; Element* _prevElement; Element* _nextElement; Element* _firstElement; friend class HtmlElement; friend class TextElement; Loading @@ -83,7 +84,7 @@ namespace libhtmlpp { class HtmlElement : public Element { public: HtmlElement(); HtmlElement(const char* tag); HtmlElement(const std::string &tag); HtmlElement(const HtmlElement &hel); HtmlElement(const HtmlElement *hel); ~HtmlElement(); Loading @@ -94,48 +95,45 @@ namespace libhtmlpp { bool operator==(const HtmlElement *hel); bool operator==(const HtmlElement &hel); void setAttribute(const char* name, const char* value); void setAttribute(const char* name,size_t nlen, const char* value,size_t vlen); void setAttribute(const std::string &name, const std::string &value); void setIntAttribute(const char* name, int value); void setIntAttribute(const std::string &name, int value); const char* getAtributte(const char* name) const; const std::string getAtributte(const std::string &name) const; int getIntAtributte(const char* name); int getIntAtributte(const std::string &name) const; void insertChild(const Element* el); void insertChild(const Element& el); void appendChild(const Element* el); void appendChild(const Element& el); void setTagname(const char *name); const char *getTagname(); void setTagname(const std::string &name); const std::string getTagname() const; HtmlElement *getElementbyID(const char *id) const; HtmlElement *getElementbyTag(const char *tag) const; HtmlElement *getElementbyID(const std::string &id) const; HtmlElement *getElementbyTag(const std::string &tag) const; int getType() const; void remove(Element* el); protected: Element* _childElement; std::unique_ptr<Element> _childElement; struct Attributes { Attributes(); ~Attributes(); std::vector<char> _Key; std::vector<char> _Value; std::vector<char> _CStr; Attributes* _nextAttr; std::unique_ptr<Attributes> _nextAttr; }; private: //if text tagname must be zero std::vector<char> _TagName; std::vector<char> _CStr; //if text Attributes must be zero Attributes* _firstAttr; std::unique_ptr<Attributes> _firstAttr; Attributes* _lastAttr; friend class HtmlString; Loading @@ -147,20 +145,19 @@ namespace libhtmlpp { class TextElement : public Element { public: TextElement(); TextElement(const char *txt); TextElement(const std::string &txt); TextElement(const TextElement &texel); ~TextElement(); TextElement& operator=(const Element &hel); TextElement& operator=(const Element *hel); const char *getText(); void setText(const char *txt); const std::string getText(); void setText(const std::string &txt); int getType() const; protected: std::vector<char> _Text; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -175,13 +172,12 @@ namespace libhtmlpp { CommentElement& operator=(const Element &hel); CommentElement& operator=(const Element *hel); const char *getComment(); void setComment(const char *txt); const std::string getComment(); void setComment(const std::string &txt); int getType() const; protected: std::vector<char> _Comment; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -196,8 +192,8 @@ namespace libhtmlpp { ScriptElement& operator=(const Element &hel); ScriptElement& operator=(const Element *hel); const char *getScript(); void setScript(const char *txt); const std::string getScript(); void setScript(const std::string &txt); int getType() const; Loading @@ -211,7 +207,35 @@ namespace libhtmlpp { Element* _childElement=nullptr; std::vector<char> _Script; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; class SvgElement : public HtmlElement{ public: SvgElement(); SvgElement(const SvgElement &svgsrc); ~SvgElement(); SvgElement& operator=(const Element &hel); SvgElement& operator=(const Element *hel); const std::vector<char> getSvg(); void setSvg(const std::string &svg); int getType() const; void insertChild(const Element* el)=delete; void insertChild(const Element& el)=delete; void appendChild(const Element* el)=delete; void appendChild(const Element& el)=delete; protected: Element* _childElement=nullptr; std::vector<char> _Svg; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -226,30 +250,25 @@ namespace libhtmlpp { HtmlString(); HtmlString(const HtmlString &str); HtmlString(const HtmlString *str); HtmlString(const char *str); HtmlString(char str); HtmlString(const std::string &str); ~HtmlString(); void append(const char* src, size_t srcsize); void append(const char* src); void append(const std::string &src); void append(HtmlString& hstring); void push_back(const char src); void insert(size_t pos, char src); HtmlString& operator+=(const char* src); HtmlString& operator+=(const std::string &src); HtmlString& operator+=(HtmlString& hstring); HtmlString& operator=(const char* src); HtmlString& operator=(const std::string *src); HtmlString& operator=(const std::string &src); HtmlString& operator=(const HtmlString& src); char operator[](size_t pos) const; HtmlString& operator<<(const char* src); HtmlString& operator<<(std::string &src); HtmlString& operator<<(std::string *src); HtmlString& operator<<(const std::string &src); HtmlString& operator<<(HtmlString src); HtmlString& operator<<(int src); HtmlString& operator<<(unsigned int src); Loading @@ -261,19 +280,20 @@ namespace libhtmlpp { size_t size() const; void clear(); bool empty(); const char * c_str(); const std::vector<char>& data(); const std::string str(); const char *c_str(); libhtmlpp::Element *parse(); bool validate(std::string *err); libhtmlpp::Element &parse(); private: std::unique_ptr<Element> rootEl; void _serialelize(std::vector<char> in, HtmlElement* out); Element *_buildTree(); void _buildtreenode(const DocElements *firstel,const DocElements *lastel); void _buildTree(); void _buildtreenode(std::unique_ptr<DocElements> &firstel,DocElements *lastel); std::vector<char> _Data; std::vector<char> _CStr; std::stack<Element*> _Childs; std::string _Str; friend void HtmlEncode(const std::string &input,HtmlString *output); friend class HtmlPage; }; Loading @@ -285,14 +305,15 @@ namespace libhtmlpp { public: HtmlPage(); ~HtmlPage(); void loadFile(libhtmlpp::HtmlElement &html,const char* path); void saveFile(libhtmlpp::HtmlElement &html,const char* path); void loadFile(libhtmlpp::HtmlElement &html,const std::string &path); void saveFile(libhtmlpp::HtmlElement &html,const std::string &path); void loadString(libhtmlpp::HtmlElement &html,const std::string &src); void loadString(libhtmlpp::HtmlElement &html,const char *src); void loadString(libhtmlpp::HtmlElement &html,const HtmlString &node); void loadString(libhtmlpp::HtmlElement &html,const HtmlString *node); bool isHtml5(); private: void _CheckHeader(const HtmlString& page); bool _Html5 = true; }; class HtmlTable { Loading test/CMakeLists.txt +11 −7 Original line number Diff line number Diff line # add_executable(csstest csstest.cpp ) # target_link_libraries(csstest htmlpp) add_executable(csstest csstest.cpp ) target_link_libraries(csstest htmlpp) # # add_test(csstest csstest) add_test(csstest csstest) add_executable(htmlpagetest htmlpagetest.cpp) target_link_libraries(htmlpagetest htmlpp-static) #add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html) #add_test(htmlpagetest_wrong htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/wrong.html) add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/html4.html) add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html) add_test(htmlpagetest_wrong htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/wrong.html) set_property(TEST htmlpagetest_wrong PROPERTY WILL_FAIL TRUE ) add_executable(htmlcopytest htmlcopytest.cpp) target_link_libraries(htmlcopytest htmlpp-static) #add_test(htmlcopytest_right htmlcopytest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html) 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) Loading
src/exception.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ const char* libhtmlpp::HTMLException::what(){ return msg.c_str(); } libhtmlpp::HTMLException& libhtmlpp::HTMLException::append(const char *src){ libhtmlpp::HTMLException& libhtmlpp::HTMLException::append(const std::string &src){ msg.append(src); return *this; } Loading @@ -62,7 +62,7 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator[](int errtype){ return *this; } libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const char *src){ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const std::string &src){ return append(src); }; Loading
src/exception.h +2 −2 Original line number Diff line number Diff line Loading @@ -57,9 +57,9 @@ namespace libhtmlpp { enum Type {Note,Warning,Error,Critical}; HTMLException& append(const char *src); HTMLException& append(const std::string &src); HTMLException& operator[](int errtype); HTMLException& operator<<(const char *src); HTMLException& operator<<(const std::string &src); HTMLException& operator<<(int src); private: int curCType; Loading
src/html.h +73 −52 Original line number Diff line number Diff line Loading @@ -44,7 +44,8 @@ namespace libhtmlpp { TextEl=0, HtmlEl=1, CommentEl=2, ScriptEL=3 ScriptEL=3, SvgEL=4 }; class Element { Loading @@ -69,9 +70,9 @@ namespace libhtmlpp { Element(); std::unique_ptr<Element> _nextElement; Element* _prevElement; Element* _nextElement; Element* _firstElement; friend class HtmlElement; friend class TextElement; Loading @@ -83,7 +84,7 @@ namespace libhtmlpp { class HtmlElement : public Element { public: HtmlElement(); HtmlElement(const char* tag); HtmlElement(const std::string &tag); HtmlElement(const HtmlElement &hel); HtmlElement(const HtmlElement *hel); ~HtmlElement(); Loading @@ -94,48 +95,45 @@ namespace libhtmlpp { bool operator==(const HtmlElement *hel); bool operator==(const HtmlElement &hel); void setAttribute(const char* name, const char* value); void setAttribute(const char* name,size_t nlen, const char* value,size_t vlen); void setAttribute(const std::string &name, const std::string &value); void setIntAttribute(const char* name, int value); void setIntAttribute(const std::string &name, int value); const char* getAtributte(const char* name) const; const std::string getAtributte(const std::string &name) const; int getIntAtributte(const char* name); int getIntAtributte(const std::string &name) const; void insertChild(const Element* el); void insertChild(const Element& el); void appendChild(const Element* el); void appendChild(const Element& el); void setTagname(const char *name); const char *getTagname(); void setTagname(const std::string &name); const std::string getTagname() const; HtmlElement *getElementbyID(const char *id) const; HtmlElement *getElementbyTag(const char *tag) const; HtmlElement *getElementbyID(const std::string &id) const; HtmlElement *getElementbyTag(const std::string &tag) const; int getType() const; void remove(Element* el); protected: Element* _childElement; std::unique_ptr<Element> _childElement; struct Attributes { Attributes(); ~Attributes(); std::vector<char> _Key; std::vector<char> _Value; std::vector<char> _CStr; Attributes* _nextAttr; std::unique_ptr<Attributes> _nextAttr; }; private: //if text tagname must be zero std::vector<char> _TagName; std::vector<char> _CStr; //if text Attributes must be zero Attributes* _firstAttr; std::unique_ptr<Attributes> _firstAttr; Attributes* _lastAttr; friend class HtmlString; Loading @@ -147,20 +145,19 @@ namespace libhtmlpp { class TextElement : public Element { public: TextElement(); TextElement(const char *txt); TextElement(const std::string &txt); TextElement(const TextElement &texel); ~TextElement(); TextElement& operator=(const Element &hel); TextElement& operator=(const Element *hel); const char *getText(); void setText(const char *txt); const std::string getText(); void setText(const std::string &txt); int getType() const; protected: std::vector<char> _Text; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -175,13 +172,12 @@ namespace libhtmlpp { CommentElement& operator=(const Element &hel); CommentElement& operator=(const Element *hel); const char *getComment(); void setComment(const char *txt); const std::string getComment(); void setComment(const std::string &txt); int getType() const; protected: std::vector<char> _Comment; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -196,8 +192,8 @@ namespace libhtmlpp { ScriptElement& operator=(const Element &hel); ScriptElement& operator=(const Element *hel); const char *getScript(); void setScript(const char *txt); const std::string getScript(); void setScript(const std::string &txt); int getType() const; Loading @@ -211,7 +207,35 @@ namespace libhtmlpp { Element* _childElement=nullptr; std::vector<char> _Script; std::vector<char> _CStr; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); }; class SvgElement : public HtmlElement{ public: SvgElement(); SvgElement(const SvgElement &svgsrc); ~SvgElement(); SvgElement& operator=(const Element &hel); SvgElement& operator=(const Element *hel); const std::vector<char> getSvg(); void setSvg(const std::string &svg); int getType() const; void insertChild(const Element* el)=delete; void insertChild(const Element& el)=delete; void appendChild(const Element* el)=delete; void appendChild(const Element& el)=delete; protected: Element* _childElement=nullptr; std::vector<char> _Svg; friend class HtmlString; friend void print(Element* el, HtmlString &output,bool formated); friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src); Loading @@ -226,30 +250,25 @@ namespace libhtmlpp { HtmlString(); HtmlString(const HtmlString &str); HtmlString(const HtmlString *str); HtmlString(const char *str); HtmlString(char str); HtmlString(const std::string &str); ~HtmlString(); void append(const char* src, size_t srcsize); void append(const char* src); void append(const std::string &src); void append(HtmlString& hstring); void push_back(const char src); void insert(size_t pos, char src); HtmlString& operator+=(const char* src); HtmlString& operator+=(const std::string &src); HtmlString& operator+=(HtmlString& hstring); HtmlString& operator=(const char* src); HtmlString& operator=(const std::string *src); HtmlString& operator=(const std::string &src); HtmlString& operator=(const HtmlString& src); char operator[](size_t pos) const; HtmlString& operator<<(const char* src); HtmlString& operator<<(std::string &src); HtmlString& operator<<(std::string *src); HtmlString& operator<<(const std::string &src); HtmlString& operator<<(HtmlString src); HtmlString& operator<<(int src); HtmlString& operator<<(unsigned int src); Loading @@ -261,19 +280,20 @@ namespace libhtmlpp { size_t size() const; void clear(); bool empty(); const char * c_str(); const std::vector<char>& data(); const std::string str(); const char *c_str(); libhtmlpp::Element *parse(); bool validate(std::string *err); libhtmlpp::Element &parse(); private: std::unique_ptr<Element> rootEl; void _serialelize(std::vector<char> in, HtmlElement* out); Element *_buildTree(); void _buildtreenode(const DocElements *firstel,const DocElements *lastel); void _buildTree(); void _buildtreenode(std::unique_ptr<DocElements> &firstel,DocElements *lastel); std::vector<char> _Data; std::vector<char> _CStr; std::stack<Element*> _Childs; std::string _Str; friend void HtmlEncode(const std::string &input,HtmlString *output); friend class HtmlPage; }; Loading @@ -285,14 +305,15 @@ namespace libhtmlpp { public: HtmlPage(); ~HtmlPage(); void loadFile(libhtmlpp::HtmlElement &html,const char* path); void saveFile(libhtmlpp::HtmlElement &html,const char* path); void loadFile(libhtmlpp::HtmlElement &html,const std::string &path); void saveFile(libhtmlpp::HtmlElement &html,const std::string &path); void loadString(libhtmlpp::HtmlElement &html,const std::string &src); void loadString(libhtmlpp::HtmlElement &html,const char *src); void loadString(libhtmlpp::HtmlElement &html,const HtmlString &node); void loadString(libhtmlpp::HtmlElement &html,const HtmlString *node); bool isHtml5(); private: void _CheckHeader(const HtmlString& page); bool _Html5 = true; }; class HtmlTable { Loading
test/CMakeLists.txt +11 −7 Original line number Diff line number Diff line # add_executable(csstest csstest.cpp ) # target_link_libraries(csstest htmlpp) add_executable(csstest csstest.cpp ) target_link_libraries(csstest htmlpp) # # add_test(csstest csstest) add_test(csstest csstest) add_executable(htmlpagetest htmlpagetest.cpp) target_link_libraries(htmlpagetest htmlpp-static) #add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html) #add_test(htmlpagetest_wrong htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/wrong.html) add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/html4.html) add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html) add_test(htmlpagetest_wrong htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/wrong.html) set_property(TEST htmlpagetest_wrong PROPERTY WILL_FAIL TRUE ) add_executable(htmlcopytest htmlcopytest.cpp) target_link_libraries(htmlcopytest htmlpp-static) #add_test(htmlcopytest_right htmlcopytest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html) 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)