ClampTextLength

Forms, interaction, unicode

Description

Internal helper of TPDFlibFormSession that truncates a value to at most a requested number of UTF-16 code units

Values already within the limit pass through unchanged and a non-positive limit yields an empty string

The cut lands on the last extended grapheme boundary at or before the limit, so surrogate pairs, combining sequences and joined emoji are never divided

The helper enforces the text field /MaxLen limit while setting the edit value, replacing a selection and committing a value

Declaration

function ClampTextLength(const Value: WideString;
  MaxLength: Integer): WideString;

Parameters

ValueText to truncate
MaxLengthMaximum number of UTF-16 code units to retain

Return value

Returns the unchanged value when it fits, otherwise the longest grapheme-aligned prefix within the limit

See also

ApplySelectionEdit, CommitEdit, EnsureSelectionBoundaries, TPDFlibFormSelectionUnit, TPDFlibFormSession