Trame

utf8: portable SIMD UTF-8 validation

trame:utf8 validates UTF-8 byte slices sixteen bytes at a time using portable #simd[16]u8 and base:intrinsics only (no std: imports). Algorithm: John Keiser and Daniel Lemire, "Validating UTF-8 In Less Than One Instruction Per Byte" (2021). Design: src/md/infrastructure/utf8.md.

Formula
#import "trame:utf8"

if !utf8.valid(bytes) { return }
if !utf8.valid_string(text, reject_controls = true) { return }
ProcedureResult
valid(bytes, reject_controls := false) -> booltrue when bytes is well-formed UTF-8 (RFC 3629); with reject_controls = true, also refuses U+0000..U+001F, U+007F, and U+0080..U+009F (C2 80..9F) in the same SIMD pass
valid_string(s, reject_controls := false) -> boolvalid on a string
valid_scalar(bytes, reject_controls := false) -> boolscalar RFC 3629 reference oracle

Edit this page on GitHub