SyntaxText

Represent a string.

SyntaxText.swift:47

This declaration is gated by at least one @_spi attribute.

struct SyntaxText

This type does not own the string data. The data reside in some other buffer whose lifetime extends past that of the SyntaxText.

SyntaxText is a Collection of UInt8 which is expected to be a UTF8 encoded byte sequence. However, since that is essentially just a span of a memory buffer, it may contain ill-formed UTF8 sequences. And their comparison (e.g.==, hasPrefix()) are purely based on the byte sequences, without any Unicode normalization or anything.

Since it’s just a byte sequence, SyntaxText can represent the exact source buffer regardless of whether it is a valid UTF8. When creating Swift.String, ill-formed UTF8 sequences are replaced with the Unicode replacement character (\u{FFFD}).