File indexing completed on 2025-05-12 09:08:10
0001 #ifndef STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003
0004 #if defined(_MSC_VER) || \
0005 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006 (__GNUC__ >= 4))
0007 #pragma once
0008 #endif
0009
0010 #include <cstddef>
0011
0012 namespace SHERPA_YAML {
0013 class StringCharSource {
0014 public:
0015 StringCharSource(const char* str, std::size_t size)
0016 : m_str(str), m_size(size), m_offset(0) {}
0017
0018 operator bool() const { return m_offset < m_size; }
0019 char operator[](std::size_t i) const { return m_str[m_offset + i]; }
0020 bool operator!() const { return !static_cast<bool>(*this); }
0021
0022 const StringCharSource operator+(int i) const {
0023 StringCharSource source(*this);
0024 if (static_cast<int>(source.m_offset) + i >= 0)
0025 source.m_offset += i;
0026 else
0027 source.m_offset = 0;
0028 return source;
0029 }
0030
0031 StringCharSource& operator++() {
0032 ++m_offset;
0033 return *this;
0034 }
0035
0036 StringCharSource& operator+=(std::size_t offset) {
0037 m_offset += offset;
0038 return *this;
0039 }
0040
0041 private:
0042 const char* m_str;
0043 std::size_t m_size;
0044 std::size_t m_offset;
0045 };
0046 }
0047
0048 #endif