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