1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (c) 2002-2011, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 **********************************************************************
8 * Date Name Description
9 * 01/21/2002 aliu Creation.
10 **********************************************************************
16 #include "unicode/utypes.h"
18 #if !UCONFIG_NO_TRANSLITERATION
20 #include "unicode/unifunct.h"
21 #include "unicode/unirepl.h"
22 #include "unicode/unistr.h"
26 class TransliterationRuleData;
29 * A replacer that produces static text as its output. The text may
30 * contain transliterator stand-in characters that represent nested
31 * UnicodeReplacer objects, making it possible to encode a tree of
32 * replacers in a StringReplacer. A StringReplacer that contains such
33 * stand-ins is called a <em>complex</em> StringReplacer. A complex
34 * StringReplacer has a slower processing loop than a non-complex one.
37 class StringReplacer : public UnicodeFunctor, public UnicodeReplacer {
42 * Output text, possibly containing stand-in characters that
43 * represent nested UnicodeReplacers.
48 * Cursor position. Value is ignored if hasCursor is false.
53 * True if this object outputs a cursor position.
58 * A complex object contains nested replacers and requires more
59 * complex processing. StringReplacers are initially assumed to
60 * be complex. If no nested replacers are seen during processing,
61 * then isComplex is set to false, and future replacements are
62 * short circuited for better performance.
67 * Object that translates stand-in characters in 'output' to
68 * UnicodeReplacer objects.
70 const TransliterationRuleData* data;
75 * Construct a StringReplacer that sets the emits the given output
76 * text and sets the cursor to the given position.
77 * @param theOutput text that will replace input text when the
78 * replace() method is called. May contain stand-in characters
79 * that represent nested replacers.
80 * @param theCursorPos cursor position that will be returned by
81 * the replace() method
82 * @param theData transliterator context object that translates
83 * stand-in characters to UnicodeReplacer objects
85 StringReplacer(const UnicodeString& theOutput,
87 const TransliterationRuleData* theData);
90 * Construct a StringReplacer that sets the emits the given output
91 * text and does not modify the cursor.
92 * @param theOutput text that will replace input text when the
93 * replace() method is called. May contain stand-in characters
94 * that represent nested replacers.
95 * @param theData transliterator context object that translates
96 * stand-in characters to UnicodeReplacer objects
98 StringReplacer(const UnicodeString& theOutput,
99 const TransliterationRuleData* theData);
104 StringReplacer(const StringReplacer& other);
109 virtual ~StringReplacer();
112 * Implement UnicodeFunctor
114 virtual UnicodeFunctor* clone() const;
117 * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
118 * and return the pointer.
120 virtual UnicodeReplacer* toReplacer() const;
123 * UnicodeReplacer API
125 virtual int32_t replace(Replaceable& text,
131 * UnicodeReplacer API
133 virtual UnicodeString& toReplacerPattern(UnicodeString& result,
134 UBool escapeUnprintable) const;
137 * Implement UnicodeReplacer
139 virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
144 virtual void setData(const TransliterationRuleData*);
147 * ICU "poor man's RTTI", returns a UClassID for this class.
149 static UClassID U_EXPORT2 getStaticClassID();
152 * ICU "poor man's RTTI", returns a UClassID for the actual class.
154 virtual UClassID getDynamicClassID() const;
159 #endif /* #if !UCONFIG_NO_TRANSLITERATION */