]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /* |
4 | ********************************************************************** | |
73c04bcf | 5 | * Copyright (c) 2002-2005, International Business Machines Corporation |
b75a7d8f A |
6 | * and others. All Rights Reserved. |
7 | ********************************************************************** | |
8 | * Date Name Description | |
9 | * 01/14/2002 aliu Creation. | |
10 | ********************************************************************** | |
11 | */ | |
12 | #ifndef UNIREPL_H | |
13 | #define UNIREPL_H | |
14 | ||
15 | #include "unicode/utypes.h" | |
16 | ||
73c04bcf A |
17 | /** |
18 | * \file | |
19 | * \brief C++ API: UnicodeReplacer | |
20 | */ | |
21 | ||
f3c0d7a5 | 22 | #if U_SHOW_CPLUSPLUS_API |
b75a7d8f A |
23 | U_NAMESPACE_BEGIN |
24 | ||
25 | class Replaceable; | |
26 | class UnicodeString; | |
27 | class UnicodeSet; | |
28 | ||
29 | /** | |
30 | * <code>UnicodeReplacer</code> defines a protocol for objects that | |
31 | * replace a range of characters in a Replaceable string with output | |
32 | * text. The replacement is done via the Replaceable API so as to | |
33 | * preserve out-of-band data. | |
34 | * | |
35 | * <p>This is a mixin class. | |
36 | * @author Alan Liu | |
374ca955 | 37 | * @stable ICU 2.4 |
b75a7d8f A |
38 | */ |
39 | class U_I18N_API UnicodeReplacer /* not : public UObject because this is an interface/mixin class */ { | |
40 | ||
41 | public: | |
42 | ||
43 | /** | |
44 | * Destructor. | |
374ca955 | 45 | * @stable ICU 2.4 |
b75a7d8f | 46 | */ |
374ca955 | 47 | virtual ~UnicodeReplacer(); |
b75a7d8f A |
48 | |
49 | /** | |
50 | * Replace characters in 'text' from 'start' to 'limit' with the | |
51 | * output text of this object. Update the 'cursor' parameter to | |
52 | * give the cursor position and return the length of the | |
53 | * replacement text. | |
54 | * | |
55 | * @param text the text to be matched | |
56 | * @param start inclusive start index of text to be replaced | |
57 | * @param limit exclusive end index of text to be replaced; | |
58 | * must be greater than or equal to start | |
59 | * @param cursor output parameter for the cursor position. | |
60 | * Not all replacer objects will update this, but in a complete | |
61 | * tree of replacer objects, representing the entire output side | |
62 | * of a transliteration rule, at least one must update it. | |
63 | * @return the number of 16-bit code units in the text replacing | |
64 | * the characters at offsets start..(limit-1) in text | |
374ca955 | 65 | * @stable ICU 2.4 |
b75a7d8f A |
66 | */ |
67 | virtual int32_t replace(Replaceable& text, | |
68 | int32_t start, | |
69 | int32_t limit, | |
70 | int32_t& cursor) = 0; | |
71 | ||
72 | /** | |
73 | * Returns a string representation of this replacer. If the | |
74 | * result of calling this function is passed to the appropriate | |
75 | * parser, typically TransliteratorParser, it will produce another | |
76 | * replacer that is equal to this one. | |
77 | * @param result the string to receive the pattern. Previous | |
78 | * contents will be deleted. | |
79 | * @param escapeUnprintable if TRUE then convert unprintable | |
80 | * character to their hex escape representations, \\uxxxx or | |
81 | * \\Uxxxxxxxx. Unprintable characters are defined by | |
82 | * Utility.isUnprintable(). | |
83 | * @return a reference to 'result'. | |
374ca955 | 84 | * @stable ICU 2.4 |
b75a7d8f A |
85 | */ |
86 | virtual UnicodeString& toReplacerPattern(UnicodeString& result, | |
87 | UBool escapeUnprintable) const = 0; | |
88 | ||
89 | /** | |
90 | * Union the set of all characters that may output by this object | |
91 | * into the given set. | |
92 | * @param toUnionTo the set into which to union the output characters | |
374ca955 | 93 | * @stable ICU 2.4 |
b75a7d8f A |
94 | */ |
95 | virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const = 0; | |
96 | }; | |
97 | ||
98 | U_NAMESPACE_END | |
f3c0d7a5 | 99 | #endif // U_SHOW_CPLUSPLUS_API |
b75a7d8f A |
100 | |
101 | #endif |