- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- Search for |

- File List
- Globals

# translit.h

Go to the documentation of this file.

    00001 /*
    00002 **********************************************************************
    00003 * Copyright (C) 1999-2008, International Business Machines
    00004 * Corporation and others. All Rights Reserved.
    00005 **********************************************************************
    00006 *   Date        Name        Description
    00007 *   11/17/99    aliu        Creation.
    00008 **********************************************************************
    00009 */
    00010 #ifndef TRANSLIT_H
    00011 #define TRANSLIT_H
    00012
    00013 #include "unicode/utypes.h"
    00014
    00020 #if !UCONFIG_NO_TRANSLITERATION
    00021
    00022 #include "unicode/uobject.h"
    00023 #include "unicode/unistr.h"
    00024 #include "unicode/parseerr.h"
    00025 #include "unicode/utrans.h" // UTransPosition, UTransDirection
    00026 #include "unicode/strenum.h"
    00027
    00028 U_NAMESPACE_BEGIN
    00029
    00030 class UnicodeFilter;
    00031 class UnicodeSet;
    00032 class CompoundTransliterator;
    00033 class TransliteratorParser;
    00034 class NormalizationTransliterator;
    00035 class TransliteratorIDParser;
    00036
    00241 class U_I18N_API Transliterator : public UObject {
    00242
    00243 private:
    00244
    00248     UnicodeString ID;
    00249
    00256     UnicodeFilter* filter;
    00257
    00258     int32_t maximumContextLength;
    00259
    00260  public:
    00261
    00267     union Token {
    00272         int32_t integer;
    00277         void*   pointer;
    00278     };
    00279
    00285     inline static Token integerToken(int32_t);
    00286
    00292     inline static Token pointerToken(void*);
    00293
    00309     typedef Transliterator* (U_EXPORT2 *Factory)(const UnicodeString& ID, Token context);
    00310
    00311 protected:
    00312
    00322     Transliterator(const UnicodeString& ID, UnicodeFilter* adoptedFilter);
    00323
    00328     Transliterator(const Transliterator&);
    00329
    00334     Transliterator& operator=(const Transliterator&);
    00335
    00347     static Transliterator* createBasicInstance(const UnicodeString& id,
    00348                                                const UnicodeString* canon);
    00349
    00350     friend class TransliteratorParser; // for parseID()
    00351     friend class TransliteratorIDParser; // for createBasicInstance()
    00352     friend class TransliteratorAlias; // for setID()
    00353
    00354 public:
    00355
    00360     virtual ~Transliterator();
    00361
    00376     virtual Transliterator* clone() const;
    00377
    00393     virtual int32_t transliterate(Replaceable& text,
    00394                                   int32_t start, int32_t limit) const;
    00395
    00401     virtual void transliterate(Replaceable& text) const;
    00402
    00467     virtual void transliterate(Replaceable& text, UTransPosition& index,
    00468                                const UnicodeString& insertion,
    00469                                UErrorCode& status) const;
    00470
    00486     virtual void transliterate(Replaceable& text, UTransPosition& index,
    00487                                UChar32 insertion,
    00488                                UErrorCode& status) const;
    00489
    00504     virtual void transliterate(Replaceable& text, UTransPosition& index,
    00505                                UErrorCode& status) const;
    00506
    00518     virtual void finishTransliteration(Replaceable& text,
    00519                                        UTransPosition& index) const;
    00520
    00521 private:
    00522
    00538     void _transliterate(Replaceable& text,
    00539                         UTransPosition& index,
    00540                         const UnicodeString* insertion,
    00541                         UErrorCode &status) const;
    00542
    00543 protected:
    00544
    00624     virtual void handleTransliterate(Replaceable& text,
    00625                                      UTransPosition& pos,
    00626                                      UBool incremental) const = 0;
    00627
    00628 public:
    00640     virtual void filteredTransliterate(Replaceable& text,
    00641                                        UTransPosition& index,
    00642                                        UBool incremental) const;
    00643
    00644 private:
    00645
    00673     virtual void filteredTransliterate(Replaceable& text,
    00674                                        UTransPosition& index,
    00675                                        UBool incremental,
    00676                                        UBool rollback) const;
    00677
    00678 public:
    00679
    00693     int32_t getMaximumContextLength(void) const;
    00694
    00695 protected:
    00696
    00703     void setMaximumContextLength(int32_t maxContextLength);
    00704
    00705 public:
    00706
    00717     virtual const UnicodeString& getID(void) const;
    00718
    00728     static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
    00729                                          UnicodeString& result);
    00730
    00752     static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
    00753                                          const Locale& inLocale,
    00754                                          UnicodeString& result);
    00755
    00763     const UnicodeFilter* getFilter(void) const;
    00764
    00774     UnicodeFilter* orphanFilter(void);
    00775
    00786     void adoptFilter(UnicodeFilter* adoptedFilter);
    00787
    00807     Transliterator* createInverse(UErrorCode& status) const;
    00808
    00825     static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
    00826                                           UTransDirection dir,
    00827                                           UParseError& parseError,
    00828                                           UErrorCode& status);
    00829
    00840     static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
    00841                                           UTransDirection dir,
    00842                                           UErrorCode& status);
    00843
    00859     static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
    00860                                            const UnicodeString& rules,
    00861                                            UTransDirection dir,
    00862                                            UParseError& parseError,
    00863                                            UErrorCode& status);
    00864
    00876     virtual UnicodeString& toRules(UnicodeString& result,
    00877                                    UBool escapeUnprintable) const;
    00878
    00891     int32_t countElements() const;
    00892
    00912     const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
    00913
    00929     UnicodeSet& getSourceSet(UnicodeSet& result) const;
    00930
    00945     virtual void handleGetSourceSet(UnicodeSet& result) const;
    00946
    00960     virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
    00961
    00962 public:
    00963
    00975     static void U_EXPORT2 registerFactory(const UnicodeString& id,
    00976                                 Factory factory,
    00977                                 Token context);
    00978
    00996     static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
    00997
    01012      static void U_EXPORT2 registerAlias(const UnicodeString& aliasID,
    01013                                          const UnicodeString& realID);
    01014
    01015 protected:
    01016
    01026     static void _registerFactory(const UnicodeString& id,
    01027                                  Factory factory,
    01028                                  Token context);
    01029
    01033     static void _registerInstance(Transliterator* adoptedObj);
    01034
    01038     static void _registerAlias(const UnicodeString& aliasID, const UnicodeString& realID);
    01039
    01073     static void _registerSpecialInverse(const UnicodeString& target,
    01074                                         const UnicodeString& inverseTarget,
    01075                                         UBool bidirectional);
    01076
    01077 public:
    01078
    01092     static void U_EXPORT2 unregister(const UnicodeString& ID);
    01093
    01094 public:
    01095
    01105     static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
    01106
    01112     static int32_t U_EXPORT2 countAvailableSources(void);
    01113
    01123     static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
    01124                                              UnicodeString& result);
    01125
    01134     static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
    01135
    01147     static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
    01148                                              const UnicodeString& source,
    01149                                              UnicodeString& result);
    01150
    01158     static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
    01159                                           const UnicodeString& target);
    01160
    01174     static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
    01175                                               const UnicodeString& source,
    01176                                               const UnicodeString& target,
    01177                                               UnicodeString& result);
    01178
    01179 protected:
    01180
    01185     static int32_t _countAvailableSources(void);
    01186
    01191     static UnicodeString& _getAvailableSource(int32_t index,
    01192                                               UnicodeString& result);
    01193
    01198     static int32_t _countAvailableTargets(const UnicodeString& source);
    01199
    01204     static UnicodeString& _getAvailableTarget(int32_t index,
    01205                                               const UnicodeString& source,
    01206                                               UnicodeString& result);
    01207
    01212     static int32_t _countAvailableVariants(const UnicodeString& source,
    01213                                            const UnicodeString& target);
    01214
    01219     static UnicodeString& _getAvailableVariant(int32_t index,
    01220                                                const UnicodeString& source,
    01221                                                const UnicodeString& target,
    01222                                                UnicodeString& result);
    01223
    01224 protected:
    01225
    01232     void setID(const UnicodeString& id);
    01233
    01234 public:
    01235
    01246     static UClassID U_EXPORT2 getStaticClassID(void);
    01247
    01263     virtual UClassID getDynamicClassID(void) const = 0;
    01264
    01265 private:
    01266     static UBool initializeRegistry(UErrorCode &status);
    01267
    01268 public:
    01276     static int32_t U_EXPORT2 countAvailableIDs(void);
    01277
    01290     static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
    01291 };
    01292
    01293 inline int32_t Transliterator::getMaximumContextLength(void) const {
    01294     return maximumContextLength;
    01295 }
    01296
    01297 inline void Transliterator::setID(const UnicodeString& id) {
    01298     ID = id;
    01299     // NUL-terminate the ID string, which is a non-aliased copy.
    01300     ID.append((UChar)0);
    01301     ID.truncate(ID.length()-1);
    01302 }
    01303
    01304 inline Transliterator::Token Transliterator::integerToken(int32_t i) {
    01305     Token t;
    01306     t.integer = i;
    01307     return t;
    01308 }
    01309
    01310 inline Transliterator::Token Transliterator::pointerToken(void* p) {
    01311     Token t;
    01312     t.pointer = p;
    01313     return t;
    01314 }
    01315
    01316 U_NAMESPACE_END
    01317
    01318 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
    01319
    01320 #endif