@Test public void testWidth() { String s = "こんにちは世界€ Hello world"; assertThat(counter.width(s), is(16 + 12)); }
@Override public int width(String text) { int len = text.length(); CpRange key = new CpRange(); int cnt = 0; int cp; for (int i = 0; i < len; i += Character.charCount(cp)) { cp = text.codePointAt(i); key.first = cp; key.last = cp + 1; if (Arrays.binarySearch(ranges_, key, cpRangeCmp_) >= 0) { cnt += 2; } else { ++cnt; } } return cnt; }
CJKTextWidthCounter implements TextWidthCounter { @Override public int width(String text) { int len = text.length(); CpRange key = new CpRange(); int cnt = 0; int cp; for (int i = 0; i < len; i += Character.charCount(cp)) { cp = text.codePointAt(i); key.first = cp; key.last = cp + 1; if (Arrays.binarySearch(ranges_, key, cpRangeCmp_) >= 0) { cnt += 2; } else { ++cnt; } } return cnt; } }
CJKTextWidthCounter implements TextWidthCounter { @Override public int width(String text) { int len = text.length(); CpRange key = new CpRange(); int cnt = 0; int cp; for (int i = 0; i < len; i += Character.charCount(cp)) { cp = text.codePointAt(i); key.first = cp; key.last = cp + 1; if (Arrays.binarySearch(ranges_, key, cpRangeCmp_) >= 0) { cnt += 2; } else { ++cnt; } } return cnt; }  }
CJKTextWidthCounter implements TextWidthCounter { @Override public int width(String text) { int len = text.length(); CpRange key = new CpRange(); int cnt = 0; int cp; for (int i = 0; i < len; i += Character.charCount(cp)) { cp = text.codePointAt(i); key.first = cp; key.last = cp + 1; if (Arrays.binarySearch(ranges_, key, cpRangeCmp_) >= 0) { cnt += 2; } else { ++cnt; } } return cnt; }  @Override int width(String text); }
CJKTextWidthCounter implements TextWidthCounter { @Override public int width(String text) { int len = text.length(); CpRange key = new CpRange(); int cnt = 0; int cp; for (int i = 0; i < len; i += Character.charCount(cp)) { cp = text.codePointAt(i); key.first = cp; key.last = cp + 1; if (Arrays.binarySearch(ranges_, key, cpRangeCmp_) >= 0) { cnt += 2; } else { ++cnt; } } return cnt; }  @Override int width(String text);  }