intl/icu/source/i18n/strrepl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/strrepl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +*   Copyright (c) 2002-2011, International Business Machines Corporation
     1.7 +*   and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +*   Date        Name        Description
    1.10 +*   01/21/2002  aliu        Creation.
    1.11 +**********************************************************************
    1.12 +*/
    1.13 +
    1.14 +#ifndef STRREPL_H
    1.15 +#define STRREPL_H
    1.16 +
    1.17 +#include "unicode/utypes.h"
    1.18 +
    1.19 +#if !UCONFIG_NO_TRANSLITERATION
    1.20 +
    1.21 +#include "unicode/unifunct.h"
    1.22 +#include "unicode/unirepl.h"
    1.23 +#include "unicode/unistr.h"
    1.24 +
    1.25 +U_NAMESPACE_BEGIN
    1.26 +
    1.27 +class TransliterationRuleData;
    1.28 +
    1.29 +/**
    1.30 + * A replacer that produces static text as its output.  The text may
    1.31 + * contain transliterator stand-in characters that represent nested
    1.32 + * UnicodeReplacer objects, making it possible to encode a tree of
    1.33 + * replacers in a StringReplacer.  A StringReplacer that contains such
    1.34 + * stand-ins is called a <em>complex</em> StringReplacer.  A complex
    1.35 + * StringReplacer has a slower processing loop than a non-complex one.
    1.36 + * @author Alan Liu
    1.37 + */
    1.38 +class StringReplacer : public UnicodeFunctor, public UnicodeReplacer {
    1.39 +
    1.40 + private:
    1.41 +
    1.42 +    /**
    1.43 +     * Output text, possibly containing stand-in characters that
    1.44 +     * represent nested UnicodeReplacers.
    1.45 +     */
    1.46 +    UnicodeString output;
    1.47 +
    1.48 +    /**
    1.49 +     * Cursor position.  Value is ignored if hasCursor is false.
    1.50 +     */
    1.51 +    int32_t cursorPos;
    1.52 +
    1.53 +    /**
    1.54 +     * True if this object outputs a cursor position.
    1.55 +     */
    1.56 +    UBool hasCursor;
    1.57 +
    1.58 +    /**
    1.59 +     * A complex object contains nested replacers and requires more
    1.60 +     * complex processing.  StringReplacers are initially assumed to
    1.61 +     * be complex.  If no nested replacers are seen during processing,
    1.62 +     * then isComplex is set to false, and future replacements are
    1.63 +     * short circuited for better performance.
    1.64 +     */
    1.65 +    UBool isComplex;
    1.66 +
    1.67 +    /**
    1.68 +     * Object that translates stand-in characters in 'output' to
    1.69 +     * UnicodeReplacer objects.
    1.70 +     */
    1.71 +    const TransliterationRuleData* data;
    1.72 +
    1.73 + public:
    1.74 +
    1.75 +    /**
    1.76 +     * Construct a StringReplacer that sets the emits the given output
    1.77 +     * text and sets the cursor to the given position.
    1.78 +     * @param theOutput text that will replace input text when the
    1.79 +     * replace() method is called.  May contain stand-in characters
    1.80 +     * that represent nested replacers.
    1.81 +     * @param theCursorPos cursor position that will be returned by
    1.82 +     * the replace() method
    1.83 +     * @param theData transliterator context object that translates
    1.84 +     * stand-in characters to UnicodeReplacer objects
    1.85 +     */
    1.86 +    StringReplacer(const UnicodeString& theOutput,
    1.87 +                   int32_t theCursorPos,
    1.88 +                   const TransliterationRuleData* theData);
    1.89 +
    1.90 +    /**
    1.91 +     * Construct a StringReplacer that sets the emits the given output
    1.92 +     * text and does not modify the cursor.
    1.93 +     * @param theOutput text that will replace input text when the
    1.94 +     * replace() method is called.  May contain stand-in characters
    1.95 +     * that represent nested replacers.
    1.96 +     * @param theData transliterator context object that translates
    1.97 +     * stand-in characters to UnicodeReplacer objects
    1.98 +     */
    1.99 +    StringReplacer(const UnicodeString& theOutput,
   1.100 +                   const TransliterationRuleData* theData);
   1.101 +
   1.102 +    /**
   1.103 +     * Copy constructor.
   1.104 +     */
   1.105 +    StringReplacer(const StringReplacer& other);
   1.106 +
   1.107 +    /**
   1.108 +     * Destructor
   1.109 +     */
   1.110 +    virtual ~StringReplacer();
   1.111 +
   1.112 +    /**
   1.113 +     * Implement UnicodeFunctor
   1.114 +     */
   1.115 +    virtual UnicodeFunctor* clone() const;
   1.116 +
   1.117 +    /**
   1.118 +     * UnicodeFunctor API.  Cast 'this' to a UnicodeReplacer* pointer
   1.119 +     * and return the pointer.
   1.120 +     */
   1.121 +    virtual UnicodeReplacer* toReplacer() const;
   1.122 +
   1.123 +    /**
   1.124 +     * UnicodeReplacer API
   1.125 +     */
   1.126 +    virtual int32_t replace(Replaceable& text,
   1.127 +                            int32_t start,
   1.128 +                            int32_t limit,
   1.129 +                            int32_t& cursor);
   1.130 +
   1.131 +    /**
   1.132 +     * UnicodeReplacer API
   1.133 +     */
   1.134 +    virtual UnicodeString& toReplacerPattern(UnicodeString& result,
   1.135 +                                             UBool escapeUnprintable) const;
   1.136 +
   1.137 +    /**
   1.138 +     * Implement UnicodeReplacer
   1.139 +     */
   1.140 +    virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
   1.141 +
   1.142 +    /**
   1.143 +     * UnicodeFunctor API
   1.144 +     */
   1.145 +    virtual void setData(const TransliterationRuleData*);
   1.146 +
   1.147 +    /**
   1.148 +     * ICU "poor man's RTTI", returns a UClassID for this class.
   1.149 +     */
   1.150 +    static UClassID U_EXPORT2 getStaticClassID();
   1.151 +
   1.152 +    /**
   1.153 +     * ICU "poor man's RTTI", returns a UClassID for the actual class.
   1.154 +     */
   1.155 +    virtual UClassID getDynamicClassID() const;
   1.156 +};
   1.157 +
   1.158 +U_NAMESPACE_END
   1.159 +
   1.160 +#endif /* #if !UCONFIG_NO_TRANSLITERATION */
   1.161 +
   1.162 +#endif
   1.163 +
   1.164 +//eof

mercurial