pub struct Wtf8 { /* private fields */ }Expand description
A WTF-8 slice.
Implementations§
Source§impl Wtf8
impl Wtf8
Sourcepub fn new<T: ?Sized + AsRef<Wtf8>>(x: &T) -> &Self
pub fn new<T: ?Sized + AsRef<Wtf8>>(x: &T) -> &Self
Coerces into a Wtf8. This accepts an &str argument.
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 code_points(&self) -> CodePoints<'_> ⓘ
pub fn code_points(&self) -> CodePoints<'_> ⓘ
Returns an iterator for the string’s code points.
Sourcepub fn to_str(&self) -> Result<&str, ToStrError>
pub fn to_str(&self) -> Result<&str, ToStrError>
Tries to convert the string to UTF-8 and return a &str slice.
Returns Err(_) if the string contains surrogates.
This does not copy the data.
Sourcepub fn chunks(&self) -> Chunks<'_> ⓘ
pub fn chunks(&self) -> Chunks<'_> ⓘ
Converts this string into a iterator of Wtf8Chunk.
The resulting iterator will intercalate Utf8 chunks
with one or more UnpairedSurrogate and
all contained codepoints can be recovered from it.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Lossily converts the string to UTF-8.
Returns a 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 get<I: Wtf8Index>(&self, i: I) -> Option<&Self>
pub fn get<I: Wtf8Index>(&self, i: I) -> Option<&Self>
Returns a slice of the given string for the byte range.
Returns None whenever index would panic.
Sourcepub fn encode_utf16(&self) -> EncodeUtf16<'_> ⓘ
pub fn encode_utf16(&self) -> EncodeUtf16<'_> ⓘ
Converts the WTF-8 string to potentially ill-formed UTF-16 and return an iterator of 16-bit code units.
Sourcepub unsafe fn get_unchecked<I: Wtf8Index>(&self, i: I) -> &Self
pub unsafe fn get_unchecked<I: Wtf8Index>(&self, i: I) -> &Self
Sourcepub fn is_code_point_boundary(&self, index: usize) -> bool
pub fn is_code_point_boundary(&self, index: usize) -> bool
Whether a given index is at a code point boundary.
Sourcepub fn make_ascii_lowercase(&mut self)
pub fn make_ascii_lowercase(&mut self)
Converts this slice to its ASCII lower case equivalent in-place.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
To return a new lowercased value without modifying the existing one, use
to_ascii_lowercase.
Sourcepub fn make_ascii_uppercase(&mut self)
pub fn make_ascii_uppercase(&mut self)
Converts this slice to its ASCII upper case equivalent in-place.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To return a new uppercased value without modifying the existing one, use
to_ascii_uppercase.
Sourcepub fn to_ascii_lowercase(&self) -> Wtf8Buf
pub fn to_ascii_lowercase(&self) -> Wtf8Buf
Returns a Wtf8Buf containing a copy of this slice where each byte
is mapped to its ASCII lower case equivalent.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
Sourcepub fn to_ascii_uppercase(&self) -> Wtf8Buf
pub fn to_ascii_uppercase(&self) -> Wtf8Buf
Returns a Wtf8Buf containing a copy of this slice where each byte
is mapped to its ASCII upper case equivalent.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To uppercase the value in-place, use make_ascii_uppercase.
Sourcepub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
Checks that two slices are an ASCII case-insensitive match.
Same as to_ascii_lowercase(a) == to_ascii_lowercase(b),
but without allocating and copying temporaries.
Trait Implementations§
Source§impl BorrowMut<Wtf8> for Wtf8Buf
impl BorrowMut<Wtf8> for Wtf8Buf
Source§fn borrow_mut(&mut self) -> &mut Wtf8
fn borrow_mut(&mut self) -> &mut Wtf8
Source§impl<'a> Extend<&'a Wtf8> for Wtf8Buf
impl<'a> Extend<&'a Wtf8> for Wtf8Buf
Source§fn extend<T: IntoIterator<Item = &'a Wtf8>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a Wtf8>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<'a> FromIterator<&'a Wtf8> for Wtf8Buf
impl<'a> FromIterator<&'a Wtf8> for Wtf8Buf
Source§impl<T: Wtf8Index> Index<T> for Wtf8
Returns a slice of the given string for the byte range.
impl<T: Wtf8Index> Index<T> for Wtf8
Returns a slice of the given string for the byte range.
§Panics
Panics when the boundaries of the range do not point to code point boundaries, or point beyond the end of the string.