ICU 78.1 78.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
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() const;
942
943 protected:
944
951 void setMaximumContextLength(int32_t maxContextLength);
952
953 public:
954
965 virtual const UnicodeString& getID() 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() const;
1012
1022 UnicodeFilter* orphanFilter();
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
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();
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
1451 static int32_t _countAvailableSources();
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();
1514
1530 virtual UClassID getDynamicClassID() const override = 0;
1531
1532 private:
1533 static UBool initializeRegistry(UErrorCode &status);
1534
1535 public:
1536 #ifndef U_HIDE_OBSOLETE_API
1544 static int32_t U_EXPORT2 countAvailableIDs();
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() 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(static_cast<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
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
icu::Replaceable
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:77
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::Transliterator
Transliterator is an abstract class that transliterates text from one format to another.
Definition: translit.h:490
icu::Transliterator::getDisplayName
static UnicodeString & getDisplayName(const UnicodeString &ID, const Locale &inLocale, UnicodeString &result)
Returns a name for this transliterator that is appropriate for display to the user in the given local...
icu::Transliterator::createFromRules
static Transliterator * createFromRules(const UnicodeString &ID, const UnicodeString &rules, UTransDirection dir, UParseError &parseError, UErrorCode &status)
Returns a Transliterator object constructed from the given rule string.
icu::Transliterator::getAvailableTarget
static UnicodeString & getAvailableTarget(int32_t index, const UnicodeString &source, UnicodeString &result)
Return a registered target specifier for a given source.
icu::Transliterator::transliterate
virtual void transliterate(Replaceable &text) const
Transliterates an entire string in place.
icu::Transliterator::getSourceSet
UnicodeSet & getSourceSet(UnicodeSet &result) const
Returns the set of all characters that may be modified in the input text by this Transliterator.
icu::Transliterator::adoptFilter
void adoptFilter(UnicodeFilter *adoptedFilter)
Changes the filter used by this transliterator.
icu::Transliterator::_getAvailableSource
static UnicodeString & _getAvailableSource(int32_t index, UnicodeString &result)
Non-mutexed internal method.
icu::Transliterator::Factory
Transliterator *(* Factory)(const UnicodeString &ID, Token context)
A function that creates and returns a Transliterator.
Definition: translit.h:560
icu::Transliterator::toRules
virtual UnicodeString & toRules(UnicodeString &result, UBool escapeUnprintable) const
Create a rule string that can be passed to createFromRules() to recreate this transliterator.
icu::Transliterator::createInstance
static Transliterator * createInstance(const UnicodeString &ID, UTransDirection dir, UErrorCode &status)
Returns a Transliterator object given its ID.
icu::Transliterator::_getAvailableTarget
static UnicodeString & _getAvailableTarget(int32_t index, const UnicodeString &source, UnicodeString &result)
Non-mutexed internal method.
icu::Transliterator::_registerAlias
static void _registerAlias(const UnicodeString &aliasID, const UnicodeString &realID)
icu::Transliterator::getDynamicClassID
virtual UClassID getDynamicClassID() const override=0
Returns a unique class ID polymorphically.
icu::Transliterator::getAvailableSource
static UnicodeString & getAvailableSource(int32_t index, UnicodeString &result)
Return a registered source specifier.
icu::Transliterator::countAvailableIDs
static int32_t countAvailableIDs()
Return the number of IDs currently registered with the system.
icu::Transliterator::unregister
static void unregister(const UnicodeString &ID)
Unregisters a transliterator or class.
icu::Transliterator::transliterate
virtual int32_t transliterate(Replaceable &text, int32_t start, int32_t limit) const
Transliterates a segment of a string, with optional filtering.
icu::Transliterator::createInverse
Transliterator * createInverse(UErrorCode &status) const
Returns this transliterator's inverse.
icu::Transliterator::handleGetSourceSet
virtual void handleGetSourceSet(UnicodeSet &result) const
Framework method that returns the set of all characters that may be modified in the input text by thi...
icu::Transliterator::orphanFilter
UnicodeFilter * orphanFilter()
Returns the filter used by this transliterator, or nullptr if this transliterator uses no filter.
icu::Transliterator::createBasicInstance
static Transliterator * createBasicInstance(const UnicodeString &id, const UnicodeString *canon)
Create a transliterator from a basic ID.
icu::Transliterator::~Transliterator
virtual ~Transliterator()
Destructor.
icu::Transliterator::registerAlias
static void registerAlias(const UnicodeString &aliasID, const UnicodeString &realID)
Registers an ID string as an alias of another ID string.
icu::Transliterator::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::Transliterator::countAvailableVariants
static int32_t countAvailableVariants(const UnicodeString &source, const UnicodeString &target)
Return the number of registered variant specifiers for a given source-target pair.
icu::Transliterator::getElement
const Transliterator & getElement(int32_t index, UErrorCode &ec) const
Return an element that makes up this transliterator.
icu::Transliterator::getAvailableID
static const UnicodeString & getAvailableID(int32_t index)
Return the index-th available ID.
icu::Transliterator::transliterate
virtual void transliterate(Replaceable &text, UTransPosition &index, UErrorCode &status) const
Transliterates the portion of the text buffer that can be transliterated unambiguosly.
icu::Transliterator::_countAvailableSources
static int32_t _countAvailableSources()
Non-mutexed internal method.
icu::Transliterator::operator=
Transliterator & operator=(const Transliterator &)
Assignment operator.
icu::Transliterator::handleTransliterate
virtual void handleTransliterate(Replaceable &text, UTransPosition &pos, UBool incremental) const =0
Abstract method that concrete subclasses define to implement their transliteration algorithm.
icu::Transliterator::getAvailableVariant
static UnicodeString & getAvailableVariant(int32_t index, const UnicodeString &source, const UnicodeString &target, UnicodeString &result)
Return a registered variant specifier for a given source-target pair.
icu::Transliterator::filteredTransliterate
virtual void filteredTransliterate(Replaceable &text, UTransPosition &index, UBool incremental) const
Transliterate a substring of text, as specified by index, taking filters into account.
icu::Transliterator::getID
virtual const UnicodeString & getID() const
Returns a programmatic identifier for this transliterator.
icu::Transliterator::getFilter
const UnicodeFilter * getFilter() const
Returns the filter used by this transliterator, or nullptr if this transliterator uses no filter.
icu::Transliterator::_registerSpecialInverse
static void _registerSpecialInverse(const UnicodeString &target, const UnicodeString &inverseTarget, UBool bidirectional)
Register two targets as being inverses of one another.
icu::Transliterator::_countAvailableTargets
static int32_t _countAvailableTargets(const UnicodeString &source)
Non-mutexed internal method.
icu::Transliterator::transliterate
virtual void transliterate(Replaceable &text, UTransPosition &index, const UnicodeString &insertion, UErrorCode &status) const
Transliterates the portion of the text buffer that can be transliterated unambiguosly after new text ...
icu::Transliterator::countAvailableTargets
static int32_t countAvailableTargets(const UnicodeString &source)
Return the number of registered target specifiers for a given source specifier.
icu::Transliterator::Transliterator
Transliterator(const UnicodeString &ID, UnicodeFilter *adoptedFilter)
Default constructor.
icu::Transliterator::Transliterator
Transliterator(const Transliterator &)
Copy constructor.
icu::Transliterator::getDisplayName
static UnicodeString & getDisplayName(const UnicodeString &ID, UnicodeString &result)
Returns a name for this transliterator that is appropriate for display to the user in the default loc...
icu::Transliterator::registerFactory
static void registerFactory(const UnicodeString &id, Factory factory, Token context)
Registers a factory function that creates transliterators of a given ID.
icu::Transliterator::setMaximumContextLength
void setMaximumContextLength(int32_t maxContextLength)
Method for subclasses to use to set the maximum context length.
icu::Transliterator::createInstance
static Transliterator * createInstance(const UnicodeString &ID, UTransDirection dir, UParseError &parseError, UErrorCode &status)
Returns a Transliterator object given its ID.
icu::Transliterator::getAvailableIDs
static StringEnumeration * getAvailableIDs(UErrorCode &ec)
Return a StringEnumeration over the IDs available at the time of the call, including user-registered ...
icu::Transliterator::getTargetSet
virtual UnicodeSet & getTargetSet(UnicodeSet &result) const
Returns the set of all characters that may be generated as replacement text by this transliterator.
icu::Transliterator::_registerFactory
static void _registerFactory(const UnicodeString &id, Factory factory, Token context)
icu::Transliterator::registerInstance
static void registerInstance(Transliterator *adoptedObj)
Registers an instance obj of a subclass of Transliterator with the system.
icu::Transliterator::countElements
int32_t countElements() const
Return the number of elements that make up this transliterator.
icu::Transliterator::_getAvailableVariant
static UnicodeString & _getAvailableVariant(int32_t index, const UnicodeString &source, const UnicodeString &target, UnicodeString &result)
Non-mutexed internal method.
icu::Transliterator::finishTransliteration
virtual void finishTransliteration(Replaceable &text, UTransPosition &index) const
Finishes any pending transliterations that were waiting for more characters.
icu::Transliterator::countAvailableSources
static int32_t countAvailableSources()
Return the number of registered source specifiers.
icu::Transliterator::clone
virtual Transliterator * clone() const
Implements Cloneable.
icu::Transliterator::transliterate
virtual void transliterate(Replaceable &text, UTransPosition &index, UChar32 insertion, UErrorCode &status) const
Transliterates the portion of the text buffer that can be transliterated unambiguosly after a new cha...
icu::Transliterator::_registerInstance
static void _registerInstance(Transliterator *adoptedObj)
icu::Transliterator::_countAvailableVariants
static int32_t _countAvailableVariants(const UnicodeString &source, const UnicodeString &target)
Non-mutexed internal method.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
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::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:285
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
icu::UnicodeString::truncate
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
Definition: unistr.h:5127
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:5019
parseerr.h
C API: Parse Error Information.
strenum.h
C++ API: String Enumeration.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
UTransPosition
Position structure for utrans_transIncremental() incremental transliteration.
Definition: utrans.h:125
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:449
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::Transliterator::Token
A context integer or pointer for a factory function, passed by value.
Definition: translit.h:516
icu::Transliterator::Token::pointer
void * pointer
This token, interpreted as a native pointer.
Definition: translit.h:526
icu::Transliterator::Token::integer
int32_t integer
This token, interpreted as a 32-bit integer.
Definition: translit.h:521
unistr.h
C++ API: Unicode String.
uobject.h
C++ API: Common ICU base class UObject.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utrans.h
C API: Transliterator.
UTransDirection
UTransDirection
Direction constant indicating the direction in a transliterator, e.g., the forward or reverse rules o...
Definition: utrans.h:83
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316