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

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

mercurial