Drag[en]gine Script Module DragonScript 1.35
Loading...
Searching...
No Matches
Dragengine.Utils.UTF8Navigator Class Reference

Navigate UTF-8 encoded string. More...

Inheritance diagram for Dragengine.Utils.UTF8Navigator:

Public Member Functions

UTF8Navigator atEnd ()
 New navigator with position set to end of string.
UTF8Navigator atStart ()
 New navigator with position set to start of string.
void backward ()
 Move one character towards start of the string.
void backward (int count)
 Move multiple characters towards start of the string.
int countCharacters ()
 Count characters from start of string to current position.
int countCharactersEnd ()
 Count characters from current position to end of string.
int decodeCharacter ()
 Decode UTF-8 character at position.
void forward ()
 Move one character towards end of the string.
void forward (int count)
 Move multiple characters towards end of the string.
int getCharacterCount ()
 Count of characters in string.
int getLength ()
 Length of string in bytes.
int getPosition ()
 Position in bytes.
String getString ()
 String to navigate.
bool isAtEnd ()
 Position is at end of string.
bool isAtStart ()
 Position is at start of string.
void move (int count)
 Move multiple characters.
UTF8Navigator new (String string)
 Create navigator.
UTF8Navigator new (String string, int position)
 Create navigator with position.
UTF8Navigator new (UTF8Navigator navigator)
 Create copy of navigator.
UTF8Navigator new (UTF8Navigator navigator, int position)
 Create copy of navigator with new position.
UTF8Navigator operator+ (int count)
 New navigator with moving multiple characters.
UTF8Navigator operator- (int count)
 New navigator with moving multiple characters.
void setCharacterPosition (int position)
 Set position in bytes matching character position clamped to valid range.
void setFrom (UTF8Navigator navigator)
 Set navigator from another navigator.
void setPosition (int position)
 Set position in bytes clamped to valid range.
void setPositionBegin ()
 Set position to start of string.
void setPositionEnd ()
 Set position to end of string.
void setString (String string)
 Set string to navigate.

Detailed Description

Navigate UTF-8 encoded string.

Version
1.16

Stores the string and position in bytes from the start of the string. The position moves forward and backward in a way it always stops at the first byte of a UTF-8 character. The following table illustrates the possible UTF-8 byte values:

^ Byte 1 ^ Byte 2 ^ Byte 3 ^ Byte 4 ^ | 0xxxxxxx | - | - | - | | 110xxxxx | 10xxxxxx | - | - | | 1110xxxx | 10xxxxxx | 10xxxxxx | - | | 11110xxx | 10xxxxxx | 10xxxxxx | 10xxxxxx |

Hence all bytes with the high bits 10 are following bytes and can be skipped.

In addition to moving by UTF-8 character it is also possible to count the characters from the begin of the string to the current position. This allows to properly position a cursor using the character position.

Member Function Documentation

◆ atEnd()

UTF8Navigator Dragengine.Utils.UTF8Navigator.atEnd ( )

New navigator with position set to end of string.

Referenced by operator-().

◆ atStart()

UTF8Navigator Dragengine.Utils.UTF8Navigator.atStart ( )

New navigator with position set to start of string.

Referenced by operator-().

◆ backward() [1/2]

void Dragengine.Utils.UTF8Navigator.backward ( )

Move one character towards start of the string.

References setPosition().

Referenced by operator-().

◆ backward() [2/2]

void Dragengine.Utils.UTF8Navigator.backward ( int count)

Move multiple characters towards start of the string.

◆ countCharacters()

int Dragengine.Utils.UTF8Navigator.countCharacters ( )

Count characters from start of string to current position.

Referenced by operator-().

◆ countCharactersEnd()

int Dragengine.Utils.UTF8Navigator.countCharactersEnd ( )

Count characters from current position to end of string.

References getPosition().

Referenced by operator-().

◆ decodeCharacter()

int Dragengine.Utils.UTF8Navigator.decodeCharacter ( )

Decode UTF-8 character at position.

If the position is at the end of string or the UTF-8 character is invalid -1 is returned.

Referenced by operator-().

◆ forward() [1/2]

void Dragengine.Utils.UTF8Navigator.forward ( )

Move one character towards end of the string.

Referenced by operator-().

◆ forward() [2/2]

void Dragengine.Utils.UTF8Navigator.forward ( int count)

Move multiple characters towards end of the string.

◆ getCharacterCount()

int Dragengine.Utils.UTF8Navigator.getCharacterCount ( )

Count of characters in string.

Referenced by setPositionEnd().

◆ getLength()

int Dragengine.Utils.UTF8Navigator.getLength ( )

Length of string in bytes.

Referenced by new(), and setCharacterPosition().

◆ getPosition()

int Dragengine.Utils.UTF8Navigator.getPosition ( )

Position in bytes.

References getString().

Referenced by countCharactersEnd().

◆ getString()

String Dragengine.Utils.UTF8Navigator.getString ( )

String to navigate.

Referenced by getPosition().

◆ isAtEnd()

bool Dragengine.Utils.UTF8Navigator.isAtEnd ( )

Position is at end of string.

Referenced by setPositionEnd().

◆ isAtStart()

bool Dragengine.Utils.UTF8Navigator.isAtStart ( )

Position is at start of string.

References setString().

Referenced by move().

◆ move()

void Dragengine.Utils.UTF8Navigator.move ( int count)

Move multiple characters.

If count is positive moves towards the end of string. If count is negative moves towards the start of string. Does nothing if count is 0.

References isAtStart().

Referenced by operator-().

◆ new() [1/4]

UTF8Navigator Dragengine.Utils.UTF8Navigator.new ( String string)

Create navigator.

References new().

Referenced by new().

◆ new() [2/4]

UTF8Navigator Dragengine.Utils.UTF8Navigator.new ( String string,
int position )

Create navigator with position.

◆ new() [3/4]

UTF8Navigator Dragengine.Utils.UTF8Navigator.new ( UTF8Navigator navigator)

Create copy of navigator.

References getLength().

◆ new() [4/4]

UTF8Navigator Dragengine.Utils.UTF8Navigator.new ( UTF8Navigator navigator,
int position )

Create copy of navigator with new position.

References setPosition().

◆ operator+()

UTF8Navigator Dragengine.Utils.UTF8Navigator.operator+ ( int count)

New navigator with moving multiple characters.

References setCharacterPosition().

◆ operator-()

UTF8Navigator Dragengine.Utils.UTF8Navigator.operator- ( int count)

◆ setCharacterPosition()

void Dragengine.Utils.UTF8Navigator.setCharacterPosition ( int position)

Set position in bytes matching character position clamped to valid range.

References getLength().

Referenced by operator+().

◆ setFrom()

void Dragengine.Utils.UTF8Navigator.setFrom ( UTF8Navigator navigator)

Set navigator from another navigator.

Referenced by operator-().

◆ setPosition()

void Dragengine.Utils.UTF8Navigator.setPosition ( int position)

Set position in bytes clamped to valid range.

If position is not at valid first byte moves backward until valid first first byte.

Referenced by backward(), new(), and setString().

◆ setPositionBegin()

void Dragengine.Utils.UTF8Navigator.setPositionBegin ( )

Set position to start of string.

Referenced by operator-().

◆ setPositionEnd()

void Dragengine.Utils.UTF8Navigator.setPositionEnd ( )

Set position to end of string.

References getCharacterCount(), and isAtEnd().

Referenced by operator-().

◆ setString()

void Dragengine.Utils.UTF8Navigator.setString ( String string)

Set string to navigate.

Sets position to 0.

References setPosition().

Referenced by isAtStart().


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