pub struct Wtf8Buf { /* private fields */ }Expand description
A WTF-8 dynamically sized, growable string.
Implementations§
Source§impl Wtf8Buf
impl Wtf8Buf
Sourcepub fn with_capacity(capacity: usize) -> Wtf8Buf
pub fn with_capacity(capacity: usize) -> Wtf8Buf
Creates a new, empty WTF-8 string with pre-allocated capacity for capacity bytes.
Sourcepub fn from_string(string: String) -> Wtf8Buf
pub fn from_string(string: String) -> Wtf8Buf
Creates a WTF-8 string from a UTF-8 String.
This takes ownership of the String and does not copy.
Since WTF-8 is a superset of UTF-8, this always succeeds.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more bytes to be inserted
in the given Wtf8Buf.
The collection may reserve more space to avoid frequent reallocations.
§Panics
Panics if the new capacity overflows usize.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional more elements to
be inserted in the given Wtf8Buf. After calling reserve_exact,
capacity will be greater than or equal to self.len() + additional.
Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it
requests. Therefore, capacity can not be relied upon to be precisely
minimal. Prefer reserve if future insertions are expected.
§Panics
Panics if the new capacity overflows usize.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of bytes that this string buffer can hold without reallocating.
Sourcepub fn from_str(str: &str) -> Wtf8Buf
pub fn from_str(str: &str) -> Wtf8Buf
Creates a WTF-8 string from a UTF-8 &str slice.
This copies the content of the slice.
Since WTF-8 is a superset of UTF-8, this always succeeds.
Sourcepub fn from_utf16<I>(v: I) -> Wtf8Bufwhere
I: IntoIterator<Item = u16>,
pub fn from_utf16<I>(v: I) -> Wtf8Bufwhere
I: IntoIterator<Item = u16>,
Creates a WTF-8 string from a potentially ill-formed UTF-16 iterator of 16-bit code units.
This is lossless: calling .encode_utf16() on the resulting string
will always return the original code units.
Sourcepub fn as_mut_wtf8(&mut self) -> &mut Wtf8
pub fn as_mut_wtf8(&mut self) -> &mut Wtf8
Returns the slice of this object.
Sourcepub fn push_wtf8(&mut self, other: &Wtf8)
pub fn push_wtf8(&mut self, other: &Wtf8)
Append a string with WTF-8 encoding.
This replaces newly paired surrogates at the boundary with a supplementary code point, like concatenating ill-formed UTF-16 strings effectively would.
Sourcepub fn push(&mut self, code_point: CodePoint)
pub fn push(&mut self, code_point: CodePoint)
Append a code point at the end of the string.
This replaces newly paired surrogates at the boundary with a supplementary code point, like concatenating ill-formed UTF-16 strings effectively would.
Sourcepub fn truncate(&mut self, new_len: usize)
pub fn truncate(&mut self, new_len: usize)
Shortens a string to the specified length.
§Panics
Panics if new_len > current length,
or if new_len is not a code point boundary.
Sourcepub fn into_string(self) -> Result<String, IntoStringError>
pub fn into_string(self) -> Result<String, IntoStringError>
Consumes the WTF-8 string and tries to convert it to UTF-8.
This does not copy the data.
If the contents are not well-formed UTF-8 (that is, if the string contains surrogates), the original WTF-8 string is returned instead.
Sourcepub fn into_string_lossy(self) -> String
pub fn into_string_lossy(self) -> String
Consumes the WTF-8 string and converts it lossily to UTF-8.
This does not copy the data (but may overwrite parts of it in place).
Surrogates are replaced with "\u{FFFD}" (the replacement character “�”)
Methods from Deref<Target = Wtf8>§
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 CodePoint> for Wtf8Buf
impl<'a> Extend<&'a CodePoint> for Wtf8Buf
Source§fn extend<T: IntoIterator<Item = &'a CodePoint>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a CodePoint>>(&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> 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> Extend<&'a char> for Wtf8Buf
impl<'a> Extend<&'a char> for Wtf8Buf
Source§fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a char>>(&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> Extend<&'a str> for Wtf8Buf
impl<'a> Extend<&'a str> for Wtf8Buf
Source§fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a str>>(&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 Extend<CodePoint> for Wtf8Buf
Append code points from an iterator to the string.
impl Extend<CodePoint> for Wtf8Buf
Append code points from an iterator to the string.
This replaces surrogate code point pairs with supplementary code points, like concatenating ill-formed UTF-16 strings effectively would.
Source§fn extend<T: IntoIterator<Item = CodePoint>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = CodePoint>>(&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 Extend<char> for Wtf8Buf
impl Extend<char> for Wtf8Buf
Source§fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = char>>(&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 CodePoint> for Wtf8Buf
impl<'a> FromIterator<&'a CodePoint> for Wtf8Buf
Source§impl<'a> FromIterator<&'a Wtf8> for Wtf8Buf
impl<'a> FromIterator<&'a Wtf8> for Wtf8Buf
Source§impl<'a> FromIterator<&'a char> for Wtf8Buf
impl<'a> FromIterator<&'a char> for Wtf8Buf
Source§impl<'a> FromIterator<&'a str> for Wtf8Buf
impl<'a> FromIterator<&'a str> for Wtf8Buf
Source§impl FromIterator<CodePoint> for Wtf8Buf
Creates a new WTF-8 string from an iterator of code points.
impl FromIterator<CodePoint> for Wtf8Buf
Creates a new WTF-8 string from an iterator of code points.
This replaces surrogate code point pairs with supplementary code points, like concatenating ill-formed UTF-16 strings effectively would.