/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-11-25 * Changed: 2021-05-01 * * */ #ifndef LS_STD_XML_PARSER_HPP #define LS_STD_XML_PARSER_HPP #include #include #include "XMLDocument.hpp" #include "XMLParseMode.hpp" #include "XMLParseData.hpp" #include namespace ls_std { class XMLParser : public ls_std::Class { public: explicit XMLParser(const std::shared_ptr &_document); ~XMLParser() override = default; std::shared_ptr getDocument(); void parse(const ls_std::byte_field &_data); void setDocument(const std::shared_ptr &_document); protected: static std::pair _readAttribute_(const ls_std::byte_field &_data); static std::list> _readAttributes_(ls_std::byte_field _data); private: uint8_t currentLevel{}; std::shared_ptr document{}; uint8_t maxLevel{}; ls_std::XMLParseMode mode{}; std::list parseData{}; void _analyze(const ls_std::byte_field &_data, std::string::size_type _index); void _assignDocument(const std::shared_ptr &_document); static std::shared_ptr _createDeclaration(const std::list> &_attributes); static std::shared_ptr _createNode(const std::list> &_attributes, const std::string &_name); static std::pair _findAttribute(const std::list> &_attributes, const std::string &_name); static size_t _findAttributeEndPosition(const ls_std::byte_field &_data); static ls_std::byte_field _getNextTagString(const ls_std::byte_field &_data, std::string::size_type _index); void _isClosingTag(const ls_std::byte_field &_data, std::string::size_type _index); void _isDeclaration(const ls_std::byte_field &_data, std::string::size_type _index); void _isOpeningTag(const ls_std::byte_field &_data, std::string::size_type _index); void _isValue(const ls_std::byte_field &_data, std::string::size_type _index); void _mergeNodes(); void _mergeChildrenToParentNode(const std::shared_ptr &_parent, std::list::iterator &_iterator, uint8_t _parentLevel); void _mergeNodesOnCurrentLevel(); void _parse(const ls_std::byte_field &_data); static std::pair _parseAttribute(const ls_std::byte_field &_data); static std::list> _parseAttributes(ls_std::byte_field _data); size_t _parseClosingTag(const ls_std::byte_field &_data, std::string::size_type _index); size_t _parseDeclaration(const ls_std::byte_field &_data, std::string::size_type _index); size_t _parseOpeningTag(const ls_std::byte_field &_data, std::string::size_type _index); static ls_std::byte_field _parseTagName(const ls_std::byte_field &_data); size_t _parseValue(const ls_std::byte_field &_data, std::string::size_type _index); void _reset(); void _setMaxLevel(); }; } #endif