struct CharacterOne extended grapheme cluster, represented as a borrowed UTF-8 byte range.
The range is produced by UAX #29 boundary iteration and may contain several Unicode scalars. Classification uses the first scalar, while equality is exact byte equality and does not normalize canonically equivalent text.
Properties
let storage: ByteStorage
The backing storage.
let start: Int
The inclusive starting byte offset in the source.
let byte_count: Int
The number of bytes in the encoded representation.
Methods
func utf8_count() -> Int
Returns this grapheme cluster's encoded byte length, not its scalar count.
View Source
pub func utf8_count() -> Int {
self.byte_count
}func as_substring() -> Substring
Borrows the cluster's exact UTF-8 range without copying.
View Source
pub func as_substring() -> Substring {
Substring(storage: self.storage, start: self.start, byte_count: self.byte_count)
}func to_string() -> String
Copies the cluster's UTF-8 bytes into a new owned string.
View Source
pub func to_string() -> String {
self.as_substring().to_string()
}func first_scalar() -> Int
Classification uses the cluster's first Unicode scalar. This keeps combining marks attached for iteration while classifying 1 plus a combining mark as numeric.
View Source
pub func first_scalar() -> Int {
_packed_scalar(
packed: _utf8_decode(
storage: self.storage,
offset: self.start,
end: self.start + self.byte_count
)
)
}func is_whitespace() -> Bool
Tests the first scalar against Unicode's White_Space property.
View Source
pub func is_whitespace() -> Bool {
scalar_is_whitespace(scalar: self.first_scalar())
}func is_alphabetic() -> Bool
Tests the first scalar against Unicode's Alphabetic property.
View Source
pub func is_alphabetic() -> Bool {
scalar_is_alphabetic(scalar: self.first_scalar())
}func is_numeric() -> Bool
Returns true for Unicode decimal, digit, or numeric-number scalars.
View Source
pub func is_numeric() -> Bool {
scalar_is_numeric(scalar: self.first_scalar())
}func is_alphanumeric() -> Bool
Returns true when the first scalar is Unicode alphabetic or numeric.
View Source
pub func is_alphanumeric() -> Bool {
scalar_is_alphanumeric(scalar: self.first_scalar())
}func is_ascii_digit() -> Bool
Returns true when the first scalar is in 0...9.
View Source
pub func is_ascii_digit() -> Bool {
scalar_is_ascii_digit(scalar: self.first_scalar())
}func is_ascii_hexdigit() -> Bool
Returns true for the ASCII hexadecimal digits 0...9, a...f, or A...F.
View Source
pub func is_ascii_hexdigit() -> Bool {
scalar_is_ascii_hexdigit(scalar: self.first_scalar())
}func is_ascii() -> Bool
Returns true only for a one-byte ASCII grapheme cluster.
View Source
pub func is_ascii() -> Bool {
self.byte_count == 1 && self.first_scalar() < 128
}func is_ascii_alphabetic() -> Bool
Returns true when the first scalar is an ASCII letter.
View Source
pub func is_ascii_alphabetic() -> Bool {
let scalar = self.first_scalar()
(64 < scalar && scalar < 91) || (96 < scalar && scalar < 123)
}func is_ascii_alphanumeric() -> Bool
Returns true when the first scalar is an ASCII letter or decimal digit.
View Source
pub func is_ascii_alphanumeric() -> Bool {
self.is_ascii_alphabetic() || self.is_ascii_digit()
}func is_ascii_whitespace() -> Bool
Recognizes ASCII space and the tab, newline, vertical-tab, form-feed, and return controls.
View Source
pub func is_ascii_whitespace() -> Bool {
let scalar = self.first_scalar()
scalar == 9 || scalar == 10 || scalar == 11 || scalar == 12 || scalar == 13 || scalar == 32
}func is_lowercase() -> Bool
Tests the first scalar against Unicode's Lowercase property.
View Source
pub func is_lowercase() -> Bool {
scalar_is_lowercase(scalar: self.first_scalar())
}func is_uppercase() -> Bool
Tests the first scalar against Unicode's Uppercase property.
View Source
pub func is_uppercase() -> Bool {
scalar_is_uppercase(scalar: self.first_scalar())
}func is_titlecase() -> Bool
Returns true when the first scalar has Unicode general category Lt.
View Source
pub func is_titlecase() -> Bool {
scalar_is_titlecase(scalar: self.first_scalar())
}func is_decimal() -> Bool
Returns true when the first scalar has Unicode general category Nd.
View Source
pub func is_decimal() -> Bool {
scalar_is_decimal(scalar: self.first_scalar())
}func is_digit() -> Bool
Returns true for Unicode decimal digits and compatibility digit characters.
View Source
pub func is_digit() -> Bool {
scalar_is_digit(scalar: self.first_scalar())
}func is_punctuation() -> Bool
Returns true when the first scalar is in a Unicode punctuation category.
View Source
pub func is_punctuation() -> Bool {
scalar_is_punctuation(scalar: self.first_scalar())
}func is_symbol() -> Bool
Returns true when the first scalar is in a Unicode symbol category.
View Source
pub func is_symbol() -> Bool {
scalar_is_symbol(scalar: self.first_scalar())
}func is_control() -> Bool
Returns true when the first scalar has Unicode general category Cc.
View Source
pub func is_control() -> Bool {
scalar_is_control(scalar: self.first_scalar())
}func is_printable() -> Bool
Excludes Unicode control, format, surrogate, private-use, and unassigned scalars.
View Source
pub func is_printable() -> Bool {
scalar_is_printable(scalar: self.first_scalar())
}func is_identifier_start() -> Bool
Recognizes Talk identifier starts: an ASCII letter or underscore.
View Source
pub func is_identifier_start() -> Bool {
let scalar = self.first_scalar()
self.is_ascii_alphabetic() || scalar == 95
}func is_identifier_continue() -> Bool
Recognizes Talk identifier continuations: a valid start or an alphanumeric scalar.
View Source
pub func is_identifier_continue() -> Bool {
self.is_identifier_start() || self.is_alphanumeric()
}func scalar_count() -> Int
Returns the number of Unicode scalar values.
View Source
pub func scalar_count() -> Int {
let count = 0
for _ in self.scalars() {
count = count + 1
}
count
}func is_single_scalar() -> Bool
Returns whether this grapheme cluster contains exactly one Unicode scalar.
View Source
pub func is_single_scalar() -> Bool {
self.scalar_count() == 1
}func scalars() -> ScalarIterator
Returns a view that iterates over Unicode scalar values.
View Source
pub func scalars() -> ScalarIterator {
ScalarIterator(
storage: self.storage,
offset: self.start,
end: self.start + self.byte_count
)
}