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 new<S: AsRef<Wtf8> + ?Sized>(value: &S) -> &Wtf8
pub fn new<S: AsRef<Wtf8> + ?Sized>(value: &S) -> &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 const unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
pub const unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
Sourcepub fn from_bytes(b: &[u8]) -> Option<&Self>
pub fn from_bytes(b: &[u8]) -> Option<&Self>
Create a WTF-8 slice from a WTF-8 byte slice.
pub const fn is_empty(&self) -> bool
Sourcepub const fn ascii_byte_at(&self, position: usize) -> u8
pub const 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) -> Wtf8CodePoints<'_> ⓘ
pub fn code_points(&self) -> Wtf8CodePoints<'_> ⓘ
Returns an iterator for the string’s code points.
Sourcepub fn code_point_indices(&self) -> Wtf8CodePointIndices<'_> ⓘ
pub fn code_point_indices(&self) -> Wtf8CodePointIndices<'_> ⓘ
Returns an iterator for the string’s code points and their indices.
Sourcepub const fn as_str(&self) -> Result<&str, Utf8Error>
pub const fn as_str(&self) -> Result<&str, Utf8Error>
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 to_wtf8_buf(&self) -> Wtf8Buf
pub fn to_wtf8_buf(&self) -> Wtf8Buf
Creates an owned Wtf8Buf from a borrowed Wtf8.
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 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.
pub const fn chunks(&self) -> Wtf8Chunks<'_> ⓘ
pub fn map_utf8<'a, I>( &'a self, f: impl Fn(&'a str) -> I, ) -> impl Iterator<Item = CodePoint>
pub fn is_code_point_boundary(&self, index: usize) -> bool
pub fn make_ascii_lowercase(&mut self)
pub fn make_ascii_uppercase(&mut self)
pub fn to_ascii_lowercase(&self) -> Wtf8Buf
pub fn to_ascii_uppercase(&self) -> Wtf8Buf
pub fn to_lowercase(&self) -> Wtf8Buf
pub fn to_uppercase(&self) -> Wtf8Buf
pub const fn is_ascii(&self) -> bool
pub fn is_utf8(&self) -> bool
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
pub fn split(&self, pat: &Wtf8) -> impl Iterator<Item = &Self>
pub fn splitn(&self, n: usize, pat: &Wtf8) -> impl Iterator<Item = &Self>
pub fn rsplit(&self, pat: &Wtf8) -> impl Iterator<Item = &Self>
pub fn rsplitn(&self, n: usize, pat: &Wtf8) -> impl Iterator<Item = &Self>
pub fn trim(&self) -> &Self
pub fn trim_start(&self) -> &Self
pub fn trim_end(&self) -> &Self
pub fn trim_start_matches(&self, f: impl Fn(CodePoint) -> bool) -> &Self
pub fn trim_end_matches(&self, f: impl Fn(CodePoint) -> bool) -> &Self
pub fn trim_matches(&self, f: impl Fn(CodePoint) -> bool) -> &Self
pub fn find(&self, pat: &Wtf8) -> Option<usize>
pub fn rfind(&self, pat: &Wtf8) -> Option<usize>
pub fn find_iter(&self, pat: &Wtf8) -> impl Iterator<Item = usize>
pub fn rfind_iter(&self, pat: &Wtf8) -> impl Iterator<Item = usize>
pub fn contains(&self, pat: &Wtf8) -> bool
pub fn contains_code_point(&self, pat: CodePoint) -> bool
pub fn get(&self, range: impl RangeBounds<usize>) -> Option<&Self>
pub fn ends_with(&self, w: impl AsRef<Wtf8>) -> bool
pub fn starts_with(&self, w: impl AsRef<Wtf8>) -> bool
pub fn strip_prefix(&self, w: impl AsRef<Wtf8>) -> Option<&Self>
pub fn strip_suffix(&self, w: impl AsRef<Wtf8>) -> Option<&Self>
pub fn replace(&self, from: &Wtf8, to: &Wtf8) -> Wtf8Buf
pub fn replacen(&self, from: &Wtf8, to: &Wtf8, n: usize) -> Wtf8Buf
Trait Implementations§
Source§impl Debug for Wtf8
Formats the string in double quotes, with characters escaped according to
char::escape_debug and unpaired surrogates represented as \u{xxxx},
where each x is a hexadecimal digit.
impl Debug for Wtf8
Formats the string in double quotes, with characters escaped according to
char::escape_debug and unpaired surrogates represented as \u{xxxx},
where each x is a hexadecimal digit.
Source§impl Display for Wtf8
Formats the string with unpaired surrogates substituted with the replacement
character, U+FFFD.
impl Display for Wtf8
Formats the string with unpaired surrogates substituted with the replacement character, U+FFFD.
Source§impl Index<Range<usize>> for Wtf8
Returns a slice of the given string for the byte range [begin..end).
impl Index<Range<usize>> for Wtf8
Returns 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
Returns a slice of the given string from byte begin to its end.
impl Index<RangeFrom<usize>> for Wtf8
Returns 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
Returns a slice of the given string from its beginning to byte end.
impl Index<RangeTo<usize>> for Wtf8
Returns 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.