]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/strrepl.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / i18n / strrepl.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (c) 2002, International Business Machines Corporation
4* and others. All Rights Reserved.
5**********************************************************************
6* Date Name Description
7* 01/21/2002 aliu Creation.
8**********************************************************************
9*/
10
11#ifndef STRREPL_H
12#define STRREPL_H
13
14#include "unicode/utypes.h"
15
16#if !UCONFIG_NO_TRANSLITERATION
17
18#include "unicode/unifunct.h"
19#include "unicode/unirepl.h"
20#include "unicode/unistr.h"
21
22U_NAMESPACE_BEGIN
23
24class TransliterationRuleData;
25
26/**
27 * A replacer that produces static text as its output. The text may
28 * contain transliterator stand-in characters that represent nested
29 * UnicodeReplacer objects, making it possible to encode a tree of
30 * replacers in a StringReplacer. A StringReplacer that contains such
31 * stand-ins is called a <em>complex</em> StringReplacer. A complex
32 * StringReplacer has a slower processing loop than a non-complex one.
33 * @author Alan Liu
34 */
35class StringReplacer : public UnicodeFunctor, public UnicodeReplacer {
36
37 private:
38
39 /**
40 * Output text, possibly containing stand-in characters that
41 * represent nested UnicodeReplacers.
42 */
43 UnicodeString output;
44
45 /**
46 * Cursor position. Value is ignored if hasCursor is false.
47 */
48 int32_t cursorPos;
49
50 /**
51 * True if this object outputs a cursor position.
52 */
53 UBool hasCursor;
54
55 /**
56 * A complex object contains nested replacers and requires more
57 * complex processing. StringReplacers are initially assumed to
58 * be complex. If no nested replacers are seen during processing,
59 * then isComplex is set to false, and future replacements are
60 * short circuited for better performance.
61 */
62 UBool isComplex;
63
64 /**
65 * Object that translates stand-in characters in 'output' to
66 * UnicodeReplacer objects.
67 */
68 const TransliterationRuleData* data;
69
70 /**
71 * The address of this static class variable serves as this class's ID
72 * for ICU "poor man's RTTI".
73 */
74 static const char fgClassID;
75
76 public:
77
78 /**
79 * Construct a StringReplacer that sets the emits the given output
80 * text and sets the cursor to the given position.
81 * @param theOutput text that will replace input text when the
82 * replace() method is called. May contain stand-in characters
83 * that represent nested replacers.
84 * @param theCursorPos cursor position that will be returned by
85 * the replace() method
86 * @param theData transliterator context object that translates
87 * stand-in characters to UnicodeReplacer objects
88 */
89 StringReplacer(const UnicodeString& theOutput,
90 int32_t theCursorPos,
91 const TransliterationRuleData* theData);
92
93 /**
94 * Construct a StringReplacer that sets the emits the given output
95 * text and does not modify the cursor.
96 * @param theOutput text that will replace input text when the
97 * replace() method is called. May contain stand-in characters
98 * that represent nested replacers.
99 * @param theData transliterator context object that translates
100 * stand-in characters to UnicodeReplacer objects
101 */
102 StringReplacer(const UnicodeString& theOutput,
103 const TransliterationRuleData* theData);
104
105 /**
106 * Copy constructor.
107 */
108 StringReplacer(const StringReplacer& other);
109
110 /**
111 * Destructor
112 */
113 virtual ~StringReplacer();
114
115 /**
116 * Implement UnicodeFunctor
117 */
118 virtual UnicodeFunctor* clone() const;
119
120 /**
121 * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
122 * and return the pointer.
123 */
124 virtual UnicodeReplacer* toReplacer() const;
125
126 /**
127 * UnicodeReplacer API
128 */
129 virtual int32_t replace(Replaceable& text,
130 int32_t start,
131 int32_t limit,
132 int32_t& cursor);
133
134 /**
135 * UnicodeReplacer API
136 */
137 virtual UnicodeString& toReplacerPattern(UnicodeString& result,
138 UBool escapeUnprintable) const;
139
140 /**
141 * Implement UnicodeReplacer
142 */
143 virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
144
145 /**
146 * UnicodeFunctor API
147 */
148 virtual void setData(const TransliterationRuleData*);
149
150 /**
151 * ICU "poor man's RTTI", returns a UClassID for the actual class.
152 *
153 * @draft ICU 2.2
154 */
155 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
156
157 /**
158 * ICU "poor man's RTTI", returns a UClassID for this class.
159 *
160 * @draft ICU 2.2
161 */
162 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
163};
164
165U_NAMESPACE_END
166
167#endif /* #if !UCONFIG_NO_TRANSLITERATION */
168
169#endif
170
171//eof