Utf8 - stingray.Utf8 namespace reference - Stingray Lua API Reference

stingray.Utf8 namespace reference

Description

All strings that the engine uses are UTF-8 encoded.

This interface provides helper functions for dealing with UTF-8 encoded strings, although it is rarely necessary to inspect strings at such a low level that knowledge of the UTF-8 format is required.

Functions

Parameters

string :

string

The string you want to test.

index :

integer

The starting byte for the string search.

Returns

integer

The index in the string where the UTF-8 character pointed to by the index value begins. This may be the same as the index value, or it may be lower if the index value points to the middle byte of a multi-byte character.

integer

The index of the next UTF-8 character in the string. For one-byte characters, this is begin + 1. For a two-byte character, this is begin + 2, etc.

For example, assume that the string comes in UTF-8 format from the engine:

Utf8.location("aa", 1) => 1, 2

Utf8.location("aa", 2) => 2, 3

Utf8.location("aåa", 1) => 1, 2

Utf8.location("aåa", 2) => 2, 4

Utf8.location("aåa", 3) => 2, 4

Utf8.location("aåa", 4) => 4, 5
Parameters

string :

string

The string to transform.

Returns

string

A lower-case version of the string.

Parameters

string :

string

The string to transform.

Returns

string

An upper-case version of the string.

This function uses the upper case mapping from UnicodeData.txt. This means that it is locale-independent, but does not handle language-specific mappings. See Character Properties, Case Mappings & Names FAQ for more information.

Parameters

string :

string

The string to test.

Returns

boolean

Returns true if the string is a valid UTF-8 string; returns false if it contains non-UTF-8-encoded characters.