OpenTTD Source 20241224-master-gf74b0cf984
IcuStringIterator Class Reference

String iterator using ICU as a backend. More...

Inheritance diagram for IcuStringIterator:
StringIterator

Public Member Functions

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

Private Attributes

icu::BreakIterator * char_itr
 ICU iterator for characters.
 
icu::BreakIterator * word_itr
 ICU iterator for words.
 
std::vector< UChar > utf16_str
 UTF-16 copy of the string.
 
std::vector< size_t > utf16_to_utf8
 Mapping from UTF-16 code point position to index in the UTF-8 source string.
 

Additional Inherited Members

- Public Types inherited from StringIterator
enum  IterType { ITER_CHARACTER , ITER_WORD }
 Type of the iterator. More...
 
- Static Public Member Functions inherited from StringIterator
static std::unique_ptr< StringIteratorCreate ()
 Create a new iterator instance.
 
- Static Public Attributes inherited from StringIterator
static const size_t END = SIZE_MAX
 Sentinel to indicate end-of-iteration.
 

Detailed Description

String iterator using ICU as a backend.

Definition at line 772 of file string.cpp.

Constructor & Destructor Documentation

◆ IcuStringIterator()

IcuStringIterator::IcuStringIterator ( )
inline

Definition at line 781 of file string.cpp.

◆ ~IcuStringIterator()

IcuStringIterator::~IcuStringIterator ( )
inlineoverride

Definition at line 791 of file string.cpp.

Member Function Documentation

◆ Next()

size_t IcuStringIterator::Next ( IterType  what)
inlineoverridevirtual

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.

Implements StringIterator.

Definition at line 852 of file string.cpp.

References StringIterator::END, IsWhitespace(), StringIterator::ITER_CHARACTER, StringIterator::ITER_WORD, and Utf16DecodeChar().

◆ Prev()

size_t IcuStringIterator::Prev ( IterType  what)
inlineoverridevirtual

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.

Implements StringIterator.

Definition at line 884 of file string.cpp.

References StringIterator::END, IsWhitespace(), StringIterator::ITER_CHARACTER, StringIterator::ITER_WORD, and Utf16DecodeChar().

◆ SetCurPosition()

size_t IcuStringIterator::SetCurPosition ( size_t  pos)
inlineoverridevirtual

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.

Implements StringIterator.

Definition at line 834 of file string.cpp.

◆ SetString()

void IcuStringIterator::SetString ( const char *  s)
inlineoverridevirtual

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.

Implements StringIterator.

Definition at line 797 of file string.cpp.

Field Documentation

◆ char_itr

icu::BreakIterator* IcuStringIterator::char_itr
private

ICU iterator for characters.

Definition at line 774 of file string.cpp.

◆ utf16_str

std::vector<UChar> IcuStringIterator::utf16_str
private

UTF-16 copy of the string.

Definition at line 777 of file string.cpp.

◆ utf16_to_utf8

std::vector<size_t> IcuStringIterator::utf16_to_utf8
private

Mapping from UTF-16 code point position to index in the UTF-8 source string.

Definition at line 778 of file string.cpp.

◆ word_itr

icu::BreakIterator* IcuStringIterator::word_itr
private

ICU iterator for words.

Definition at line 775 of file string.cpp.


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