Function cursive::utils::prefix_length [] [src]

pub fn prefix_length<'a, I>(iter: I, width: usize, delimiter: &str) -> usize where I: Iterator<Item=&'a str>

Computes the length of a prefix that fits in the given width.

Takes non-breakable elements from iter, while keeping the string width under width (and adding the length of delimiter between each element).

Given total_text = iter.collect().join(delimiter), the result is the length of the longest prefix of width or less cells, without breaking inside an element.

Example:

extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;

let my_text = "blah...";
// This returns the number of bytes for a prefix of `my_text` that
// fits within 5 cells.
prefix_length(my_text.graphemes(true), 5, "");