WcWidth { public static int width(int ucs) { if (ucs == 0) return 0; if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) return -1; if (bisearch(ucs, COMBINING.length - 1)) return 0; return 1 + ((ucs >= 0x1100 && (ucs <= 0x115f || ucs == 0x2329 || ucs == 0x232a || (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || (ucs >= 0xac00 && ucs <= 0xd7a3) || (ucs >= 0xf900 && ucs <= 0xfaff) || (ucs >= 0xfe10 && ucs <= 0xfe19) || (ucs >= 0xfe30 && ucs <= 0xfe6f) || (ucs >= 0xff00 && ucs <= 0xff60) || (ucs >= 0xffe0 && ucs <= 0xffe6) || (ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd))) ? 1 : 0); }  static int width(int ucs);  }
@Test public void testWidth() { assertEquals(1, WcWidth.width('s')); assertEquals(1, WcWidth.width('h')); assertEquals(0, WcWidth.width('\0')); assertEquals(-1, WcWidth.width('\n')); assertEquals(-1, WcWidth.width('\r')); assertEquals(-1, WcWidth.width('\t')); assertEquals(-1, WcWidth.width('\u001B')); }