1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/cpdtrans.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,230 @@ 1.4 +/* 1.5 +********************************************************************** 1.6 +* Copyright (C) 1999-2011, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +********************************************************************** 1.9 +* Date Name Description 1.10 +* 11/17/99 aliu Creation. 1.11 +********************************************************************** 1.12 +*/ 1.13 +#ifndef CPDTRANS_H 1.14 +#define CPDTRANS_H 1.15 + 1.16 +#include "unicode/utypes.h" 1.17 + 1.18 +#if !UCONFIG_NO_TRANSLITERATION 1.19 + 1.20 +#include "unicode/translit.h" 1.21 + 1.22 +U_NAMESPACE_BEGIN 1.23 + 1.24 +class U_COMMON_API UVector; 1.25 +class TransliteratorRegistry; 1.26 + 1.27 +/** 1.28 + * A transliterator that is composed of two or more other 1.29 + * transliterator objects linked together. For example, if one 1.30 + * transliterator transliterates from script A to script B, and 1.31 + * another transliterates from script B to script C, the two may be 1.32 + * combined to form a new transliterator from A to C. 1.33 + * 1.34 + * <p>Composed transliterators may not behave as expected. For 1.35 + * example, inverses may not combine to form the identity 1.36 + * transliterator. See the class documentation for {@link 1.37 + * Transliterator} for details. 1.38 + * 1.39 + * @author Alan Liu 1.40 + */ 1.41 +class U_I18N_API CompoundTransliterator : public Transliterator { 1.42 + 1.43 + Transliterator** trans; 1.44 + 1.45 + int32_t count; 1.46 + 1.47 + int32_t numAnonymousRBTs; 1.48 + 1.49 +public: 1.50 + 1.51 + /** 1.52 + * Constructs a new compound transliterator given an array of 1.53 + * transliterators. The array of transliterators may be of any 1.54 + * length, including zero or one, however, useful compound 1.55 + * transliterators have at least two components. 1.56 + * @param transliterators array of <code>Transliterator</code> 1.57 + * objects 1.58 + * @param transliteratorCount The number of 1.59 + * <code>Transliterator</code> objects in transliterators. 1.60 + * @param adoptedFilter the filter. Any character for which 1.61 + * <tt>filter.contains()</tt> returns <tt>false</tt> will not be 1.62 + * altered by this transliterator. If <tt>filter</tt> is 1.63 + * <tt>null</tt> then no filtering is applied. 1.64 + */ 1.65 + CompoundTransliterator(Transliterator* const transliterators[], 1.66 + int32_t transliteratorCount, 1.67 + UnicodeFilter* adoptedFilter = 0); 1.68 + 1.69 + /** 1.70 + * Constructs a new compound transliterator. 1.71 + * @param id compound ID 1.72 + * @param dir either UTRANS_FORWARD or UTRANS_REVERSE 1.73 + * @param adoptedFilter a global filter for this compound transliterator 1.74 + * or NULL 1.75 + */ 1.76 + CompoundTransliterator(const UnicodeString& id, 1.77 + UTransDirection dir, 1.78 + UnicodeFilter* adoptedFilter, 1.79 + UParseError& parseError, 1.80 + UErrorCode& status); 1.81 + 1.82 + /** 1.83 + * Constructs a new compound transliterator in the FORWARD 1.84 + * direction with a NULL filter. 1.85 + */ 1.86 + CompoundTransliterator(const UnicodeString& id, 1.87 + UParseError& parseError, 1.88 + UErrorCode& status); 1.89 + /** 1.90 + * Destructor. 1.91 + */ 1.92 + virtual ~CompoundTransliterator(); 1.93 + 1.94 + /** 1.95 + * Copy constructor. 1.96 + */ 1.97 + CompoundTransliterator(const CompoundTransliterator&); 1.98 + 1.99 + /** 1.100 + * Transliterator API. 1.101 + */ 1.102 + virtual Transliterator* clone(void) const; 1.103 + 1.104 + /** 1.105 + * Returns the number of transliterators in this chain. 1.106 + * @return number of transliterators in this chain. 1.107 + */ 1.108 + virtual int32_t getCount(void) const; 1.109 + 1.110 + /** 1.111 + * Returns the transliterator at the given index in this chain. 1.112 + * @param idx index into chain, from 0 to <code>getCount() - 1</code> 1.113 + * @return transliterator at the given index 1.114 + */ 1.115 + virtual const Transliterator& getTransliterator(int32_t idx) const; 1.116 + 1.117 + /** 1.118 + * Sets the transliterators. 1.119 + */ 1.120 + void setTransliterators(Transliterator* const transliterators[], 1.121 + int32_t count); 1.122 + 1.123 + /** 1.124 + * Adopts the transliterators. 1.125 + */ 1.126 + void adoptTransliterators(Transliterator* adoptedTransliterators[], 1.127 + int32_t count); 1.128 + 1.129 + /** 1.130 + * Override Transliterator: 1.131 + * Create a rule string that can be passed to createFromRules() 1.132 + * to recreate this transliterator. 1.133 + * @param result the string to receive the rules. Previous 1.134 + * contents will be deleted. 1.135 + * @param escapeUnprintable if TRUE then convert unprintable 1.136 + * character to their hex escape representations, \uxxxx or 1.137 + * \Uxxxxxxxx. Unprintable characters are those other than 1.138 + * U+000A, U+0020..U+007E. 1.139 + */ 1.140 + virtual UnicodeString& toRules(UnicodeString& result, 1.141 + UBool escapeUnprintable) const; 1.142 + 1.143 + protected: 1.144 + /** 1.145 + * Implement Transliterator framework 1.146 + */ 1.147 + virtual void handleGetSourceSet(UnicodeSet& result) const; 1.148 + 1.149 + public: 1.150 + /** 1.151 + * Override Transliterator framework 1.152 + */ 1.153 + virtual UnicodeSet& getTargetSet(UnicodeSet& result) const; 1.154 + 1.155 +protected: 1.156 + /** 1.157 + * Implements {@link Transliterator#handleTransliterate}. 1.158 + */ 1.159 + virtual void handleTransliterate(Replaceable& text, UTransPosition& idx, 1.160 + UBool incremental) const; 1.161 + 1.162 +public: 1.163 + 1.164 + /** 1.165 + * ICU "poor man's RTTI", returns a UClassID for the actual class. 1.166 + */ 1.167 + virtual UClassID getDynamicClassID() const; 1.168 + 1.169 + /** 1.170 + * ICU "poor man's RTTI", returns a UClassID for this class. 1.171 + */ 1.172 + static UClassID U_EXPORT2 getStaticClassID(); 1.173 + 1.174 + /* @internal */ 1.175 + static const UChar PASS_STRING[]; 1.176 + 1.177 +private: 1.178 + 1.179 + friend class Transliterator; 1.180 + friend class TransliteratorAlias; // to access private ct 1.181 + 1.182 + /** 1.183 + * Assignment operator. 1.184 + */ 1.185 + CompoundTransliterator& operator=(const CompoundTransliterator&); 1.186 + 1.187 + /** 1.188 + * Private constructor for Transliterator. 1.189 + */ 1.190 + CompoundTransliterator(const UnicodeString& ID, 1.191 + UVector& list, 1.192 + UnicodeFilter* adoptedFilter, 1.193 + int32_t numAnonymousRBTs, 1.194 + UParseError& parseError, 1.195 + UErrorCode& status); 1.196 + 1.197 + CompoundTransliterator(UVector& list, 1.198 + UParseError& parseError, 1.199 + UErrorCode& status); 1.200 + 1.201 + CompoundTransliterator(UVector& list, 1.202 + int32_t anonymousRBTs, 1.203 + UParseError& parseError, 1.204 + UErrorCode& status); 1.205 + 1.206 + void init(const UnicodeString& id, 1.207 + UTransDirection direction, 1.208 + UBool fixReverseID, 1.209 + UErrorCode& status); 1.210 + 1.211 + void init(UVector& list, 1.212 + UTransDirection direction, 1.213 + UBool fixReverseID, 1.214 + UErrorCode& status); 1.215 + 1.216 + /** 1.217 + * Return the IDs of the given list of transliterators, concatenated 1.218 + * with ';' delimiting them. Equivalent to the perlish expression 1.219 + * join(';', map($_.getID(), transliterators). 1.220 + */ 1.221 + UnicodeString joinIDs(Transliterator* const transliterators[], 1.222 + int32_t transCount); 1.223 + 1.224 + void freeTransliterators(void); 1.225 + 1.226 + void computeMaximumContextLength(void); 1.227 +}; 1.228 + 1.229 +U_NAMESPACE_END 1.230 + 1.231 +#endif /* #if !UCONFIG_NO_TRANSLITERATION */ 1.232 + 1.233 +#endif