SelectionUnitToUTF16

Forms, interaction, unicode

Description

Converts a count of selection units into the zero-based UTF-16 index of the matching boundary within the active edit value

With fsuUTF16CodeUnit the count is returned unchanged after clamping to the value length

With fsuUnicodeCodePoint or fsuGraphemeCluster the boundary table for that unit is built on demand and looked up, so the returned index never splits a surrogate pair or a grapheme cluster and an excessive count clamps to the final boundary

A count of zero or less always converts to index zero

Declaration

function SelectionUnitToUTF16(Index: Integer;
  IndexUnit: TPDFlibFormSelectionUnit): Integer;

Parameters

IndexNumber of complete selection units to skip from the start of the value, clamped to the last available boundary
IndexUnitSelection unit the count is expressed in

Return value

Returns the UTF-16 index of the requested boundary, the value length when the count exceeds the available boundaries, or zero for counts of zero or less

Example

// Unit 2 starts after the surrogate pair, at UTF-16 index 3
Session.SetEditValue('A' + WideChar($D83D) + WideChar($DE00) + 'B');
CaretUTF16 := Session.SelectionUnitToUTF16(2, fsuUnicodeCodePoint);
// CaretUTF16 = 3

See also

SelectionUTF16ToUnit, SetSelectionRange, GetVisualCaretOrder, TPDFlibFormSelectionUnit, TPDFlibFormSession