ICU 69.1 69.1

translit.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (C) 1999-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 * Date Name Description
9 * 11/17/99 aliu Creation.
10 **********************************************************************
11 */
12 #ifndef TRANSLIT_H
13 #define TRANSLIT_H
14
15 #include "unicode/utypes.h"
16
17 #if U_SHOW_CPLUSPLUS_API
18
24 #if !UCONFIG_NO_TRANSLITERATION
25
26 #include "unicode/uobject.h"
27 #include "unicode/unistr.h"
28 #include "unicode/parseerr.h"
29 #include "unicode/utrans.h" // UTransPosition, UTransDirection
30 #include "unicode/strenum.h"
31
32 U_NAMESPACE_BEGIN
33
34 class UnicodeFilter;
35 class UnicodeSet;
36 class TransliteratorParser;
37 class NormalizationTransliterator;
38 class TransliteratorIDParser;
39
490 class U_I18N_API Transliterator : public UObject {
491
492 private:
493
497 UnicodeString ID;
498
505 UnicodeFilter* filter;
506
507 int32_t maximumContextLength;
508
509 public:
510
516 union Token {
521 int32_t integer;
526 void* pointer;
527 };
528
529 #ifndef U_HIDE_INTERNAL_API
530
535 inline static Token integerToken(int32_t);
536
542 inline static Token pointerToken(void*);
543 #endif /* U_HIDE_INTERNAL_API */
544
560 typedef Transliterator* (U_EXPORT2 *Factory)(const UnicodeString& ID, Token context);
561
562 protected:
563
573 Transliterator(const UnicodeString& ID, UnicodeFilter* adoptedFilter);
574
579 Transliterator(const Transliterator&);
580
585 Transliterator& operator=(const Transliterator&);
586
598 static Transliterator* createBasicInstance(const UnicodeString& id,
599 const UnicodeString* canon);
600
601 friend class TransliteratorParser; // for parseID()
602 friend class TransliteratorIDParser; // for createBasicInstance()
603 friend class TransliteratorAlias; // for setID()
604
605 public:
606
611 virtual ~Transliterator();
612
627 virtual Transliterator* clone() const;
628
644 virtual int32_t transliterate(Replaceable& text,
645 int32_t start, int32_t limit) const;
646
652 virtual void transliterate(Replaceable& text) const;
653
718 virtual void transliterate(Replaceable& text, UTransPosition& index,
719 const UnicodeString& insertion,
720 UErrorCode& status) const;
721
737 virtual void transliterate(Replaceable& text, UTransPosition& index,
738 UChar32 insertion,
739 UErrorCode& status) const;
740
753 virtual void transliterate(Replaceable& text, UTransPosition& index,
754 UErrorCode& status) const;
755
766 virtual void finishTransliteration(Replaceable& text,
767 UTransPosition& index) const;
768
769 private:
770
786 void _transliterate(Replaceable& text,
787 UTransPosition& index,
788 const UnicodeString* insertion,
789 UErrorCode &status) const;
790
791 protected:
792
872 virtual void handleTransliterate(Replaceable& text,
873 UTransPosition& pos,
874 UBool incremental) const = 0;
875
876 public:
888 virtual void filteredTransliterate(Replaceable& text,
889 UTransPosition& index,
890 UBool incremental) const;
891
892 private:
893
921 virtual void filteredTransliterate(Replaceable& text,
922 UTransPosition& index,
923 UBool incremental,
924 UBool rollback) const;
925
926 public:
927
941 int32_t getMaximumContextLength(void) const;
942
943 protected:
944
951 void setMaximumContextLength(int32_t maxContextLength);
952
953 public:
954
965 virtual const UnicodeString& getID(void) const;
966
976 static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
977 UnicodeString& result);
978
1000 static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
1001 const Locale& inLocale,
1002 UnicodeString& result);
1003
1011 const UnicodeFilter* getFilter(void) const;
1012
1022 UnicodeFilter* orphanFilter(void);
1023
1034 void adoptFilter(UnicodeFilter* adoptedFilter);
1035
1055 Transliterator* createInverse(UErrorCode& status) const;
1056
1073 static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
1074 UTransDirection dir,
1075 UParseError& parseError,
1076 UErrorCode& status);
1077
1088 static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
1089 UTransDirection dir,
1090 UErrorCode& status);
1091
1109 static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
1110 const UnicodeString& rules,
1111 UTransDirection dir,
1112 UParseError& parseError,
1113 UErrorCode& status);
1114
1126 virtual UnicodeString& toRules(UnicodeString& result,
1127 UBool escapeUnprintable) const;
1128
1141 int32_t countElements() const;
1142
1162 const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
1163
1179 UnicodeSet& getSourceSet(UnicodeSet& result) const;
1180
1195 virtual void handleGetSourceSet(UnicodeSet& result) const;
1196
1210 virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
1211
1212 public:
1213
1230 static void U_EXPORT2 registerFactory(const UnicodeString& id,
1231 Factory factory,
1232 Token context);
1233
1255 static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
1256
1271 static void U_EXPORT2 registerAlias(const UnicodeString& aliasID,
1272 const UnicodeString& realID);
1273
1274 protected:
1275
1276 #ifndef U_HIDE_INTERNAL_API
1277
1286 static void _registerFactory(const UnicodeString& id,
1287 Factory factory,
1288 Token context);
1289
1293 static void _registerInstance(Transliterator* adoptedObj);
1294
1298 static void _registerAlias(const UnicodeString& aliasID, const UnicodeString& realID);
1299
1333 static void _registerSpecialInverse(const UnicodeString& target,
1334 const UnicodeString& inverseTarget,
1335 UBool bidirectional);
1336 #endif /* U_HIDE_INTERNAL_API */
1337
1338 public:
1339
1357 static void U_EXPORT2 unregister(const UnicodeString& ID);
1358
1359 public:
1360
1370 static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
1371
1377 static int32_t U_EXPORT2 countAvailableSources(void);
1378
1388 static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
1389 UnicodeString& result);
1390
1399 static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
1400
1412 static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
1413 const UnicodeString& source,
1414 UnicodeString& result);
1415
1423 static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
1424 const UnicodeString& target);
1425
1439 static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
1440 const UnicodeString& source,
1441 const UnicodeString& target,
1442 UnicodeString& result);
1443
1444 protected:
1445
1446 #ifndef U_HIDE_INTERNAL_API
1447
1451 static int32_t _countAvailableSources(void);
1452
1457 static UnicodeString& _getAvailableSource(int32_t index,
1458 UnicodeString& result);
1459
1464 static int32_t _countAvailableTargets(const UnicodeString& source);
1465
1470 static UnicodeString& _getAvailableTarget(int32_t index,
1471 const UnicodeString& source,
1472 UnicodeString& result);
1473
1478 static int32_t _countAvailableVariants(const UnicodeString& source,
1479 const UnicodeString& target);
1480
1485 static UnicodeString& _getAvailableVariant(int32_t index,
1486 const UnicodeString& source,
1487 const UnicodeString& target,
1488 UnicodeString& result);
1489 #endif /* U_HIDE_INTERNAL_API */
1490
1491 protected:
1492
1499 void setID(const UnicodeString& id);
1500
1501 public:
1502
1513 static UClassID U_EXPORT2 getStaticClassID(void);
1514
1530 virtual UClassID getDynamicClassID(void) const = 0;
1531
1532 private:
1533 static UBool initializeRegistry(UErrorCode &status);
1534
1535 public:
1536 #ifndef U_HIDE_OBSOLETE_API
1537
1544 static int32_t U_EXPORT2 countAvailableIDs(void);
1545
1558 static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
1559 #endif /* U_HIDE_OBSOLETE_API */
1560 };
1561
1562 inline int32_t Transliterator::getMaximumContextLength(void) const {
1563 return maximumContextLength;
1564 }
1565
1566 inline void Transliterator::setID(const UnicodeString& id) {
1567 ID = id;
1568 // NUL-terminate the ID string, which is a non-aliased copy.
1569 ID.append((char16_t)0);
1570 ID.truncate(ID.length()-1);
1571 }
1572
1573 #ifndef U_HIDE_INTERNAL_API
1574 inline Transliterator::Token Transliterator::integerToken(int32_t i) {
1575 Token t;
1576 t.integer = i;
1577 return t;
1578 }
1579
1580 inline Transliterator::Token Transliterator::pointerToken(void* p) {
1581 Token t;
1582 t.pointer = p;
1583 return t;
1584 }
1585 #endif /* U_HIDE_INTERNAL_API */
1586
1587 U_NAMESPACE_END
1588
1589 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
1590
1591 #endif /* U_SHOW_CPLUSPLUS_API */
1592
1593 #endif
UTransPosition
Position structure for utrans_transIncremental() incremental transliteration.
Definition: utrans.h:125
icu::Transliterator::Token::integer
int32_t integer
This token, interpreted as a 32-bit integer.
Definition: translit.h:521
parseerr.h
C API: Parse Error Information.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Transliterator::Token::pointer
void * pointer
This token, interpreted as a native pointer.
Definition: translit.h:526
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:279
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::Replaceable
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:77
icu::UnicodeString::append
UnicodeString & append(const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Append the characters in srcText in the range [srcStart, srcStart + srcLength) to the UnicodeString o...
Definition: unistr.h:4622
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:467
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::Transliterator::Token
A context integer or pointer for a factory function, passed by value.
Definition: translit.h:516
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UTransDirection
UTransDirection
Direction constant indicating the direction in a transliterator, e.g., the forward or reverse rules o...
Definition: utrans.h:83
icu::Transliterator::Factory
Transliterator *(* Factory)(const UnicodeString &ID, Token context)
A function that creates and returns a Transliterator.
Definition: translit.h:560
icu::Transliterator
Transliterator is an abstract class that transliterates text from one format to another.
Definition: translit.h:490
strenum.h
C++ API: String Enumeration.
utrans.h
C API: Transliterator.
icu::UnicodeString::truncate
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
Definition: unistr.h:4730
uobject.h
C++ API: Common ICU base class UObject.
icu::UnicodeFilter
UnicodeFilter defines a protocol for selecting a subset of the full range (U+0000 to U+10FFFF) of Uni...
Definition: unifilt.h:65
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
unistr.h
C++ API: Unicode String.