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