OpenTTD Source 20241224-master-gf74b0cf984
StringIterator Class Referenceabstract

Class for iterating over different kind of parts of a string. More...

#include <string_base.h>

Inheritance diagram for StringIterator:
IcuStringIterator OSXStringIterator UniscribeStringIterator

Public Types

enum  IterType { ITER_CHARACTER , ITER_WORD }
 Type of the iterator. More...
 

Public Member Functions

virtual void SetString (const char *s)=0
 Set a new iteration string.
 
virtual size_t SetCurPosition (size_t pos)=0
 Change the current string cursor.
 
virtual size_t Next (IterType what=ITER_CHARACTER)=0
 Advance the cursor by one iteration unit.
 
virtual size_t Prev (IterType what=ITER_CHARACTER)=0
 Move the cursor back by one iteration unit.
 

Static Public Member Functions

static std::unique_ptr< StringIteratorCreate ()
 Create a new iterator instance.
 

Static Public Attributes

static const size_t END = SIZE_MAX
 Sentinel to indicate end-of-iteration.
 

Detailed Description

Class for iterating over different kind of parts of a string.

Definition at line 14 of file string_base.h.

Member Enumeration Documentation

◆ IterType

Type of the iterator.

Enumerator
ITER_CHARACTER 

Iterate over characters (or more exactly grapheme clusters).

ITER_WORD 

Iterate over words.

Definition at line 17 of file string_base.h.

Constructor & Destructor Documentation

◆ StringIterator()

StringIterator::StringIterator ( )
inlineprotected

Definition at line 61 of file string_base.h.

Member Function Documentation

◆ Create()

std::unique_ptr< StringIterator > StringIterator::Create ( )
static

Create a new iterator instance.

Returns
New iterator instance.

Definition at line 917 of file string.cpp.

◆ Next()

virtual size_t StringIterator::Next ( IterType  what = ITER_CHARACTER)
pure virtual

Advance the cursor by one iteration unit.

Returns
New cursor position (in bytes) or END if the cursor is already at the end of the string.

Implemented in OSXStringIterator, UniscribeStringIterator, and IcuStringIterator.

◆ Prev()

virtual size_t StringIterator::Prev ( IterType  what = ITER_CHARACTER)
pure virtual

Move the cursor back by one iteration unit.

Returns
New cursor position (in bytes) or END if the cursor is already at the start of the string.

Implemented in OSXStringIterator, UniscribeStringIterator, and IcuStringIterator.

◆ SetCurPosition()

virtual size_t StringIterator::SetCurPosition ( size_t  pos)
pure virtual

Change the current string cursor.

Parameters
posNew cursor position.
Returns
Actual new cursor position at the next valid character boundary.
Precondition
pos has to be inside the current string.

Implemented in OSXStringIterator, UniscribeStringIterator, and IcuStringIterator.

◆ SetString()

virtual void StringIterator::SetString ( const char *  s)
pure virtual

Set a new iteration string.

Must also be called if the string contents changed. The cursor is reset to the start of the string.

Parameters
sNew string.

Implemented in OSXStringIterator, UniscribeStringIterator, and IcuStringIterator.

Field Documentation

◆ END

const size_t StringIterator::END = SIZE_MAX
static

Sentinel to indicate end-of-iteration.

Definition at line 23 of file string_base.h.

Referenced by Textbuf::MoveNext(), Textbuf::MovePrev(), IcuStringIterator::Next(), IcuStringIterator::Prev(), and Textbuf::UpdateStringIter().


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