1/* GENERATED SOURCE. DO NOT MODIFY. */
2// © 2016 and later: Unicode, Inc. and others.
3// License & terms of use: http://www.unicode.org/copyright.html#License
4/*
5**********************************************************************
6*   Copyright (c) 2002-2010, International Business Machines Corporation
7*   and others.  All Rights Reserved.
8**********************************************************************
9*   Date        Name        Description
10*   01/14/2002  aliu        Creation.
11**********************************************************************
12*/
13
14package android.icu.text;
15
16/**
17 * A replacer that calls a transliterator to generate its output text.
18 * The input text to the transliterator is the output of another
19 * UnicodeReplacer object.  That is, this replacer wraps another
20 * replacer with a transliterator.
21 * @author Alan Liu
22 */
23class FunctionReplacer implements UnicodeReplacer {
24
25    /**
26     * The transliterator.  Must not be null.
27     */
28    private Transliterator translit;
29
30    /**
31     * The replacer object.  This generates text that is then
32     * processed by 'translit'.  Must not be null.
33     */
34    private UnicodeReplacer replacer;
35
36    /**
37     * Construct a replacer that takes the output of the given
38     * replacer, passes it through the given transliterator, and emits
39     * the result as output.
40     */
41    public FunctionReplacer(Transliterator theTranslit,
42                            UnicodeReplacer theReplacer) {
43        translit = theTranslit;
44        replacer = theReplacer;
45    }
46
47    /**
48     * UnicodeReplacer API
49     */
50    @Override
51    public int replace(Replaceable text,
52                       int start,
53                       int limit,
54                       int[] cursor) {
55
56        // First delegate to subordinate replacer
57        int len = replacer.replace(text, start, limit, cursor);
58        limit = start + len;
59
60        // Now transliterate
61        limit = translit.transliterate(text, start, limit);
62
63        return limit - start;
64    }
65
66    /**
67     * UnicodeReplacer API
68     */
69    @Override
70    public String toReplacerPattern(boolean escapeUnprintable) {
71        StringBuilder rule = new StringBuilder("&");
72        rule.append(translit.getID());
73        rule.append("( ");
74        rule.append(replacer.toReplacerPattern(escapeUnprintable));
75        rule.append(" )");
76        return rule.toString();
77    }
78
79    /**
80     * Union the set of all characters that may output by this object
81     * into the given set.
82     * @param toUnionTo the set into which to union the output characters
83     */
84    @Override
85    public void addReplacementSetTo(UnicodeSet toUnionTo) {
86        toUnionTo.addAll(translit.getTargetSet());
87    }
88}
89
90//eof
91