ICU 76.1 76.1
Loading...
Searching...
No Matches
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
32U_NAMESPACE_BEGIN
33
34class UnicodeFilter;
35class UnicodeSet;
36class TransliteratorParser;
37class NormalizationTransliterator;
38class TransliteratorIDParser;
39
491
492private:
493
497 UnicodeString ID;
498
505 UnicodeFilter* filter;
506
507 int32_t maximumContextLength;
508
509 public:
510
516 union Token {
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
562protected:
563
574
580
586
599 const UnicodeString* canon);
600
601 friend class TransliteratorParser; // for parseID()
602 friend class TransliteratorIDParser; // for createBasicInstance()
603 friend class TransliteratorAlias; // for setID()
604
605public:
606
612
627 virtual Transliterator* clone() const;
628
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,
720 UErrorCode& status) const;
721
737 virtual void transliterate(Replaceable& text, UTransPosition& index,
739 UErrorCode& status) const;
740
753 virtual void transliterate(Replaceable& text, UTransPosition& index,
754 UErrorCode& status) const;
755
767 UTransPosition& index) const;
768
769private:
770
786 void _transliterate(Replaceable& text,
787 UTransPosition& index,
789 UErrorCode &status) const;
790
791protected:
792
873 UTransPosition& pos,
874 UBool incremental) const = 0;
875
876public:
889 UTransPosition& index,
890 UBool incremental) const;
891
892private:
893
921 virtual void filteredTransliterate(Replaceable& text,
922 UTransPosition& index,
924 UBool rollback) const;
925
926public:
927
941 int32_t getMaximumContextLength() const;
942
943protected:
944
952
953public:
954
965 virtual const UnicodeString& getID() const;
966
978
1001 const Locale& inLocale,
1003
1011 const UnicodeFilter* getFilter() const;
1012
1023
1035
1056
1074 UTransDirection dir,
1077
1089 UTransDirection dir,
1091
1110 const UnicodeString& rules,
1111 UTransDirection dir,
1114
1127 UBool escapeUnprintable) const;
1128
1142
1163
1180
1196
1211
1212public:
1213
1231 Factory factory,
1232 Token context);
1233
1256
1272 const UnicodeString& realID);
1273
1274protected:
1275
1276#ifndef U_HIDE_INTERNAL_API
1286 static void _registerFactory(const UnicodeString& id,
1287 Factory factory,
1288 Token context);
1289
1294
1299
1333 static void _registerSpecialInverse(const UnicodeString& target,
1336#endif /* U_HIDE_INTERNAL_API */
1337
1338public:
1339
1357 static void U_EXPORT2 unregister(const UnicodeString& ID);
1358
1359public:
1360
1371
1378
1390
1400
1413 const UnicodeString& source,
1415
1424 const UnicodeString& target);
1425
1440 const UnicodeString& source,
1441 const UnicodeString& target,
1443
1444protected:
1445
1446#ifndef U_HIDE_INTERNAL_API
1452
1459
1465
1471 const UnicodeString& source,
1473
1479 const UnicodeString& target);
1480
1486 const UnicodeString& source,
1487 const UnicodeString& target,
1489#endif /* U_HIDE_INTERNAL_API */
1490
1491protected:
1492
1499 void setID(const UnicodeString& id);
1500
1501public:
1502
1514
1530 virtual UClassID getDynamicClassID() const override = 0;
1531
1532private:
1533 static UBool initializeRegistry(UErrorCode &status);
1534
1535public:
1536#ifndef U_HIDE_OBSOLETE_API
1545
1559#endif /* U_HIDE_OBSOLETE_API */
1560};
1561
1562inline int32_t Transliterator::getMaximumContextLength() const {
1563 return maximumContextLength;
1564}
1565
1566inline 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
1574inline Transliterator::Token Transliterator::integerToken(int32_t i) {
1575 Token t;
1576 t.integer = i;
1577 return t;
1578}
1579
1580inline Transliterator::Token Transliterator::pointerToken(void* p) {
1581 Token t;
1582 t.pointer = p;
1583 return t;
1584}
1585#endif /* U_HIDE_INTERNAL_API */
1586
1588
1589#endif /* #if !UCONFIG_NO_TRANSLITERATION */
1590
1591#endif /* U_SHOW_CPLUSPLUS_API */
1592
1593#endif
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition rep.h:77
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:61
Transliterator is an abstract class that transliterates text from one format to another.
Definition translit.h:490
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.
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.
virtual void transliterate(Replaceable &text) const
Transliterates an entire string in place.
const Transliterator & getElement(int32_t index, UErrorCode &ec) const
Return an element that makes up this transliterator.
void adoptFilter(UnicodeFilter *adoptedFilter)
Changes the filter used by this transliterator.
static UnicodeString & _getAvailableVariant(int32_t index, const UnicodeString &source, const UnicodeString &target, UnicodeString &result)
Non-mutexed internal method.
static void _registerAlias(const UnicodeString &aliasID, const UnicodeString &realID)
virtual UClassID getDynamicClassID() const override=0
Returns a unique class ID polymorphically.
static int32_t countAvailableIDs()
Return the number of IDs currently registered with the system.
static void unregister(const UnicodeString &ID)
Unregisters a transliterator or class.
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...
virtual const UnicodeString & getID() const
Returns a programmatic identifier for this transliterator.
virtual int32_t transliterate(Replaceable &text, int32_t start, int32_t limit) const
Transliterates a segment of a string, with optional filtering.
Transliterator & operator=(const Transliterator &)
Assignment operator.
virtual UnicodeSet & getTargetSet(UnicodeSet &result) const
Returns the set of all characters that may be generated as replacement text by this transliterator.
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...
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...
Transliterator * createInverse(UErrorCode &status) const
Returns this transliterator's inverse.
UnicodeFilter * orphanFilter()
Returns the filter used by this transliterator, or nullptr if this transliterator uses no filter.
static UnicodeString & getAvailableSource(int32_t index, UnicodeString &result)
Return a registered source specifier.
static Transliterator * createInstance(const UnicodeString &ID, UTransDirection dir, UErrorCode &status)
Returns a Transliterator object given its ID.
virtual ~Transliterator()
Destructor.
static void registerAlias(const UnicodeString &aliasID, const UnicodeString &realID)
Registers an ID string as an alias of another ID string.
static UClassID getStaticClassID()
Return the class ID for this class.
static int32_t countAvailableVariants(const UnicodeString &source, const UnicodeString &target)
Return the number of registered variant specifiers for a given source-target pair.
static Transliterator * createBasicInstance(const UnicodeString &id, const UnicodeString *canon)
Create a transliterator from a basic ID.
virtual void transliterate(Replaceable &text, UTransPosition &index, UErrorCode &status) const
Transliterates the portion of the text buffer that can be transliterated unambiguosly.
static int32_t _countAvailableSources()
Non-mutexed internal method.
const UnicodeFilter * getFilter() const
Returns the filter used by this transliterator, or nullptr if this transliterator uses no filter.
virtual Transliterator * clone() const
Implements Cloneable.
virtual void handleTransliterate(Replaceable &text, UTransPosition &pos, UBool incremental) const =0
Abstract method that concrete subclasses define to implement their transliteration algorithm.
virtual void filteredTransliterate(Replaceable &text, UTransPosition &index, UBool incremental) const
Transliterate a substring of text, as specified by index, taking filters into account.
Transliterator *(* Factory)(const UnicodeString &ID, Token context)
A function that creates and returns a Transliterator.
Definition translit.h:560
static UnicodeString & _getAvailableTarget(int32_t index, const UnicodeString &source, UnicodeString &result)
Non-mutexed internal method.
static UnicodeString & getAvailableTarget(int32_t index, const UnicodeString &source, UnicodeString &result)
Return a registered target specifier for a given source.
static void _registerSpecialInverse(const UnicodeString &target, const UnicodeString &inverseTarget, UBool bidirectional)
Register two targets as being inverses of one another.
UnicodeSet & getSourceSet(UnicodeSet &result) const
Returns the set of all characters that may be modified in the input text by this Transliterator.
static int32_t _countAvailableTargets(const UnicodeString &source)
Non-mutexed internal method.
virtual UnicodeString & toRules(UnicodeString &result, UBool escapeUnprintable) const
Create a rule string that can be passed to createFromRules() to recreate this transliterator.
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 ...
static int32_t countAvailableTargets(const UnicodeString &source)
Return the number of registered target specifiers for a given source specifier.
Transliterator(const UnicodeString &ID, UnicodeFilter *adoptedFilter)
Default constructor.
Transliterator(const Transliterator &)
Copy constructor.
static void registerFactory(const UnicodeString &id, Factory factory, Token context)
Registers a factory function that creates transliterators of a given ID.
static UnicodeString & _getAvailableSource(int32_t index, UnicodeString &result)
Non-mutexed internal method.
void setMaximumContextLength(int32_t maxContextLength)
Method for subclasses to use to set the maximum context length.
static const UnicodeString & getAvailableID(int32_t index)
Return the index-th available ID.
static Transliterator * createInstance(const UnicodeString &ID, UTransDirection dir, UParseError &parseError, UErrorCode &status)
Returns a Transliterator object given its ID.
static void _registerFactory(const UnicodeString &id, Factory factory, Token context)
static void registerInstance(Transliterator *adoptedObj)
Registers an instance obj of a subclass of Transliterator with the system.
int32_t countElements() const
Return the number of elements that make up this transliterator.
virtual void finishTransliteration(Replaceable &text, UTransPosition &index) const
Finishes any pending transliterations that were waiting for more characters.
static int32_t countAvailableSources()
Return the number of registered source specifiers.
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...
static void _registerInstance(Transliterator *adoptedObj)
static StringEnumeration * getAvailableIDs(UErrorCode &ec)
Return a StringEnumeration over the IDs available at the time of the call, including user-registered ...
static int32_t _countAvailableVariants(const UnicodeString &source, const UnicodeString &target)
Non-mutexed internal method.
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeFilter defines a protocol for selecting a subset of the full range (U+0000 to U+10FFFF) of Uni...
Definition unifilt.h:65
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:285
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
Definition unistr.h:5068
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:4960
C API: Parse Error Information.
C++ API: String Enumeration.
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
Position structure for utrans_transIncremental() incremental transliteration.
Definition utrans.h:125
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:427
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
A context integer or pointer for a factory function, passed by value.
Definition translit.h:516
void * pointer
This token, interpreted as a native pointer.
Definition translit.h:526
int32_t integer
This token, interpreted as a 32-bit integer.
Definition translit.h:521
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
C API: Transliterator.
UTransDirection
Direction constant indicating the direction in a transliterator, e.g., the forward or reverse rules o...
Definition utrans.h:83
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316