Skip to main content

calculate_truncate_chars_length

Calculates the remaining character length after accounting for a replacement truncation string by decrementing the initial length for each non-combining character in the replacement text.

def calculate_truncate_chars_length(
length: int,
replacement: string
) - > int

Calculates the remaining character budget for a string after accounting for the visual length of a truncation replacement string.

Parameters

NameTypeDescription
lengthintThe total allowed character length for the truncated output.
replacementstringThe string or placeholder text to be appended when truncation occurs.

Returns

TypeDescription
intThe number of characters remaining for the original content after subtracting the non-combining characters found in the replacement text.