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

- Search for |

- File List
- Globals

# translit.h

Go to the documentation of this file.

    00001 /*
    00002 **********************************************************************
    00003 * Copyright (C) 1999-2007, 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
    00489     virtual void transliterate(Replaceable& text, UTransPosition& index,
    00490                                UChar32 insertion,
    00491                                UErrorCode& status) const;
    00492
    00507     virtual void transliterate(Replaceable& text, UTransPosition& index,
    00508                                UErrorCode& status) const;
    00509
    00521     virtual void finishTransliteration(Replaceable& text,
    00522                                        UTransPosition& index) const;
    00523
    00524 private:
    00525
    00541     void _transliterate(Replaceable& text,
    00542                         UTransPosition& index,
    00543                         const UnicodeString* insertion,
    00544                         UErrorCode &status) const;
    00545
    00546 protected:
    00547
    00627     virtual void handleTransliterate(Replaceable& text,
    00628                                      UTransPosition& pos,
    00629                                      UBool incremental) const = 0;
    00630
    00631 public:
    00643     virtual void filteredTransliterate(Replaceable& text,
    00644                                        UTransPosition& index,
    00645                                        UBool incremental) const;
    00646
    00647 private:
    00648
    00676     virtual void filteredTransliterate(Replaceable& text,
    00677                                        UTransPosition& index,
    00678                                        UBool incremental,
    00679                                        UBool rollback) const;
    00680
    00681 public:
    00682
    00696     int32_t getMaximumContextLength(void) const;
    00697
    00698 protected:
    00699
    00706     void setMaximumContextLength(int32_t maxContextLength);
    00707
    00708 public:
    00709
    00720     virtual const UnicodeString& getID(void) const;
    00721
    00731     static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
    00732                                          UnicodeString& result);
    00733
    00755     static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
    00756                                          const Locale& inLocale,
    00757                                          UnicodeString& result);
    00758
    00766     const UnicodeFilter* getFilter(void) const;
    00767
    00777     UnicodeFilter* orphanFilter(void);
    00778
    00789     void adoptFilter(UnicodeFilter* adoptedFilter);
    00790
    00810     Transliterator* createInverse(UErrorCode& status) const;
    00811
    00828     static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
    00829                                           UTransDirection dir,
    00830                                           UParseError& parseError,
    00831                                           UErrorCode& status);
    00832
    00843     static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
    00844                                           UTransDirection dir,
    00845                                           UErrorCode& status);
    00846
    00862     static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
    00863                                            const UnicodeString& rules,
    00864                                            UTransDirection dir,
    00865                                            UParseError& parseError,
    00866                                            UErrorCode& status);
    00867
    00879     virtual UnicodeString& toRules(UnicodeString& result,
    00880                                    UBool escapeUnprintable) const;
    00881
    00894     int32_t countElements() const;
    00895
    00915     const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
    00916
    00932     UnicodeSet& getSourceSet(UnicodeSet& result) const;
    00933
    00948     virtual void handleGetSourceSet(UnicodeSet& result) const;
    00949
    00963     virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
    00964
    00965 public:
    00966
    00978     static void U_EXPORT2 registerFactory(const UnicodeString& id,
    00979                                 Factory factory,
    00980                                 Token context);
    00981
    00999     static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
    01000
    01015      static void U_EXPORT2 registerAlias(const UnicodeString& aliasID,
    01016                                          const UnicodeString& realID);
    01017
    01018 protected:
    01019
    01029     static void _registerFactory(const UnicodeString& id,
    01030                                  Factory factory,
    01031                                  Token context);
    01032
    01036     static void _registerInstance(Transliterator* adoptedObj);
    01037
    01041     static void _registerAlias(const UnicodeString& aliasID, const UnicodeString& realID);
    01042
    01076     static void _registerSpecialInverse(const UnicodeString& target,
    01077                                         const UnicodeString& inverseTarget,
    01078                                         UBool bidirectional);
    01079
    01080 public:
    01081
    01095     static void U_EXPORT2 unregister(const UnicodeString& ID);
    01096
    01097 public:
    01098
    01108     static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
    01109
    01115     static int32_t U_EXPORT2 countAvailableSources(void);
    01116
    01126     static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
    01127                                              UnicodeString& result);
    01128
    01137     static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
    01138
    01150     static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
    01151                                              const UnicodeString& source,
    01152                                              UnicodeString& result);
    01153
    01161     static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
    01162                                           const UnicodeString& target);
    01163
    01177     static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
    01178                                               const UnicodeString& source,
    01179                                               const UnicodeString& target,
    01180                                               UnicodeString& result);
    01181
    01182 protected:
    01183
    01188     static int32_t _countAvailableSources(void);
    01189
    01194     static UnicodeString& _getAvailableSource(int32_t index,
    01195                                               UnicodeString& result);
    01196
    01201     static int32_t _countAvailableTargets(const UnicodeString& source);
    01202
    01207     static UnicodeString& _getAvailableTarget(int32_t index,
    01208                                               const UnicodeString& source,
    01209                                               UnicodeString& result);
    01210
    01215     static int32_t _countAvailableVariants(const UnicodeString& source,
    01216                                            const UnicodeString& target);
    01217
    01222     static UnicodeString& _getAvailableVariant(int32_t index,
    01223                                                const UnicodeString& source,
    01224                                                const UnicodeString& target,
    01225                                                UnicodeString& result);
    01226
    01227 protected:
    01228
    01235     void setID(const UnicodeString& id);
    01236
    01237 public:
    01238
    01249     static UClassID U_EXPORT2 getStaticClassID(void);
    01250
    01266     virtual UClassID getDynamicClassID(void) const = 0;
    01267
    01268 private:
    01269     static UBool initializeRegistry(void);
    01270
    01271 public:
    01279     static int32_t U_EXPORT2 countAvailableIDs(void);
    01280
    01293     static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
    01294 };
    01295
    01296 inline int32_t Transliterator::getMaximumContextLength(void) const {
    01297     return maximumContextLength;
    01298 }
    01299
    01300 inline void Transliterator::setID(const UnicodeString& id) {
    01301     ID = id;
    01302     // NUL-terminate the ID string, which is a non-aliased copy.
    01303     ID.append((UChar)0);
    01304     ID.truncate(ID.length()-1);
    01305 }
    01306
    01307 inline Transliterator::Token Transliterator::integerToken(int32_t i) {
    01308     Token t;
    01309     t.integer = i;
    01310     return t;
    01311 }
    01312
    01313 inline Transliterator::Token Transliterator::pointerToken(void* p) {
    01314     Token t;
    01315     t.pointer = p;
    01316     return t;
    01317 }
    01318
    01319 U_NAMESPACE_END
    01320
    01321 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
    01322
    01323 #endif