michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Date Name Description michael@0: * 11/17/99 aliu Creation. michael@0: ********************************************************************** michael@0: */ michael@0: #ifndef CPDTRANS_H michael@0: #define CPDTRANS_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: #include "unicode/translit.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class U_COMMON_API UVector; michael@0: class TransliteratorRegistry; michael@0: michael@0: /** michael@0: * A transliterator that is composed of two or more other michael@0: * transliterator objects linked together. For example, if one michael@0: * transliterator transliterates from script A to script B, and michael@0: * another transliterates from script B to script C, the two may be michael@0: * combined to form a new transliterator from A to C. michael@0: * michael@0: *
Composed transliterators may not behave as expected. For
michael@0: * example, inverses may not combine to form the identity
michael@0: * transliterator. See the class documentation for {@link
michael@0: * Transliterator} for details.
michael@0: *
michael@0: * @author Alan Liu
michael@0: */
michael@0: class U_I18N_API CompoundTransliterator : public Transliterator {
michael@0:
michael@0: Transliterator** trans;
michael@0:
michael@0: int32_t count;
michael@0:
michael@0: int32_t numAnonymousRBTs;
michael@0:
michael@0: public:
michael@0:
michael@0: /**
michael@0: * Constructs a new compound transliterator given an array of
michael@0: * transliterators. The array of transliterators may be of any
michael@0: * length, including zero or one, however, useful compound
michael@0: * transliterators have at least two components.
michael@0: * @param transliterators array of Transliterator
michael@0: * objects
michael@0: * @param transliteratorCount The number of
michael@0: * Transliterator
objects in transliterators.
michael@0: * @param adoptedFilter the filter. Any character for which
michael@0: * filter.contains() returns false will not be
michael@0: * altered by this transliterator. If filter is
michael@0: * null then no filtering is applied.
michael@0: */
michael@0: CompoundTransliterator(Transliterator* const transliterators[],
michael@0: int32_t transliteratorCount,
michael@0: UnicodeFilter* adoptedFilter = 0);
michael@0:
michael@0: /**
michael@0: * Constructs a new compound transliterator.
michael@0: * @param id compound ID
michael@0: * @param dir either UTRANS_FORWARD or UTRANS_REVERSE
michael@0: * @param adoptedFilter a global filter for this compound transliterator
michael@0: * or NULL
michael@0: */
michael@0: CompoundTransliterator(const UnicodeString& id,
michael@0: UTransDirection dir,
michael@0: UnicodeFilter* adoptedFilter,
michael@0: UParseError& parseError,
michael@0: UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Constructs a new compound transliterator in the FORWARD
michael@0: * direction with a NULL filter.
michael@0: */
michael@0: CompoundTransliterator(const UnicodeString& id,
michael@0: UParseError& parseError,
michael@0: UErrorCode& status);
michael@0: /**
michael@0: * Destructor.
michael@0: */
michael@0: virtual ~CompoundTransliterator();
michael@0:
michael@0: /**
michael@0: * Copy constructor.
michael@0: */
michael@0: CompoundTransliterator(const CompoundTransliterator&);
michael@0:
michael@0: /**
michael@0: * Transliterator API.
michael@0: */
michael@0: virtual Transliterator* clone(void) const;
michael@0:
michael@0: /**
michael@0: * Returns the number of transliterators in this chain.
michael@0: * @return number of transliterators in this chain.
michael@0: */
michael@0: virtual int32_t getCount(void) const;
michael@0:
michael@0: /**
michael@0: * Returns the transliterator at the given index in this chain.
michael@0: * @param idx index into chain, from 0 to getCount() - 1
michael@0: * @return transliterator at the given index
michael@0: */
michael@0: virtual const Transliterator& getTransliterator(int32_t idx) const;
michael@0:
michael@0: /**
michael@0: * Sets the transliterators.
michael@0: */
michael@0: void setTransliterators(Transliterator* const transliterators[],
michael@0: int32_t count);
michael@0:
michael@0: /**
michael@0: * Adopts the transliterators.
michael@0: */
michael@0: void adoptTransliterators(Transliterator* adoptedTransliterators[],
michael@0: int32_t count);
michael@0:
michael@0: /**
michael@0: * Override Transliterator:
michael@0: * Create a rule string that can be passed to createFromRules()
michael@0: * to recreate this transliterator.
michael@0: * @param result the string to receive the rules. Previous
michael@0: * contents will be deleted.
michael@0: * @param escapeUnprintable if TRUE then convert unprintable
michael@0: * character to their hex escape representations, \uxxxx or
michael@0: * \Uxxxxxxxx. Unprintable characters are those other than
michael@0: * U+000A, U+0020..U+007E.
michael@0: */
michael@0: virtual UnicodeString& toRules(UnicodeString& result,
michael@0: UBool escapeUnprintable) const;
michael@0:
michael@0: protected:
michael@0: /**
michael@0: * Implement Transliterator framework
michael@0: */
michael@0: virtual void handleGetSourceSet(UnicodeSet& result) const;
michael@0:
michael@0: public:
michael@0: /**
michael@0: * Override Transliterator framework
michael@0: */
michael@0: virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
michael@0:
michael@0: protected:
michael@0: /**
michael@0: * Implements {@link Transliterator#handleTransliterate}.
michael@0: */
michael@0: virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
michael@0: UBool incremental) const;
michael@0:
michael@0: public:
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: * ICU "poor man's RTTI", returns a UClassID for this class.
michael@0: */
michael@0: static UClassID U_EXPORT2 getStaticClassID();
michael@0:
michael@0: /* @internal */
michael@0: static const UChar PASS_STRING[];
michael@0:
michael@0: private:
michael@0:
michael@0: friend class Transliterator;
michael@0: friend class TransliteratorAlias; // to access private ct
michael@0:
michael@0: /**
michael@0: * Assignment operator.
michael@0: */
michael@0: CompoundTransliterator& operator=(const CompoundTransliterator&);
michael@0:
michael@0: /**
michael@0: * Private constructor for Transliterator.
michael@0: */
michael@0: CompoundTransliterator(const UnicodeString& ID,
michael@0: UVector& list,
michael@0: UnicodeFilter* adoptedFilter,
michael@0: int32_t numAnonymousRBTs,
michael@0: UParseError& parseError,
michael@0: UErrorCode& status);
michael@0:
michael@0: CompoundTransliterator(UVector& list,
michael@0: UParseError& parseError,
michael@0: UErrorCode& status);
michael@0:
michael@0: CompoundTransliterator(UVector& list,
michael@0: int32_t anonymousRBTs,
michael@0: UParseError& parseError,
michael@0: UErrorCode& status);
michael@0:
michael@0: void init(const UnicodeString& id,
michael@0: UTransDirection direction,
michael@0: UBool fixReverseID,
michael@0: UErrorCode& status);
michael@0:
michael@0: void init(UVector& list,
michael@0: UTransDirection direction,
michael@0: UBool fixReverseID,
michael@0: UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Return the IDs of the given list of transliterators, concatenated
michael@0: * with ';' delimiting them. Equivalent to the perlish expression
michael@0: * join(';', map($_.getID(), transliterators).
michael@0: */
michael@0: UnicodeString joinIDs(Transliterator* const transliterators[],
michael@0: int32_t transCount);
michael@0:
michael@0: void freeTransliterators(void);
michael@0:
michael@0: void computeMaximumContextLength(void);
michael@0: };
michael@0:
michael@0: U_NAMESPACE_END
michael@0:
michael@0: #endif /* #if !UCONFIG_NO_TRANSLITERATION */
michael@0:
michael@0: #endif