pub struct Wtf8Index { /* private fields */ }Expand description
A code-point-index to byte-offset table for one WTF-8 buffer.
Implementations§
Source§impl Wtf8Index
impl Wtf8Index
Sourcepub fn new(data: &Wtf8, char_len: usize) -> Self
pub fn new(data: &Wtf8, char_len: usize) -> Self
Builds the table for data, whose code point count is char_len.
O(data.len()), and touches every byte, so it pays for itself only when
the caller goes on to index the buffer more than a couple of times.
Sourcepub fn byte_offset(&self, data: &Wtf8, index: usize) -> usize
pub fn byte_offset(&self, data: &Wtf8, index: usize) -> usize
The byte offset of data’s index-th code point.
data must be the buffer the table was built for, and index must be
below its code point count.
Sourcepub fn char_index_at_byte(
&self,
data: &Wtf8,
bytepos: usize,
char_len: usize,
) -> usize
pub fn char_index_at_byte( &self, data: &Wtf8, bytepos: usize, char_len: usize, ) -> usize
The index of the code point starting at byte offset bytepos, the
inverse of Self::byte_offset.
data must be the buffer the table was built for, char_len its code
point count, and bytepos a code point boundary at or before its end.
Logarithmic rather than constant: the table is keyed by code point
index, so going the other way is a search through it. The bracketing
below is what keeps that search short – a code point occupies one to
four bytes, which pins the answer to a narrow band around bytepos
before the first comparison.
Auto Trait Implementations§
impl Freeze for Wtf8Index
impl RefUnwindSafe for Wtf8Index
impl Send for Wtf8Index
impl Sync for Wtf8Index
impl Unpin for Wtf8Index
impl UnsafeUnpin for Wtf8Index
impl UnwindSafe for Wtf8Index
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more