Class WcWidth

java.lang.Object
org.aesh.terminal.utils.WcWidth

public final class WcWidth extends Object
Utility class for determining the display width of Unicode characters. Based on the wcwidth implementation by Markus Kuhn.
  • Method Details

    • width

      public static int width(int ucs)
      Determine the column width of an ISO 10646 character.

      The following rules apply:

      • The null character (U+0000) has a column width of 0.
      • Other C0/C1 control characters and DEL will lead to a return value of -1.
      • Non-spacing and enclosing combining characters have a column width of 0.
      • SOFT HYPHEN (U+00AD) has a column width of 1.
      • Other format characters and ZERO WIDTH SPACE (U+200B) have a column width of 0.
      • Hangul Jamo medial vowels and final consonants (U+1160-U+11FF) have a column width of 0.
      • East Asian Wide (W) or Full-width (F) characters have a column width of 2.
      • All remaining characters have a column width of 1.

      This implementation assumes that wchar_t characters are encoded in ISO 10646.

      Parameters:
      ucs - the Unicode code point
      Returns:
      the column width (0, 1, or 2), or -1 for control characters