You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

2 months ago
  1. #ifndef STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  3. #if defined(_MSC_VER) || \
  4. (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
  5. (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
  6. #pragma once
  7. #endif
  8. #include <cstddef>
  9. namespace YAML {
  10. class StringCharSource {
  11. public:
  12. StringCharSource(const char* str, std::size_t size)
  13. : m_str(str), m_size(size), m_offset(0) {}
  14. operator bool() const { return m_offset < m_size; }
  15. char operator[](std::size_t i) const { return m_str[m_offset + i]; }
  16. bool operator!() const { return !static_cast<bool>(*this); }
  17. const StringCharSource operator+(int i) const {
  18. StringCharSource source(*this);
  19. if (static_cast<int>(source.m_offset) + i >= 0)
  20. source.m_offset += i;
  21. else
  22. source.m_offset = 0;
  23. return source;
  24. }
  25. StringCharSource& operator++() {
  26. ++m_offset;
  27. return *this;
  28. }
  29. StringCharSource& operator+=(std::size_t offset) {
  30. m_offset += offset;
  31. return *this;
  32. }
  33. private:
  34. const char* m_str;
  35. std::size_t m_size;
  36. std::size_t m_offset;
  37. };
  38. }
  39. #endif // STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66