pub struct Wtf8Atom { /* private fields */ }
Expand description
A WTF-8 encoded atom. This is like Atom, but can contain unpaired surrogates.
Implementations§
Methods from Deref<Target = Wtf8>§
Sourcepub fn slice(&self, begin: usize, end: usize) -> &Wtf8
pub fn slice(&self, begin: usize, end: usize) -> &Wtf8
Return a slice of the given string for the byte range [begin
..end
).
§Failure
Fails when begin
and end
do not point to code point boundaries,
or point beyond the end of the string.
Sourcepub fn slice_from(&self, begin: usize) -> &Wtf8
pub fn slice_from(&self, begin: usize) -> &Wtf8
Return a slice of the given string from byte begin
to its end.
§Failure
Fails when begin
is not at a code point boundary,
or is beyond the end of the string.
Sourcepub fn slice_to(&self, end: usize) -> &Wtf8
pub fn slice_to(&self, end: usize) -> &Wtf8
Return a slice of the given string from its beginning to byte end
.
§Failure
Fails when end
is not at a code point boundary,
or is beyond the end of the string.
Sourcepub fn ascii_byte_at(&self, position: usize) -> u8
pub fn ascii_byte_at(&self, position: usize) -> u8
Return the code point at position
if it is in the ASCII range,
or `b’\xFF’ otherwise.
§Failure
Fails if position
is beyond the end of the string.
Sourcepub fn code_points(&self) -> Wtf8CodePoints<'_> ⓘ
pub fn code_points(&self) -> Wtf8CodePoints<'_> ⓘ
Return an iterator for the string’s code points.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Try to convert the string to UTF-8 and return a &str
slice.
Return None
if the string contains surrogates.
This does not copy the data.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Lossily convert the string to UTF-8.
Return an UTF-8 &str
slice if the contents are well-formed in UTF-8.
Surrogates are replaced with "\u{FFFD}"
(the replacement character
“�”).
This only copies the data if necessary (if it contains any surrogate).
Sourcepub fn to_ill_formed_utf16(&self) -> IllFormedUtf16CodeUnits<'_> ⓘ
pub fn to_ill_formed_utf16(&self) -> IllFormedUtf16CodeUnits<'_> ⓘ
Convert the WTF-8 string to potentially ill-formed UTF-16 and return an iterator of 16-bit code units.
This is lossless:
calling Wtf8Buf::from_ill_formed_utf16
on the resulting code units
would always return the original WTF-8 string.
Trait Implementations§
impl Eq for Wtf8Atom
impl Send for Wtf8Atom
Immutable, so it’s safe to be shared between threads
impl Sync for Wtf8Atom
Immutable, so it’s safe to be shared between threads