1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************** 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Copyright (c) 2002-2007, International Business Machines Corporation 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* and others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************** 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Date Name Description 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 06/06/2002 aliu Creation. 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************** 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _ANYTRANS_H_ 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define _ANYTRANS_H_ 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/translit.h" 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uscript.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uhash.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * A transliterator named Any-T or Any-T/V, where T is the target 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * script and V is the optional variant, that uses multiple 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterators, all going to T or T/V, all with script sources. 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The target must be a script. It partitions text into runs of the 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * same script, and then based on the script of each run, 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterates from that script to the given target or 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * target/variant. Adjacent COMMON or INHERITED script characters are 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * included in each run. 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @author Alan Liu 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass AnyTransliterator : public Transliterator { 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Cache mapping UScriptCode values to Transliterator*. 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UHashtable* cache; 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The target or target/variant string. 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString target; 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The target script code. Never USCRIPT_INVALID_CODE. 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UScriptCode targetScript; 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Destructor. 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ~AnyTransliterator(); 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copy constructor. 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru AnyTransliterator(const AnyTransliterator&); 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Transliterator API. 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual Transliterator* clone() const; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Implements {@link Transliterator#handleTransliterate}. 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void handleTransliterate(Replaceable& text, UTransPosition& index, 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool incremental) const; 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICU "poor man's RTTI", returns a UClassID for the actual class. 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID() const; 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICU "poor man's RTTI", returns a UClassID for this class. 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Private constructor 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the ID of the form S-T or S-T/V, where T is theTarget 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and V is theVariant. Must not be empty. 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param theTarget the target name. Must not be empty, and must 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * name a script corresponding to theTargetScript. 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param theVariant the variant name, or the empty string if 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * there is no variant 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param theTargetScript the script code corresponding to 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * theTarget. 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param ec error code, fails if the internal hashtable cannot be 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * allocated 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru AnyTransliterator(const UnicodeString& id, 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString& theTarget, 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString& theVariant, 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UScriptCode theTargetScript, 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode& ec); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Returns a transliterator from the given source to our target or 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * target/variant. Returns NULL if the source is the same as our 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * target script, or if the source is USCRIPT_INVALID_CODE. 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Caches the result and returns the same transliterator the next 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * time. The caller does NOT own the result and must not delete 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * it. 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* getTransliterator(UScriptCode source) const; 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Registers standard transliterators with the system. Called by 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Transliterator during initialization. 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static void registerIDs(); 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru friend class Transliterator; // for registerIDs() 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_TRANSLITERATION */ 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 130