Leviathan  0.8.0.0
Leviathan game engine
Leviathan::StringDataIterator Class Referenceabstract

#include <StringDataIterator.h>

+ Inheritance diagram for Leviathan::StringDataIterator:

Public Member Functions

DLLEXPORT StringDataIterator ()
 
virtual DLLEXPORT ~StringDataIterator ()
 
virtual bool GetNextCharCode (int &codepointreceiver, size_t forward)=0
 Gets the next character unicode code point (usually an ascii value) More...
 
virtual bool GetPreviousCharacter (int &receiver)=0
 Gets the previous character code point. More...
 
virtual void MoveToNextCharacter ()=0
 Moves the iterator forward. More...
 
virtual DLLEXPORT bool ReturnSubString (size_t startpos, size_t endpos, std::string &receiver)
 
virtual DLLEXPORT bool ReturnSubString (size_t startpos, size_t endpos, std::wstring &receiver)
 
virtual size_t CurrentIteratorPosition () const =0
 Gets the position of the iterator, for use with ReturnSubString and others. More...
 
virtual size_t GetLastValidIteratorPosition () const =0
 Gets the last valid index of the underlying string (not the last character but the last byte) More...
 
virtual bool IsPositionValid () const =0
 Returns true when the iterator is still valid. More...
 
virtual DLLEXPORT size_t GetCurrentCharacterNumber () const
 Returns the 0 based character number (NOT position, number of characters) More...
 
virtual DLLEXPORT size_t GetCurrentLineNumber () const
 Returns the 1 based line number. More...
 

Protected Member Functions

DLLEXPORT void CheckLineChange ()
 Updates CurrentLineNumber if currently on a line break. More...
 

Protected Attributes

size_t CurrentCharacterNumber
 
size_t CurrentLineNumber
 The current line number, the amount of
characters. More...
 

Detailed Description

Interface that wraps string for iteration with StringIterator

Subclasses allow different types of data sources to be used with this class

Definition at line 12 of file StringDataIterator.h.

Constructor & Destructor Documentation

◆ StringDataIterator()

DLLEXPORT Leviathan::StringDataIterator::StringDataIterator ( )

Definition at line 13 of file StringDataIterator.cpp.

13  :
15 {
16 
17 }
size_t CurrentLineNumber
The current line number, the amount of characters.

◆ ~StringDataIterator()

DLLEXPORT Leviathan::StringDataIterator::~StringDataIterator ( )
virtual

Definition at line 19 of file StringDataIterator.cpp.

19  {
20 
21 }

Member Function Documentation

◆ CheckLineChange()

DLLEXPORT void Leviathan::StringDataIterator::CheckLineChange ( )
protected

Updates CurrentLineNumber if currently on a line break.

Definition at line 50 of file StringDataIterator.cpp.

50  {
51 
52  int32_t checkchar;
53 
54  if (GetNextCharCode(checkchar, 0) && StringOperations::IsLineTerminator(checkchar)) {
55 
56  // Check for multiline //
57  int32_t evenfurthercharacter;
58  if (!GetNextCharCode(evenfurthercharacter, 1) ||
59  !StringOperations::IsLineTerminator(checkchar, evenfurthercharacter))
60  {
62  }
63  }
64 }
virtual bool GetNextCharCode(int &codepointreceiver, size_t forward)=0
Gets the next character unicode code point (usually an ascii value)
static bool IsLineTerminator(int32_t codepoint)
size_t CurrentLineNumber
The current line number, the amount of characters.

◆ CurrentIteratorPosition()

virtual size_t Leviathan::StringDataIterator::CurrentIteratorPosition ( ) const
pure virtual

Gets the position of the iterator, for use with ReturnSubString and others.

Implemented in Leviathan::UTF8PointerDataIterator, Leviathan::StringClassPointerIterator< STRType >, and Leviathan::StringClassDataIterator< STRType >.

◆ GetCurrentCharacterNumber()

