Byte-bounded UTF-8 helpers shared by diagnostics and public metadata.
truncate/2 leaves values within the byte limit unchanged. When truncation
is required, it backs up to a valid UTF-8 boundary and copies the result so
retaining a short diagnostic cannot retain its complete source binary.
This is a truncation helper, not a validator: an invalid binary already within the limit is returned unchanged.
Summary
Functions
Returns the longest valid UTF-8 prefix within max_bytes.
Functions
@spec truncate(binary(), non_neg_integer()) :: binary()
@spec truncate_valid(binary(), non_neg_integer()) :: binary()
Returns the longest valid UTF-8 prefix within max_bytes.
Unlike truncate/2, this also sanitizes an invalid value that is already
within the byte limit. A changed result is copied out of its parent binary.