2 *******************************************************************************
\r
3 * Copyright (C) 1996-2004, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.test.util;
\r
9 import com.ibm.icu.impl.Utility;
\r
10 import com.ibm.icu.text.UTF16;
\r
12 public abstract class UnicodeLabel {
\r
14 public abstract String getValue(int codepoint, boolean isShort);
\r
16 public String getValue(String s, String separator, boolean withCodePoint) {
\r
17 if (s.length() == 1) { // optimize simple case
\r
18 return getValue(s.charAt(0), withCodePoint);
\r
20 StringBuffer sb = new StringBuffer();
\r
22 for (int i = 0; i < s.length(); i+=UTF16.getCharCount(cp)) {
\r
23 cp = UTF16.charAt(s,i);
\r
24 if (i != 0) sb.append(separator);
\r
25 sb.append(getValue(cp, withCodePoint));
\r
27 return sb.toString();
\r
30 public int getMaxWidth(boolean isShort) {
\r
34 private static class Hex extends UnicodeLabel {
\r
35 public String getValue(int codepoint, boolean isShort) {
\r
36 if (isShort) return Utility.hex(codepoint,4);
\r
37 return "U+" + Utility.hex(codepoint,4);
\r
41 public static class Constant extends UnicodeLabel {
\r
42 private String value;
\r
43 public Constant(String value) {
\r
44 if (value == null) value = "";
\r
47 public String getValue(int codepoint, boolean isShort) {
\r
50 public int getMaxWidth(boolean isShort) {
\r
51 return value.length();
\r
54 public static final UnicodeLabel NULL = new Constant("");
\r
55 public static final UnicodeLabel HEX = new Hex();
\r