KVParser.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-25
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #ifndef LS_STD_KV_PARSER_HPP
  10. #define LS_STD_KV_PARSER_HPP
  11. #include <ls_std/base/Class.hpp>
  12. #include <ls_std/base/Types.hpp>
  13. #include "KVDocument.hpp"
  14. #include "KVParseData.hpp"
  15. #include <memory>
  16. namespace ls_std
  17. {
  18. class KVParser : public ls_std::Class
  19. {
  20. public:
  21. explicit KVParser(const std::shared_ptr<ls_std::KVDocument> &_document);
  22. ~KVParser() override = default;
  23. std::shared_ptr<ls_std::KVDocument> getDocument();
  24. void parse(const ls_std::byte_field &_data);
  25. void setDocument(const std::shared_ptr<ls_std::KVDocument> &_document);
  26. private:
  27. std::shared_ptr<ls_std::KVDocument> document{};
  28. void _assignDocument(const std::shared_ptr<ls_std::KVDocument> &_document);
  29. static bool _lineHasPair(ls_std::KVParseData _parseData);
  30. void _parse(const ls_std::byte_field &_data);
  31. void _parsePair(ls_std::KVParseData _parseData);
  32. static ls_std::KVParseData _readLine(const ls_std::byte_field &_data, std::string::size_type _index);
  33. static void _readLineWithUnixLineBreak(ls_std::KVParseData &_parseData);
  34. static void _readLineWithWindowsLineBreak(ls_std::KVParseData &_parseData);
  35. };
  36. }
  37. #endif