Drafter's own width tables, and the default Drafter.CharacterWidth.
Used when no other implementation is configured. Call Drafter.CharacterWidth
rather than this module directly, so a configured implementation is honoured.
Width comes from Unicode East Asian Width (UAX #11 W and F are two
columns), Emoji Presentation (UTS #51), and the general categories that occupy
no column at all — non-spacing combining marks, format characters, and C0/C1
controls.
Measurement is per grapheme cluster, not per codepoint. A cluster's width is
the width of its base character; trailing combining marks, skin-tone
modifiers, and regional-indicator continuations add nothing. Variation
selectors override the base: U+FE0F forces emoji presentation (two columns)
and U+FE0E forces text presentation (one column). A cluster joined by
U+200D (ZWJ) measures two columns.
No bidirectional reordering is performed: right-to-left text is measured correctly but emitted in logical order.
Examples
iex> Drafter.CharacterWidth.Default.string("ab漢")
4
iex> Drafter.CharacterWidth.Default.grapheme("")
0
iex> Drafter.CharacterWidth.Default.printable_ascii?("plain")
true
Summary
Functions
Display width in columns of a single codepoint.
Display width in columns of a single grapheme cluster.
Whether every byte is printable ASCII, over which display width equals byte size.
Display width in columns of a string.
Functions
@spec codepoint(non_neg_integer()) :: non_neg_integer()
Display width in columns of a single codepoint.
@spec grapheme(String.t()) :: non_neg_integer()
Display width in columns of a single grapheme cluster.
The cluster's base character determines the width; combining marks, skin-tone modifiers and regional-indicator continuations add nothing.
Whether every byte is printable ASCII, over which display width equals byte size.
@spec string(String.t()) :: non_neg_integer()
Display width in columns of a string.
Printable-ASCII input is measured by byte size; anything else per grapheme cluster.