CLegacyConfigParser.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /// Parser for any text files from H3
  14. class DLL_LINKAGE CLegacyConfigParser
  15. {
  16. std::string fileEncoding;
  17. std::unique_ptr<char[]> data;
  18. const char * curr;
  19. const char * end;
  20. /// extracts part of quoted string.
  21. std::string extractQuotedPart();
  22. /// extracts quoted string. Any end of lines are ignored, double-quote is considered as "escaping"
  23. std::string extractQuotedString();
  24. /// extracts non-quoted string
  25. std::string extractNormalString();
  26. /// reads "raw" string without encoding conversion
  27. std::string readRawString();
  28. public:
  29. /// read one entry from current line. Return ""/0 if end of line reached
  30. std::string readString();
  31. float readNumber();
  32. template <typename numeric>
  33. std::vector<numeric> readNumArray(size_t size)
  34. {
  35. std::vector<numeric> ret;
  36. ret.reserve(size);
  37. while (size--)
  38. ret.push_back(readNumber());
  39. return ret;
  40. }
  41. /// returns true if next entry is empty
  42. bool isNextEntryEmpty() const;
  43. /// end current line
  44. bool endLine();
  45. explicit CLegacyConfigParser(const TextPath & URI);
  46. };
  47. VCMI_LIB_NAMESPACE_END