2 *******************************************************************************
3 * Copyright (C) 2002-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.dev.test.util;
9 import com.ibm.icu.impl.Utility;
10 import com.ibm.icu.text.UTF16;
12 public abstract class Quoter {
13 private static boolean DEBUG = false;
15 protected boolean quoting = false;
16 protected StringBuffer output = new StringBuffer();
18 public void setQuoting(boolean value) {
21 public boolean isQuoting() {
29 return output.length();
31 public Quoter append(String string) {
32 output.append(string);
35 public Quoter append(int codepoint) {
36 return append(UTF16.valueOf(codepoint));
38 // warning, allows access to internals
39 public String toString() {
40 setQuoting(false); // finish quoting
41 return output.toString();
44 * Implements standard ICU rule quoting
46 public static class RuleQuoter extends Quoter {
47 private StringBuffer quoteBuffer = new StringBuffer();
48 public void setQuoting(boolean value) {
49 if (quoting == value) return;
50 if (quoting) { // stop quoting
51 Utility.appendToRule(output, (int)-1, true, false, quoteBuffer); // close previous quote
55 public Quoter append(String s) {
56 if (DEBUG) System.out.println("\"" + s + "\"");
58 Utility.appendToRule(output, s, false, false, quoteBuffer);