DLLEXPORT size_t Leviathan::StringDataIterator::GetCurrentCharacterNumber ( ) const
virtual

Returns the 0 based character number (NOT position, number of characters)

Definition at line 42 of file StringDataIterator.cpp.

42  {
44 }

◆ GetCurrentLineNumber()

DLLEXPORT size_t Leviathan::StringDataIterator::GetCurrentLineNumber ( ) const
virtual

Returns the 1 based line number.

Definition at line 46 of file StringDataIterator.cpp.

46  {
47  return CurrentLineNumber;
48 }
size_t CurrentLineNumber
The current line number, the amount of characters.

◆ GetLastValidIteratorPosition()

virtual size_t Leviathan::StringDataIterator::GetLastValidIteratorPosition ( ) const
pure virtual

Gets the last valid index of the underlying string (not the last character but the last byte)

Implemented in Leviathan::UTF8PointerDataIterator, Leviathan::StringClassPointerIterator< STRType >, and Leviathan::StringClassDataIterator< STRType >.

◆ GetNextCharCode()

virtual bool Leviathan::StringDataIterator::GetNextCharCode ( int &  codepointreceiver,
size_t  forward 
)
pure virtual

Gets the next character unicode code point (usually an ascii value)

Parameters
forwardDefines how many characters past the current position the wanted character is. This is usually 0 or 1
Note
This is used to get the next character but also used for peeking so this should not increment the underlying iterator
Returns
Returns true when the input is still valid

Implemented in Leviathan::UTF8PointerDataIterator, Leviathan::StringClassPointerIterator< STRType >, and Leviathan::StringClassDataIterator< STRType >.

◆ GetPreviousCharacter()

virtual bool Leviathan::StringDataIterator::GetPreviousCharacter ( int &  receiver)
pure virtual

Gets the previous character code point.

Returns
True when succeeded false when this is the first character and there is nothing before it
See also
GetNextCharCode

Implemented in Leviathan::UTF8PointerDataIterator, Leviathan::StringClassPointerIterator< STRType >, and Leviathan::StringClassDataIterator< STRType >.

◆ IsPositionValid()

virtual bool Leviathan::StringDataIterator::IsPositionValid ( ) const
pure virtual

◆ MoveToNextCharacter()

virtual void Leviathan::StringDataIterator::MoveToNextCharacter ( )
pure virtual

◆ ReturnSubString() [1/2]

DLLEXPORT bool Leviathan::StringDataIterator::ReturnSubString ( size_t  startpos,
size_t  endpos,
std::string &  receiver 
)
virtual

Reimplemented in Leviathan::UTF8PointerDataIterator.

Definition at line 23 of file StringDataIterator.cpp.

25 {
26  DEBUG_BREAK;
27  LEVIATHAN_ASSERT(0, "StringDataIterator doesn't support getting with type: string, "
28  "make sure your provided data source string type is the same as the "
29  "request template type");
30  return false;
31 }

◆ ReturnSubString() [2/2]

DLLEXPORT bool Leviathan::StringDataIterator::ReturnSubString ( size_t  startpos,
size_t  endpos,
std::wstring &  receiver 
)
virtual

Definition at line 33 of file StringDataIterator.cpp.

35 {
36  DEBUG_BREAK;
37  LEVIATHAN_ASSERT(0, "StringDataIterator doesn't support getting with type: wstring, make "
38  "sure your provided data source string type is the same as the request template type");
39  return false;
40 }

Member Data Documentation

◆ CurrentCharacterNumber

size_t Leviathan::StringDataIterator::CurrentCharacterNumber
protected

Must be the current character number, not the number of bytes for example one utf8 character might be 4 bytes

Definition at line 78 of file StringDataIterator.h.

◆ CurrentLineNumber

size_t Leviathan::StringDataIterator::CurrentLineNumber
protected

The current line number, the amount of
characters.

Definition at line 81 of file StringDataIterator.h.


The documentation for this class was generated from the following files: