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