CLegacyConfigParser.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * CLegacyConfigParser.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "filesystem/ResourcePath.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. //class CInputStream;
  14. //class JsonNode;
  15. //class JsonSerializeFormat;
  16. /// Parser for any text files from H3
  17. class DLL_LINKAGE CLegacyConfigParser
  18. {
  19. std::string fileEncoding;
  20. std::unique_ptr<char[]> data;
  21. char * curr;
  22. char * end;
  23. /// extracts part of quoted string.
  24. std::string extractQuotedPart();
  25. /// extracts quoted string. Any end of lines are ignored, double-quote is considered as "escaping"
  26. std::string extractQuotedString();
  27. /// extracts non-quoted string
  28. std::string extractNormalString();
  29. /// reads "raw" string without encoding conversion
  30. std::string readRawString();
  31. public:
  32. /// read one entry from current line. Return ""/0 if end of line reached
  33. std::string readString();
  34. float readNumber();
  35. template <typename numeric>
  36. std::vector<numeric> readNumArray(size_t size)
  37. {
  38. std::vector<numeric> ret;
  39. ret.reserve(size);
  40. while (size--)
  41. ret.push_back((numeric)readNumber());
  42. return ret;
  43. }
  44. /// returns true if next entry is empty
  45. bool isNextEntryEmpty() const;
  46. /// end current line
  47. bool endLine();
  48. explicit CLegacyConfigParser(const TextPath & URI);
  49. };
  50. VCMI_LIB_NAMESPACE_END