class UtfString implements ArrayAccess

Implements array-like access for UTF-8 strings.

In this library, this class should be used to parse UTF-8 queries.

Properties

string $str The raw, multi-byte string.
int $byteIdx The index of current byte.
int $charIdx The index of current character.
int $byteLen The length of the string (in bytes).
int $charLen The length of the string (in characters).

Methods

__construct(string $str)

Constructor.

bool
offsetExists(int $offset)

Checks if the given offset exists.

string
offsetGet(int $offset)

Gets the character at given offset.

offsetSet(int $offset, string $value)

Sets the value of a character.

offsetUnset(int $offset)

Unsets an index.

static int
getCharLength(string $byte)

Gets the length of an UTF-8 character.

int
length()

Returns the length in characters of the string.

string
__toString()

Returns the contained string.

Details

at line 72
__construct(string $str)

Constructor.

Parameters

string $str the string

at line 92
bool offsetExists(int $offset)

Checks if the given offset exists.

Parameters

int $offset the offset to be checked

Return Value

bool

at line 104
string offsetGet(int $offset)

Gets the character at given offset.

Parameters

int $offset the offset to be returned

Return Value

string

at line 146
offsetSet(int $offset, string $value)

Sets the value of a character.

Parameters

int $offset the offset to be set
string $value the value to be set

Exceptions

Exception not implemented

at line 158
offsetUnset(int $offset)

Unsets an index.

Parameters

int $offset the value to be unset

Exceptions

Exception not implemented

at line 176
static int getCharLength(string $byte)

Gets the length of an UTF-8 character.

According to RFC 3629, a UTF-8 character can have at most 4 bytes. However, this implementation supports UTF-8 characters containing up to 6 bytes.

Parameters

string $byte the byte to be analyzed

Return Value

int

See also

at line 199
int length()

Returns the length in characters of the string.

Return Value

int

at line 209
string __toString()

Returns the contained string.

Return Value

string