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