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

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.

◆ atStart()

UTF8Navigator Dragengine.Utils.UTF8Navigator.atStart ( )

New navigator with position set to start of string.

◆ backward() [1/2]

void Dragengine.Utils.UTF8Navigator.backward ( )

Move one character towards start of the string.

◆ 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.

◆ countCharactersEnd()

int Dragengine.Utils.UTF8Navigator.countCharactersEnd ( )

Count characters from current position to end of string.

◆ 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.

◆ forward() [1/2]

void Dragengine.Utils.UTF8Navigator.forward ( )

Move one character towards end of the string.

◆ 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.

◆ getLength()

int Dragengine.Utils.UTF8Navigator.getLength ( )

Length of string in bytes.

◆ getPosition()

int Dragengine.Utils.UTF8Navigator.getPosition ( )

Position in bytes.

◆ getString()

String Dragengine.Utils.UTF8Navigator.getString ( )

String to navigate.

◆ isAtEnd()

bool Dragengine.Utils.UTF8Navigator.isAtEnd ( )

Position is at end of string.

◆ isAtStart()

bool Dragengine.Utils.UTF8Navigator.isAtStart ( )

Position is at start of string.

◆ 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.

◆ new() [1/4]

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

Create navigator.

◆ 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.

◆ new() [4/4]

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

Create copy of navigator with new position.

◆ operator+()

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

New navigator with moving multiple characters.

◆ operator-()

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

New navigator with moving multiple characters.

◆ setCharacterPosition()

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

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

◆ setFrom()

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

Set navigator from another navigator.

◆ 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.

◆ setPositionBegin()

void Dragengine.Utils.UTF8Navigator.setPositionBegin ( )

Set position to start of string.

◆ setPositionEnd()

void Dragengine.Utils.UTF8Navigator.setPositionEnd ( )

Set position to end of string.

◆ setString()

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

Set string to navigate.

Sets position to 0.


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