1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4**********************************************************************
5* Copyright (c) 2002-2011, International Business Machines Corporation
6* and others. All Rights Reserved.
7**********************************************************************
8* Date Name Description
9* 02/04/2002 aliu Creation.
10**********************************************************************
11*/
12
13#ifndef FUNCREPL_H
14#define FUNCREPL_H
15
16#include "unicode/utypes.h"
17
18#if !UCONFIG_NO_TRANSLITERATION
19
20#include "unicode/unifunct.h"
21#include "unicode/unirepl.h"
22
23U_NAMESPACE_BEGIN
24
25class Transliterator;
26
27/**
28 * A replacer that calls a transliterator to generate its output text.
29 * The input text to the transliterator is the output of another
30 * UnicodeReplacer object. That is, this replacer wraps another
31 * replacer with a transliterator.
32 *
33 * @author Alan Liu
34 */
35class FunctionReplacer : public UnicodeFunctor, public UnicodeReplacer {
36
37 private:
38
39 /**
40 * The transliterator. Must not be null. OWNED.
41 */
42 Transliterator* translit;
43
44 /**
45 * The replacer object. This generates text that is then
46 * processed by 'translit'. Must not be null. OWNED.
47 */
48 UnicodeFunctor* replacer;
49
50 public:
51
52 /**
53 * Construct a replacer that takes the output of the given
54 * replacer, passes it through the given transliterator, and emits
55 * the result as output.
56 */
57 FunctionReplacer(Transliterator* adoptedTranslit,
58 UnicodeFunctor* adoptedReplacer);
59
60 /**
61 * Copy constructor.
62 */
63 FunctionReplacer(const FunctionReplacer& other);
64
65 /**
66 * Destructor
67 */
68 virtual ~FunctionReplacer();
69
70 /**
71 * Implement UnicodeFunctor
72 */
73 virtual FunctionReplacer* clone() const;
74
75 /**
76 * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
77 * and return the pointer.
78 */
79 virtual UnicodeReplacer* toReplacer() const;
80
81 /**
82 * UnicodeReplacer API
83 */
84 virtual int32_t replace(Replaceable& text,
85 int32_t start,
86 int32_t limit,
87 int32_t& cursor);
88
89 /**
90 * UnicodeReplacer API
91 */
92 virtual UnicodeString& toReplacerPattern(UnicodeString& rule,
93 UBool escapeUnprintable) const;
94
95 /**
96 * Implement UnicodeReplacer
97 */
98 virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
99
100 /**
101 * UnicodeFunctor API
102 */
103 virtual void setData(const TransliterationRuleData*);
104
105 /**
106 * ICU "poor man's RTTI", returns a UClassID for the actual class.
107 */
108 virtual UClassID getDynamicClassID() const;
109
110 /**
111 * ICU "poor man's RTTI", returns a UClassID for this class.
112 */
113 static UClassID U_EXPORT2 getStaticClassID();
114};
115
116U_NAMESPACE_END
117
118#endif /* #if !UCONFIG_NO_TRANSLITERATION */
119#endif
120
121//eof
122