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
impl LineBreakLeafIter
sourcepub fn new(s: &str, ix: usize) -> LineBreakLeafIter
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.
sourcepub fn next(&mut self, s: &str) -> (usize, bool)
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
impl Clone for LineBreakLeafIter
source§fn clone(&self) -> LineBreakLeafIter
fn clone(&self) -> LineBreakLeafIter
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more