Class CharWidth


  • public final class CharWidth
    extends java.lang.Object
    Terminal display width of characters and code points: 0 for zero-width, 2 for East Asian wide characters and common emoji, 1 otherwise. Best-effort per code point; not grapheme-cluster aware.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int of​(char c)
      Returns the display width of a BMP character.
      static int of​(int cp)
      Returns the display width of a Unicode code point.
      static int width​(java.lang.CharSequence text)
      Returns the total display width of a sequence (sum of its code points' widths).
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • of

        public static int of​(char c)
        Returns the display width of a BMP character.
        Parameters:
        c - the character to measure
        Returns:
        the display width (0, 1, or 2)
      • width

        public static int width​(java.lang.CharSequence text)
        Returns the total display width of a sequence (sum of its code points' widths).
        Parameters:
        text - the sequence to measure
        Returns:
        the total display width
      • of

        public static int of​(int cp)
        Returns the display width of a Unicode code point.
        Parameters:
        cp - the code point to measure
        Returns:
        the display width (0, 1, or 2)