intl/icu/source/i18n/strrepl.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 **********************************************************************
michael@0 3 * Copyright (c) 2002-2011, International Business Machines Corporation
michael@0 4 * and others. All Rights Reserved.
michael@0 5 **********************************************************************
michael@0 6 * Date Name Description
michael@0 7 * 01/21/2002 aliu Creation.
michael@0 8 **********************************************************************
michael@0 9 */
michael@0 10
michael@0 11 #ifndef STRREPL_H
michael@0 12 #define STRREPL_H
michael@0 13
michael@0 14 #include "unicode/utypes.h"
michael@0 15
michael@0 16 #if !UCONFIG_NO_TRANSLITERATION
michael@0 17
michael@0 18 #include "unicode/unifunct.h"
michael@0 19 #include "unicode/unirepl.h"
michael@0 20 #include "unicode/unistr.h"
michael@0 21
michael@0 22 U_NAMESPACE_BEGIN
michael@0 23
michael@0 24 class TransliterationRuleData;
michael@0 25
michael@0 26 /**
michael@0 27 * A replacer that produces static text as its output. The text may
michael@0 28 * contain transliterator stand-in characters that represent nested
michael@0 29 * UnicodeReplacer objects, making it possible to encode a tree of
michael@0 30 * replacers in a StringReplacer. A StringReplacer that contains such
michael@0 31 * stand-ins is called a <em>complex</em> StringReplacer. A complex
michael@0 32 * StringReplacer has a slower processing loop than a non-complex one.
michael@0 33 * @author Alan Liu
michael@0 34 */
michael@0 35 class StringReplacer : public UnicodeFunctor, public UnicodeReplacer {
michael@0 36
michael@0 37 private:
michael@0 38
michael@0 39 /**
michael@0 40 * Output text, possibly containing stand-in characters that
michael@0 41 * represent nested UnicodeReplacers.
michael@0 42 */
michael@0 43 UnicodeString output;
michael@0 44
michael@0 45 /**
michael@0 46 * Cursor position. Value is ignored if hasCursor is false.
michael@0 47 */
michael@0 48 int32_t cursorPos;
michael@0 49
michael@0 50 /**
michael@0 51 * True if this object outputs a cursor position.
michael@0 52 */
michael@0 53 UBool hasCursor;
michael@0 54
michael@0 55 /**
michael@0 56 * A complex object contains nested replacers and requires more
michael@0 57 * complex processing. StringReplacers are initially assumed to
michael@0 58 * be complex. If no nested replacers are seen during processing,
michael@0 59 * then isComplex is set to false, and future replacements are
michael@0 60 * short circuited for better performance.
michael@0 61 */
michael@0 62 UBool isComplex;
michael@0 63
michael@0 64 /**
michael@0 65 * Object that translates stand-in characters in 'output' to
michael@0 66 * UnicodeReplacer objects.
michael@0 67 */
michael@0 68 const TransliterationRuleData* data;
michael@0 69
michael@0 70 public:
michael@0 71
michael@0 72 /**
michael@0 73 * Construct a StringReplacer that sets the emits the given output
michael@0 74 * text and sets the cursor to the given position.
michael@0 75 * @param theOutput text that will replace input text when the
michael@0 76 * replace() method is called. May contain stand-in characters
michael@0 77 * that represent nested replacers.
michael@0 78 * @param theCursorPos cursor position that will be returned by
michael@0 79 * the replace() method
michael@0 80 * @param theData transliterator context object that translates
michael@0 81 * stand-in characters to UnicodeReplacer objects
michael@0 82 */
michael@0 83 StringReplacer(const UnicodeString& theOutput,
michael@0 84 int32_t theCursorPos,
michael@0 85 const TransliterationRuleData* theData);
michael@0 86
michael@0 87 /**
michael@0 88 * Construct a StringReplacer that sets the emits the given output
michael@0 89 * text and does not modify the cursor.
michael@0 90 * @param theOutput text that will replace input text when the
michael@0 91 * replace() method is called. May contain stand-in characters
michael@0 92 * that represent nested replacers.
michael@0 93 * @param theData transliterator context object that translates
michael@0 94 * stand-in characters to UnicodeReplacer objects
michael@0 95 */
michael@0 96 StringReplacer(const UnicodeString& theOutput,
michael@0 97 const TransliterationRuleData* theData);
michael@0 98
michael@0 99 /**
michael@0 100 * Copy constructor.
michael@0 101 */
michael@0 102 StringReplacer(const StringReplacer& other);
michael@0 103
michael@0 104 /**
michael@0 105 * Destructor
michael@0 106 */
michael@0 107 virtual ~StringReplacer();
michael@0 108
michael@0 109 /**
michael@0 110 * Implement UnicodeFunctor
michael@0 111 */
michael@0 112 virtual UnicodeFunctor* clone() const;
michael@0 113
michael@0 114 /**
michael@0 115 * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
michael@0 116 * and return the pointer.
michael@0 117 */
michael@0 118 virtual UnicodeReplacer* toReplacer() const;
michael@0 119
michael@0 120 /**
michael@0 121 * UnicodeReplacer API
michael@0 122 */
michael@0 123 virtual int32_t replace(Replaceable& text,
michael@0 124 int32_t start,
michael@0 125 int32_t limit,
michael@0 126 int32_t& cursor);
michael@0 127
michael@0 128 /**
michael@0 129 * UnicodeReplacer API
michael@0 130 */
michael@0 131 virtual UnicodeString& toReplacerPattern(UnicodeString& result,
michael@0 132 UBool escapeUnprintable) const;
michael@0 133
michael@0 134 /**
michael@0 135 * Implement UnicodeReplacer
michael@0 136 */
michael@0 137 virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
michael@0 138
michael@0 139 /**
michael@0 140 * UnicodeFunctor API
michael@0 141 */
michael@0 142 virtual void setData(const TransliterationRuleData*);
michael@0 143
michael@0 144 /**
michael@0 145 * ICU "poor man's RTTI", returns a UClassID for this class.
michael@0 146 */
michael@0 147 static UClassID U_EXPORT2 getStaticClassID();
michael@0 148
michael@0 149 /**
michael@0 150 * ICU "poor man's RTTI", returns a UClassID for the actual class.
michael@0 151 */
michael@0 152 virtual UClassID getDynamicClassID() const;
michael@0 153 };
michael@0 154
michael@0 155 U_NAMESPACE_END
michael@0 156
michael@0 157 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
michael@0 158
michael@0 159 #endif
michael@0 160
michael@0 161 //eof

mercurial