pub fn length_width(bytes: &[u8], stop: usize) -> usize
Expand description

Length Width.

Return the maximum byte length for the slice that fits a given display width, such that slice[0..len] will be a valid substring likely to fit. This method is Unicode-safe, but Unicode character widths are at best aproximations, so actual results may vary plus or minus a few spaces.

If no fit is possible, zero is returned.

See the documentation for width for more information.

For performance reasons, this method will assume the byte sequence is ASCII unless/until it finds a non-ASCII code, at which point it will shift to the heavier length_width_unicode method and finish counting there.

This requires the fitted crate feature.

Safety.

The byte sequence must be valid UTF-8 or undefined things will happen.