1 /* 2 ********************************************************************** 3 * Copyright (c) 2002-2011, International Business Machines Corporation 4 * and others. All Rights Reserved. 5 ********************************************************************** 6 * Date Name Description 7 * 02/04/2002 aliu Creation. 8 ********************************************************************** 9 */ 10 11 #ifndef FUNCREPL_H 12 #define FUNCREPL_H 13 14 #include "unicode/utypes.h" 15 16 #if !UCONFIG_NO_TRANSLITERATION 17 18 #include "unicode/unifunct.h" 19 #include "unicode/unirepl.h" 20 21 U_NAMESPACE_BEGIN 22 23 class Transliterator; 24 25 /** 26 * A replacer that calls a transliterator to generate its output text. 27 * The input text to the transliterator is the output of another 28 * UnicodeReplacer object. That is, this replacer wraps another 29 * replacer with a transliterator. 30 * 31 * @author Alan Liu 32 */ 33 class FunctionReplacer : public UnicodeFunctor, public UnicodeReplacer { 34 35 private: 36 37 /** 38 * The transliterator. Must not be null. OWNED. 39 */ 40 Transliterator* translit; 41 42 /** 43 * The replacer object. This generates text that is then 44 * processed by 'translit'. Must not be null. OWNED. 45 */ 46 UnicodeFunctor* replacer; 47 48 public: 49 50 /** 51 * Construct a replacer that takes the output of the given 52 * replacer, passes it through the given transliterator, and emits 53 * the result as output. 54 */ 55 FunctionReplacer(Transliterator* adoptedTranslit, 56 UnicodeFunctor* adoptedReplacer); 57 58 /** 59 * Copy constructor. 60 */ 61 FunctionReplacer(const FunctionReplacer& other); 62 63 /** 64 * Destructor 65 */ 66 virtual ~FunctionReplacer(); 67 68 /** 69 * Implement UnicodeFunctor 70 */ 71 virtual UnicodeFunctor* clone() const; 72 73 /** 74 * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer 75 * and return the pointer. 76 */ 77 virtual UnicodeReplacer* toReplacer() const; 78 79 /** 80 * UnicodeReplacer API 81 */ 82 virtual int32_t replace(Replaceable& text, 83 int32_t start, 84 int32_t limit, 85 int32_t& cursor); 86 87 /** 88 * UnicodeReplacer API 89 */ 90 virtual UnicodeString& toReplacerPattern(UnicodeString& rule, 91 UBool escapeUnprintable) const; 92 93 /** 94 * Implement UnicodeReplacer 95 */ 96 virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const; 97 98 /** 99 * UnicodeFunctor API 100 */ 101 virtual void setData(const TransliterationRuleData*); 102 103 /** 104 * ICU "poor man's RTTI", returns a UClassID for the actual class. 105 */ 106 virtual UClassID getDynamicClassID() const; 107 108 /** 109 * ICU "poor man's RTTI", returns a UClassID for this class. 110 */ 111 static UClassID U_EXPORT2 getStaticClassID(); 112 }; 113 114 U_NAMESPACE_END 115 116 #endif /* #if !UCONFIG_NO_TRANSLITERATION */ 117 #endif 118 119 //eof 120