pub struct Wtf8 { /* private fields */ }
Expand description
A borrowed slice of well-formed WTF-8 data.
Similar to &str
, but can additionally contain surrogate code points
if they’re not in a surrogate pair.
Implementations§
source§impl Wtf8
impl Wtf8
sourcepub fn from_str(value: &str) -> &Wtf8
pub fn from_str(value: &str) -> &Wtf8
Creates a WTF-8 slice from a UTF-8 &str
slice.
Since WTF-8 is a superset of UTF-8, this always succeeds.
sourcepub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
pub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
Creates a WTF-8 slice from a WTF-8 byte slice.
Since the byte slice is not checked for valid WTF-8, this functions is marked unsafe.
pub fn is_empty(&self) -> bool
sourcepub fn ascii_byte_at(&self, position: usize) -> u8
pub fn ascii_byte_at(&self, position: usize) -> u8
Returns the code point at position
if it is in the ASCII range,
or `b’\xFF’ otherwise.
Panics
Panics if position
is beyond the end of the string.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Tries to convert the string to UTF-8 and return a &str
slice.
Returns None
if the string contains surrogates.
This does not copy the data.
sourcepub fn encode_wide(&self) -> EncodeWide<'_>
pub fn encode_wide(&self) -> EncodeWide<'_>
Converts 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.
source§impl Wtf8
impl Wtf8
pub fn make_ascii_uppercase(&mut self)
Trait Implementations§
source§impl Debug for Wtf8
impl Debug for Wtf8
Format the slice with double quotes,
and surrogates as \u
followed by four hexadecimal digits.
Example: "a\u{D800}"
for a slice with code points [U+0061, U+D800]
source§impl Hay for Wtf8
impl Hay for Wtf8
source§fn start_index(&self) -> usize
fn start_index(&self) -> usize
source§unsafe fn slice_unchecked(&self, range: Range<usize>) -> &Self
unsafe fn slice_unchecked(&self, range: Range<usize>) -> &Self
self
. Read moresource§impl Index<Range<usize>> for Wtf8
impl Index<Range<usize>> for Wtf8
Return a slice of the given string for the byte range [begin
..end
).
Panics
Panics when begin
and end
do not point to code point boundaries,
or point beyond the end of the string.
source§impl Index<RangeFrom<usize>> for Wtf8
impl Index<RangeFrom<usize>> for Wtf8
Return a slice of the given string from byte begin
to its end.
Panics
Panics when begin
is not at a code point boundary,
or is beyond the end of the string.
source§impl Index<RangeTo<usize>> for Wtf8
impl Index<RangeTo<usize>> for Wtf8
Return a slice of the given string from its beginning to byte end
.
Panics
Panics when end
is not at a code point boundary,
or is beyond the end of the string.