Expand description
Width.
Find the “display width” of a byte string.
Like anything having to do with width vs length, this should be considered
at best an approximation. For ASCII, every byte that is not a control
character or part of an ANSI formatting sequence is counted as having a
length of 1. For Unicode, the unicode_width
crate is used
to determine width.
While not 100% perfect, results should be closer than simply trusting the raw byte length.
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 width_unicode
method and finish counting there.
Note: line breaks are ignored; the cummulative width of all lines is returned. If you’re trying to calculate line widths, split the slice first and pass each chunk separately.
This requires the fitted
crate feature.
Safety.
The byte sequence must be valid UTF-8 or undefined things will happen.