2 **********************************************************************
\r
3 * Copyright (c) 2002-2010, International Business Machines Corporation
\r
4 * and others. All Rights Reserved.
\r
5 **********************************************************************
\r
6 * Date Name Description
\r
7 * 01/14/2002 aliu Creation.
\r
8 **********************************************************************
\r
11 package com.ibm.icu.text;
\r
14 * A replacer that calls a transliterator to generate its output text.
\r
15 * The input text to the transliterator is the output of another
\r
16 * UnicodeReplacer object. That is, this replacer wraps another
\r
17 * replacer with a transliterator.
\r
20 class FunctionReplacer implements UnicodeReplacer {
\r
23 * The transliterator. Must not be null.
\r
25 private Transliterator translit;
\r
28 * The replacer object. This generates text that is then
\r
29 * processed by 'translit'. Must not be null.
\r
31 private UnicodeReplacer replacer;
\r
34 * Construct a replacer that takes the output of the given
\r
35 * replacer, passes it through the given transliterator, and emits
\r
36 * the result as output.
\r
38 public FunctionReplacer(Transliterator theTranslit,
\r
39 UnicodeReplacer theReplacer) {
\r
40 translit = theTranslit;
\r
41 replacer = theReplacer;
\r
45 * UnicodeReplacer API
\r
47 public int replace(Replaceable text,
\r
52 // First delegate to subordinate replacer
\r
53 int len = replacer.replace(text, start, limit, cursor);
\r
54 limit = start + len;
\r
56 // Now transliterate
\r
57 limit = translit.transliterate(text, start, limit);
\r
59 return limit - start;
\r
63 * UnicodeReplacer API
\r
65 public String toReplacerPattern(boolean escapeUnprintable) {
\r
66 StringBuilder rule = new StringBuilder("&");
\r
67 rule.append(translit.getID());
\r
69 rule.append(replacer.toReplacerPattern(escapeUnprintable));
\r
71 return rule.toString();
\r
75 * Union the set of all characters that may output by this object
\r
76 * into the given set.
\r
77 * @param toUnionTo the set into which to union the output characters
\r
79 public void addReplacementSetTo(UnicodeSet toUnionTo) {
\r
80 toUnionTo.addAll(translit.getTargetSet());
\r