Function

GLibutf8_offset_to_pointer

Declaration

gchar*
g_utf8_offset_to_pointer (
  const gchar* str,
  glong offset
)

Description

Converts from an integer character offset to a pointer to a position within the string.

Since 2.10, this function allows to pass a negative offset to step backwards. It is usually worth stepping backwards from the end instead of forwards if offset is in the last fourth of the string, since moving forward is about 3 times faster than moving backward.

Note that this function doesn’t abort when reaching the end of str. Therefore you should be sure that offset is within string boundaries before calling that function. Call g_utf8_strlen() when unsure. This limitation exists as this function is called frequently during text rendering and therefore has to be as fast as possible.

Parameters

str

Type: const gchar*

A UTF-8 encoded string.

The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.
offset

Type: glong

A character offset within str.

Return value

Type: gchar*

The resulting pointer.

The data is owned by the called function.
The value is a NUL terminated UTF-8 string.