3#ifndef PL_INCLUDING_BASICS_H
4# error "Please don't include StringIterator.h directly, but instead include Foundation/Basics.h"
11 using iterator_category = std::bidirectional_iterator_tag;
12 using value_type = plUInt32;
13 using difference_type = std::ptrdiff_t;
14 using pointer =
const char*;
15 using reference = plUInt32;
17 PL_DECLARE_POD_TYPE();
23 PL_FORCE_INLINE
explicit plStringIterator(
const char* pStartPtr,
const char* pEndPtr,
const char* pCurPtr)
25 m_pStartPtr = pStartPtr;
31 PL_ALWAYS_INLINE
bool IsValid()
const {
return m_pCurPtr !=
nullptr && m_pCurPtr != m_pEndPtr; }
40 PL_ALWAYS_INLINE
const char*
GetData()
const {
return m_pCurPtr; }
49 const char* pPrevElement = m_pCurPtr;
51 if (m_pCurPtr < m_pEndPtr)
56 return static_cast<plUInt32
>(m_pCurPtr - pPrevElement);
62 if (m_pCurPtr < m_pEndPtr)
73 if (m_pStartPtr < m_pCurPtr)
148 PL_ASSERT_DEV((szCurPos >= m_pStartPtr) && (szCurPos <= m_pEndPtr),
"New position must still be inside the iterator's range.");
150 m_pCurPtr = szCurPos;
154 const char* m_pStartPtr =
nullptr;
155 const char* m_pEndPtr =
nullptr;
156 const char* m_pCurPtr =
nullptr;
164 using iterator_category = std::bidirectional_iterator_tag;
165 using value_type = plUInt32;
166 using difference_type = std::ptrdiff_t;
167 using pointer =
const char*;
168 using reference = plUInt32;
170 PL_DECLARE_POD_TYPE();
178 m_pStartPtr = pStartPtr;
182 if (m_pStartPtr >= m_pEndPtr)
186 else if (m_pCurPtr == m_pEndPtr)
193 PL_ALWAYS_INLINE
bool IsValid()
const {
return (m_pCurPtr !=
nullptr); }
202 PL_ALWAYS_INLINE
const char*
GetData()
const {
return m_pCurPtr; }
211 if (m_pCurPtr !=
nullptr && m_pStartPtr < m_pCurPtr)
222 if (m_pCurPtr !=
nullptr)
224 const char* szOldPos = m_pCurPtr;
227 if (m_pCurPtr == m_pEndPtr)
228 m_pCurPtr = szOldPos;
233 m_pCurPtr = m_pStartPtr;
305 PL_ASSERT_DEV((szCurPos ==
nullptr) || ((szCurPos >= m_pStartPtr) && (szCurPos < m_pEndPtr)),
"New position must still be inside the iterator's range.");
307 m_pCurPtr = szCurPos;
311 const char* m_pStartPtr =
nullptr;
312 const char* m_pEndPtr =
nullptr;
313 const char* m_pCurPtr =
nullptr;
static plUInt32 ConvertUtf8ToUtf32(const char *pFirstChar)
Converts the UTF-8 character that starts at pFirstChar into a UTF-32 character.
Definition UnicodeUtils_inl.h:124
static plResult MoveToNextUtf8(const char *&ref_szUtf8, plUInt32 uiNumCharacters=1)
Moves the given string pointer ahead to the next Utf8 character sequence.
Definition UnicodeUtils_inl.h:201
static plResult MoveToPriorUtf8(const char *&ref_szUtf8, const char *szUtf8Start, plUInt32 uiNumCharacters=1)
Moves the given string pointer backwards to the previous Utf8 character sequence.
Definition UnicodeUtils_inl.h:241
void AssertSuccess(const char *szMsg=nullptr, const char *szDetails=nullptr) const
Asserts that the function succeeded. In case of failure, the program will terminate.
Definition Status.cpp:7
STL forward iterator used by all string classes. Iterates over unicode characters....
Definition StringIterator.h:10
PL_ALWAYS_INLINE plStringIterator operator-(difference_type d) const
Returns an iterator that is advanced backwards by d characters.
Definition StringIterator.h:136
PL_ALWAYS_INLINE const char * GetData() const
Returns the address the iterator currently points to.
Definition StringIterator.h:40
PL_ALWAYS_INLINE plUInt32 operator*() const
Returns the currently pointed to character in Utf32 encoding.
Definition StringIterator.h:37
PL_ALWAYS_INLINE plUInt32 Advance()
Advances the iterated to the next character, same as operator++, but returns how many bytes were cons...
Definition StringIterator.h:47
PL_ALWAYS_INLINE plStringIterator operator+(difference_type d) const
Returns an iterator that is advanced forwards by d characters.
Definition StringIterator.h:128
PL_ALWAYS_INLINE plUInt32 GetCharacter() const
Returns the currently pointed to character in Utf32 encoding.
Definition StringIterator.h:34
PL_ALWAYS_INLINE plStringIterator & operator++()
Move to the next Utf8 character.
Definition StringIterator.h:60
PL_ALWAYS_INLINE plStringIterator operator--(int)
Move to the previous Utf8 character.
Definition StringIterator.h:90
PL_ALWAYS_INLINE plStringIterator()=default
Constructs an invalid iterator.
void SetCurrentPosition(const char *szCurPos)
Allows to set the 'current' iteration position to a different value.
Definition StringIterator.h:146
PL_FORCE_INLINE plStringIterator(const char *pStartPtr, const char *pEndPtr, const char *pCurPtr)
Constructs either a begin or end iterator for the given string.
Definition StringIterator.h:23
PL_ALWAYS_INLINE bool operator==(const plStringIterator &it2) const
Checks whether the two iterators point to the same element.
Definition StringIterator.h:43
PL_FORCE_INLINE void operator-=(difference_type d)
Moves the iterator backwards by d characters. Does not move it beyond the range's start.
Definition StringIterator.h:113
PL_ALWAYS_INLINE bool IsValid() const
Checks whether this iterator points to a valid element. Invalid iterators either point to m_pEndPtr o...
Definition StringIterator.h:31
PL_ALWAYS_INLINE plStringIterator & operator--()
Move to the previous Utf8 character.
Definition StringIterator.h:71
PL_ALWAYS_INLINE plStringIterator operator++(int)
Move to the next Utf8 character.
Definition StringIterator.h:82
PL_FORCE_INLINE void operator+=(difference_type d)
Advances the iterator forwards by d characters. Does not move it beyond the range's end.
Definition StringIterator.h:98
STL reverse iterator used by all string classes. Iterates over unicode characters....
Definition StringIterator.h:163
PL_ALWAYS_INLINE plUInt32 GetCharacter() const
Returns the currently pointed to character in Utf32 encoding.
Definition StringIterator.h:196
PL_ALWAYS_INLINE plStringReverseIterator operator-(difference_type d) const
Returns an iterator that is advanced backwards by d characters.
Definition StringIterator.h:293
PL_FORCE_INLINE plStringReverseIterator & operator++()
Move to the next Utf8 character.
Definition StringIterator.h:209
PL_ALWAYS_INLINE bool operator==(const plStringReverseIterator &it2) const
Checks whether the two iterators point to the same element.
Definition StringIterator.h:205
PL_ALWAYS_INLINE plStringReverseIterator operator+(difference_type d) const
Returns an iterator that is advanced forwards by d characters.
Definition StringIterator.h:285
PL_FORCE_INLINE void SetCurrentPosition(const char *szCurPos)
Allows to set the 'current' iteration position to a different value.
Definition StringIterator.h:303
PL_ALWAYS_INLINE plUInt32 operator*() const
Returns the currently pointed to character in Utf32 encoding.
Definition StringIterator.h:199
PL_ALWAYS_INLINE plStringReverseIterator operator--(int)
Move to the previous Utf8 character.
Definition StringIterator.h:247
PL_FORCE_INLINE void operator+=(difference_type d)
Advances the iterator forwards by d characters. Does not move it beyond the range's end.
Definition StringIterator.h:255
PL_FORCE_INLINE void operator-=(difference_type d)
Moves the iterator backwards by d characters. Does not move it beyond the range's start.
Definition StringIterator.h:270
PL_ALWAYS_INLINE const char * GetData() const
Returns the address the iterator currently points to.
Definition StringIterator.h:202
PL_ALWAYS_INLINE plStringReverseIterator()=default
Constructs an invalid iterator.
PL_ALWAYS_INLINE bool IsValid() const
Checks whether this iterator points to a valid element.
Definition StringIterator.h:193
PL_FORCE_INLINE plStringReverseIterator & operator--()
Move to the previous Utf8 character.
Definition StringIterator.h:220
PL_FORCE_INLINE plStringReverseIterator(const char *pStartPtr, const char *pEndPtr, const char *pCurPtr)
Constructs either a rbegin or rend iterator for the given string.
Definition StringIterator.h:176
PL_ALWAYS_INLINE plStringReverseIterator operator++(int)
Move to the next Utf8 character.
Definition StringIterator.h:239