OpenTTD
Public Member Functions | Private Attributes
IcuStringIterator Class Reference

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

Inheritance diagram for IcuStringIterator:
StringIterator

Public Member Functions

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

Private Attributes

icu::BreakIterator * char_itr
 ICU iterator for characters.
 
icu::BreakIterator * word_itr
 ICU iterator for words.
 
SmallVector< UChar, 32 > utf16_str
 UTF-16 copy of the string.
 
SmallVector< size_t, 32 > 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 StringIteratorCreate ()
 Create a new iterator instance. More...
 
- Static Public Attributes inherited from StringIterator
static const size_t END = SIZE_MAX
 Sentinel to indicate end-of-iteration. More...
 

Detailed Description

String iterator using ICU as a backend.

Definition at line 594 of file string.cpp.

Member Function Documentation

◆ Next()

virtual size_t IcuStringIterator::Next ( IterType  what)
inlinevirtual

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 674 of file string.cpp.

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

◆ Prev()

virtual size_t IcuStringIterator::Prev ( IterType  what)
inlinevirtual

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 706 of file string.cpp.

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

◆ SetCurPosition()

virtual size_t IcuStringIterator::SetCurPosition ( size_t  pos)
inlinevirtual

Change the current string cursor.

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

Implements StringIterator.

Definition at line 656 of file string.cpp.

References SmallVector< T, S >::Length().

Referenced by StringIterator::Create().

◆ SetString()

virtual void IcuStringIterator::SetString ( const char *  s)
inlinevirtual

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 619 of file string.cpp.

References SmallVector< T, S >::Clear().

Referenced by StringIterator::Create().


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