Struct wtf8_rs::wtf8buf::Wtf8Buf [−][src]
pub struct Wtf8Buf { /* fields omitted */ }
Expand description
A WTF-8 dynamically sized, growable string.
Implementations
Creates a new, empty WTF-8 string with pre-allocated capacity for capacity
bytes.
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.
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
.
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
.
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.
Returns the number of bytes that this string buffer can hold without reallocating.
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.
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.
Returns the slice of this object.
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.
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.
Shortens a string to the specified length.
Panics
Panics if new_len
> current length,
or if new_len
is not a code point boundary.
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.
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>
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.
pub fn code_points(&self) -> CodePoints<'_>ⓘNotable traits for CodePoints<'_>impl Iterator for CodePoints<'_> type Item = CodePoint;
pub fn code_points(&self) -> CodePoints<'_>ⓘNotable traits for CodePoints<'_>impl Iterator for CodePoints<'_> type Item = CodePoint;
impl Iterator for CodePoints<'_> type Item = CodePoint;
Returns an iterator for the string’s code points.
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.
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.
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).
Returns a slice of the given string for the byte range.
Returns None
whenever index
would panic.
pub fn encode_utf16(&self) -> EncodeUtf16<'_>ⓘNotable traits for EncodeUtf16<'_>impl Iterator for EncodeUtf16<'_> type Item = u16;
pub fn encode_utf16(&self) -> EncodeUtf16<'_>ⓘNotable traits for EncodeUtf16<'_>impl Iterator for EncodeUtf16<'_> type Item = u16;
impl Iterator for EncodeUtf16<'_> type Item = u16;
Converts the WTF-8 string to potentially ill-formed UTF-16 and return an iterator of 16-bit code units.
Whether a given index is at a code point boundary.
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
.
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
.
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.
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
.
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
Mutably borrows from an owned value. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
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.
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
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.
type Err = Infallible
type Err = Infallible
The associated error which can be returned from parsing.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Wtf8Buf
impl UnwindSafe for Wtf8Buf
Blanket Implementations
Mutably borrows from an owned value. Read more