michael@0: /* michael@0: *********************************************************************** michael@0: * Copyright (c) 2002-2007, International Business Machines Corporation michael@0: * and others. All Rights Reserved. michael@0: *********************************************************************** michael@0: * Date Name Description michael@0: * 06/06/2002 aliu Creation. michael@0: *********************************************************************** michael@0: */ michael@0: #ifndef _ANYTRANS_H_ michael@0: #define _ANYTRANS_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: #include "unicode/uscript.h" michael@0: #include "uhash.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * A transliterator named Any-T or Any-T/V, where T is the target michael@0: * script and V is the optional variant, that uses multiple michael@0: * transliterators, all going to T or T/V, all with script sources. michael@0: * The target must be a script. It partitions text into runs of the michael@0: * same script, and then based on the script of each run, michael@0: * transliterates from that script to the given target or michael@0: * target/variant. Adjacent COMMON or INHERITED script characters are michael@0: * included in each run. michael@0: * michael@0: * @author Alan Liu michael@0: */ michael@0: class AnyTransliterator : public Transliterator { michael@0: michael@0: /** michael@0: * Cache mapping UScriptCode values to Transliterator*. michael@0: */ michael@0: UHashtable* cache; michael@0: michael@0: /** michael@0: * The target or target/variant string. michael@0: */ michael@0: UnicodeString target; michael@0: michael@0: /** michael@0: * The target script code. Never USCRIPT_INVALID_CODE. michael@0: */ michael@0: UScriptCode targetScript; michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Destructor. michael@0: */ michael@0: virtual ~AnyTransliterator(); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: */ michael@0: AnyTransliterator(const AnyTransliterator&); michael@0: michael@0: /** michael@0: * Transliterator API. michael@0: */ michael@0: virtual Transliterator* clone() const; michael@0: michael@0: /** michael@0: * Implements {@link Transliterator#handleTransliterate}. michael@0: */ michael@0: virtual void handleTransliterate(Replaceable& text, UTransPosition& index, michael@0: UBool incremental) const; 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: U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * Private constructor michael@0: * @param id the ID of the form S-T or S-T/V, where T is theTarget michael@0: * and V is theVariant. Must not be empty. michael@0: * @param theTarget the target name. Must not be empty, and must michael@0: * name a script corresponding to theTargetScript. michael@0: * @param theVariant the variant name, or the empty string if michael@0: * there is no variant michael@0: * @param theTargetScript the script code corresponding to michael@0: * theTarget. michael@0: * @param ec error code, fails if the internal hashtable cannot be michael@0: * allocated michael@0: */ michael@0: AnyTransliterator(const UnicodeString& id, michael@0: const UnicodeString& theTarget, michael@0: const UnicodeString& theVariant, michael@0: UScriptCode theTargetScript, michael@0: UErrorCode& ec); michael@0: michael@0: /** michael@0: * Returns a transliterator from the given source to our target or michael@0: * target/variant. Returns NULL if the source is the same as our michael@0: * target script, or if the source is USCRIPT_INVALID_CODE. michael@0: * Caches the result and returns the same transliterator the next michael@0: * time. The caller does NOT own the result and must not delete michael@0: * it. michael@0: */ michael@0: Transliterator* getTransliterator(UScriptCode source) const; michael@0: michael@0: /** michael@0: * Registers standard transliterators with the system. Called by michael@0: * Transliterator during initialization. michael@0: */ michael@0: static void registerIDs(); michael@0: michael@0: friend class Transliterator; // for registerIDs() michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_TRANSLITERATION */ michael@0: michael@0: #endif