XmlParser.hpp 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-25
  6. * Changed: 2023-02-22
  7. *
  8. * */
  9. #ifndef LS_STD_XML_PARSER_HPP
  10. #define LS_STD_XML_PARSER_HPP
  11. #include "XmlDocument.hpp"
  12. #include "XmlParseMode.hpp"
  13. #include "XmlParseParameter.hpp"
  14. #include <list>
  15. #include <ls-std/core/Class.hpp>
  16. #include <ls-std/core/type/Types.hpp>
  17. #include <ls-std/os/dynamic-goal.hpp>
  18. namespace ls::std::io
  19. {
  20. class LS_STD_DYNAMIC_GOAL XmlParser : public ls::std::core::Class
  21. {
  22. public:
  23. explicit XmlParser(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document);
  24. ~XmlParser() noexcept override;
  25. [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlDocument> getDocument();
  26. void parse(const ls::std::core::type::byte_field &_data);
  27. void setDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document);
  28. protected:
  29. [[nodiscard]] static ::std::pair<::std::string, ::std::string> _readAttribute_(const ls::std::core::type::byte_field &_data);
  30. [[nodiscard]] static ::std::list<::std::pair<::std::string, ::std::string>> _readAttributes_(ls::std::core::type::byte_field _data);
  31. private:
  32. uint8_t currentLevel{};
  33. ::std::shared_ptr<ls::std::io::XmlDocument> document{};
  34. uint8_t maxLevel{};
  35. ls::std::io::XmlParseMode mode{};
  36. ::std::list<ls::std::io::XmlParseParameter> parseParameters{};
  37. void _analyze(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  38. void _assignDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document);
  39. [[nodiscard]] static bool _contains(const ::std::string &_text, const ::std::string &_searchText);
  40. [[nodiscard]] static ::std::shared_ptr<ls::std::io::XmlDeclaration> _createDeclaration(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes);
  41. [[nodiscard]] static ::std::shared_ptr<ls::std::io::XmlNode> _createNode(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes, const ::std::string &_name);
  42. [[nodiscard]] static bool _endsWith(const ::std::string &_text, const ::std::string &_ending);
  43. [[nodiscard]] static ::std::pair<::std::string, ::std::string> _findAttribute(const ::std::list<::std::pair<::std::string, ::std::string>> &_attributes, const ::std::string &_name);
  44. [[nodiscard]] static size_t _findAttributeEndPosition(const ls::std::core::type::byte_field &_data);
  45. [[nodiscard]] static ls::std::core::type::byte_field _getNextTagString(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  46. void _isClosingTag(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  47. void _isDeclaration(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  48. void _isOpeningTag(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  49. void _isValue(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  50. void _mergeNodes();
  51. void _mergeChildrenToParentNode(const ::std::shared_ptr<ls::std::io::XmlNode> &_parent, ::std::list<ls::std::io::XmlParseParameter>::iterator &_iterator, uint8_t _parentLevel);
  52. void _mergeNodesOnCurrentLevel();
  53. void _parse(const ls::std::core::type::byte_field &_data);
  54. [[nodiscard]] static ::std::pair<::std::string, ::std::string> _parseAttribute(const ls::std::core::type::byte_field &_data);
  55. [[nodiscard]] static ::std::list<::std::pair<::std::string, ::std::string>> _parseAttributes(ls::std::core::type::byte_field _data);
  56. [[nodiscard]] size_t _parseClosingTag(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  57. [[nodiscard]] size_t _parseDeclaration(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  58. [[nodiscard]] size_t _parseOpeningTag(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  59. [[nodiscard]] static ls::std::core::type::byte_field _parseTagName(const ls::std::core::type::byte_field &_data);
  60. [[nodiscard]] size_t _parseValue(const ls::std::core::type::byte_field &_data, ::std::string::size_type _index);
  61. void _reset();
  62. void _setMaxLevel();
  63. };
  64. }
  65. #endif