michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (c) 2002-2011, International Business Machines Corporation michael@0: * and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Date Name Description michael@0: * 01/21/2002 aliu Creation. michael@0: ********************************************************************** michael@0: */ michael@0: michael@0: #ifndef STRREPL_H michael@0: #define STRREPL_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: #include "unicode/unifunct.h" michael@0: #include "unicode/unirepl.h" michael@0: #include "unicode/unistr.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class TransliterationRuleData; michael@0: michael@0: /** michael@0: * A replacer that produces static text as its output. The text may michael@0: * contain transliterator stand-in characters that represent nested michael@0: * UnicodeReplacer objects, making it possible to encode a tree of michael@0: * replacers in a StringReplacer. A StringReplacer that contains such michael@0: * stand-ins is called a complex StringReplacer. A complex michael@0: * StringReplacer has a slower processing loop than a non-complex one. michael@0: * @author Alan Liu michael@0: */ michael@0: class StringReplacer : public UnicodeFunctor, public UnicodeReplacer { michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * Output text, possibly containing stand-in characters that michael@0: * represent nested UnicodeReplacers. michael@0: */ michael@0: UnicodeString output; michael@0: michael@0: /** michael@0: * Cursor position. Value is ignored if hasCursor is false. michael@0: */ michael@0: int32_t cursorPos; michael@0: michael@0: /** michael@0: * True if this object outputs a cursor position. michael@0: */ michael@0: UBool hasCursor; michael@0: michael@0: /** michael@0: * A complex object contains nested replacers and requires more michael@0: * complex processing. StringReplacers are initially assumed to michael@0: * be complex. If no nested replacers are seen during processing, michael@0: * then isComplex is set to false, and future replacements are michael@0: * short circuited for better performance. michael@0: */ michael@0: UBool isComplex; michael@0: michael@0: /** michael@0: * Object that translates stand-in characters in 'output' to michael@0: * UnicodeReplacer objects. michael@0: */ michael@0: const TransliterationRuleData* data; michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Construct a StringReplacer that sets the emits the given output michael@0: * text and sets the cursor to the given position. michael@0: * @param theOutput text that will replace input text when the michael@0: * replace() method is called. May contain stand-in characters michael@0: * that represent nested replacers. michael@0: * @param theCursorPos cursor position that will be returned by michael@0: * the replace() method michael@0: * @param theData transliterator context object that translates michael@0: * stand-in characters to UnicodeReplacer objects michael@0: */ michael@0: StringReplacer(const UnicodeString& theOutput, michael@0: int32_t theCursorPos, michael@0: const TransliterationRuleData* theData); michael@0: michael@0: /** michael@0: * Construct a StringReplacer that sets the emits the given output michael@0: * text and does not modify the cursor. michael@0: * @param theOutput text that will replace input text when the michael@0: * replace() method is called. May contain stand-in characters michael@0: * that represent nested replacers. michael@0: * @param theData transliterator context object that translates michael@0: * stand-in characters to UnicodeReplacer objects michael@0: */ michael@0: StringReplacer(const UnicodeString& theOutput, michael@0: const TransliterationRuleData* theData); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: */ michael@0: StringReplacer(const StringReplacer& other); michael@0: michael@0: /** michael@0: * Destructor michael@0: */ michael@0: virtual ~StringReplacer(); michael@0: michael@0: /** michael@0: * Implement UnicodeFunctor michael@0: */ michael@0: virtual UnicodeFunctor* clone() const; michael@0: michael@0: /** michael@0: * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer michael@0: * and return the pointer. michael@0: */ michael@0: virtual UnicodeReplacer* toReplacer() const; michael@0: michael@0: /** michael@0: * UnicodeReplacer API michael@0: */ michael@0: virtual int32_t replace(Replaceable& text, michael@0: int32_t start, michael@0: int32_t limit, michael@0: int32_t& cursor); michael@0: michael@0: /** michael@0: * UnicodeReplacer API michael@0: */ michael@0: virtual UnicodeString& toReplacerPattern(UnicodeString& result, michael@0: UBool escapeUnprintable) const; michael@0: michael@0: /** michael@0: * Implement UnicodeReplacer michael@0: */ michael@0: virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const; michael@0: michael@0: /** michael@0: * UnicodeFunctor API michael@0: */ michael@0: virtual void setData(const TransliterationRuleData*); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_TRANSLITERATION */ michael@0: michael@0: #endif michael@0: michael@0: //eof