Struct xi_unicode::LineBreakLeafIter

source ·
pub struct LineBreakLeafIter {
    pub(crate) ix: usize,
    pub(crate) state: u8,
}
Expand description

A struct useful for computing line breaks in a rope or other non-contiguous string representation. This is a trickier problem than iterating in a string for a few reasons, the trickiest of which is that in the general case, line breaks require an indeterminate amount of look-behind.

This is something of an “expert-level” interface, and should only be used if the caller is prepared to respect all the invariants. Otherwise, you might get inconsistent breaks depending on start position and leaf boundaries.

Fields§

§ix: usize§state: u8

Implementations§

source§

impl LineBreakLeafIter

source

pub fn new(s: &str, ix: usize) -> LineBreakLeafIter

Create a new line break iterator suitable for leaves in a rope. Precondition: ix is at a code point boundary within s.

source

pub fn next(&mut self, s: &str) -> (usize, bool)

Return break pos and whether it’s a hard break. Note: hard break indication may go away, this may not be useful in actual application. If end of leaf is found, return leaf’s len. This does not indicate a break, as that requires at least one more codepoint of context. If it is a break, then subsequent next call will return an offset of 0. EOT is always a break, so in the EOT case it’s up to the caller to figure that out.

For consistent results, always supply same s until end of leaf is reached (and initially this should be the same as in the new call).

Trait Implementations§

source§

impl Clone for LineBreakLeafIter

source§

fn clone(&self) -> LineBreakLeafIter

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for LineBreakLeafIter

source§

fn default() -> LineBreakLeafIter

Returns the “default value” for a type. Read more
source§

impl Copy for LineBreakLeafIter

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.