PtcRunner.Utf8 (PtcRunner v0.14.0)

Copy Markdown View Source

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

truncate(value, max_bytes)

@spec truncate(binary(), non_neg_integer()) :: binary()

truncate_valid(value, max_bytes)

@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.