translit.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (C) 1999-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
* 11/17/99 aliu Creation.
**********************************************************************
*/
#ifndef TRANSLIT_H
#define TRANSLIT_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/uobject.h"
#include "unicode/unistr.h"
#include "unicode/parseerr.h"
#include "unicode/utrans.h" // UTransPosition, UTransDirection
#include "unicode/strenum.h"
U_NAMESPACE_BEGIN
class UnicodeFilter;
class UnicodeSet;
class TransliteratorParser;
class NormalizationTransliterator;
class TransliteratorIDParser;
class U_I18N_API Transliterator : public UObject {
private:
UnicodeString ID;
UnicodeFilter* filter;
int32_t maximumContextLength;
public:
union Token {
int32_t integer;
void* pointer;
};
#ifndef U_HIDE_INTERNAL_API
inline static Token integerToken(int32_t);
inline static Token pointerToken(void*);
#endif /* U_HIDE_INTERNAL_API */
typedef Transliterator* (U_EXPORT2 *Factory)(const UnicodeString& ID, Token context);
protected:
Transliterator(const UnicodeString& ID, UnicodeFilter* adoptedFilter);
Transliterator(const Transliterator&);
Transliterator& operator=(const Transliterator&);
static Transliterator* createBasicInstance(const UnicodeString& id,
const UnicodeString* canon);
friend class TransliteratorParser; // for parseID()
friend class TransliteratorIDParser; // for createBasicInstance()
friend class TransliteratorAlias; // for setID()
public:
virtual ~Transliterator();
virtual Transliterator* clone() const;
virtual int32_t transliterate(Replaceable& text,
int32_t start, int32_t limit) const;
virtual void transliterate(Replaceable& text) const;
virtual void transliterate(Replaceable& text, UTransPosition& index,
const UnicodeString& insertion,
UErrorCode& status) const;
virtual void transliterate(Replaceable& text, UTransPosition& index,
UChar32 insertion,
UErrorCode& status) const;
virtual void transliterate(Replaceable& text, UTransPosition& index,
UErrorCode& status) const;
virtual void finishTransliteration(Replaceable& text,
UTransPosition& index) const;
private:
void _transliterate(Replaceable& text,
UTransPosition& index,
const UnicodeString* insertion,
UErrorCode &status) const;
protected:
virtual void handleTransliterate(Replaceable& text,
UTransPosition& pos,
UBool incremental) const = 0;
public:
virtual void filteredTransliterate(Replaceable& text,
UTransPosition& index,
UBool incremental) const;
private:
virtual void filteredTransliterate(Replaceable& text,
UTransPosition& index,
UBool incremental,
UBool rollback) const;
public:
int32_t getMaximumContextLength(void) const;
protected:
void setMaximumContextLength(int32_t maxContextLength);
public:
virtual const UnicodeString& getID(void) const;
static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
UnicodeString& result);
static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
const Locale& inLocale,
UnicodeString& result);
const UnicodeFilter* getFilter(void) const;
UnicodeFilter* orphanFilter(void);
void adoptFilter(UnicodeFilter* adoptedFilter);
Transliterator* createInverse(UErrorCode& status) const;
static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
UTransDirection dir,
UParseError& parseError,
UErrorCode& status);
static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
UTransDirection dir,
UErrorCode& status);
static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
const UnicodeString& rules,
UTransDirection dir,
UParseError& parseError,
UErrorCode& status);
virtual UnicodeString& toRules(UnicodeString& result,
UBool escapeUnprintable) const;
int32_t countElements() const;
const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
UnicodeSet& getSourceSet(UnicodeSet& result) const;
virtual void handleGetSourceSet(UnicodeSet& result) const;
virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
public:
static void U_EXPORT2 registerFactory(const UnicodeString& id,
Factory factory,
Token context);
static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
static void U_EXPORT2 registerAlias(const UnicodeString& aliasID,
const UnicodeString& realID);
protected:
#ifndef U_HIDE_INTERNAL_API
static void _registerFactory(const UnicodeString& id,
Factory factory,
Token context);
static void _registerInstance(Transliterator* adoptedObj);
static void _registerAlias(const UnicodeString& aliasID, const UnicodeString& realID);
static void _registerSpecialInverse(const UnicodeString& target,
const UnicodeString& inverseTarget,
UBool bidirectional);
#endif /* U_HIDE_INTERNAL_API */
public:
static void U_EXPORT2 unregister(const UnicodeString& ID);
public:
static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
static int32_t U_EXPORT2 countAvailableSources(void);
static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
UnicodeString& result);
static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
const UnicodeString& source,
UnicodeString& result);
static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
const UnicodeString& target);
static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
const UnicodeString& source,
const UnicodeString& target,
UnicodeString& result);
protected:
#ifndef U_HIDE_INTERNAL_API
static int32_t _countAvailableSources(void);
static UnicodeString& _getAvailableSource(int32_t index,
UnicodeString& result);
static int32_t _countAvailableTargets(const UnicodeString& source);
static UnicodeString& _getAvailableTarget(int32_t index,
const UnicodeString& source,
UnicodeString& result);
static int32_t _countAvailableVariants(const UnicodeString& source,
const UnicodeString& target);
static UnicodeString& _getAvailableVariant(int32_t index,
const UnicodeString& source,
const UnicodeString& target,
UnicodeString& result);
#endif /* U_HIDE_INTERNAL_API */
protected:
void setID(const UnicodeString& id);
public:
static UClassID U_EXPORT2 getStaticClassID(void);
virtual UClassID getDynamicClassID(void) const override = 0;
private:
static UBool initializeRegistry(UErrorCode &status);
public:
#ifndef U_HIDE_OBSOLETE_API
static int32_t U_EXPORT2 countAvailableIDs(void);
static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
#endif /* U_HIDE_OBSOLETE_API */
};
inline int32_t Transliterator::getMaximumContextLength(void) const {
return maximumContextLength;
}
inline void Transliterator::setID(const UnicodeString& id) {
ID = id;
// NUL-terminate the ID string, which is a non-aliased copy.
ID.append((char16_t)0);
ID.truncate(ID.length()-1);
}
#ifndef U_HIDE_INTERNAL_API
inline Transliterator::Token Transliterator::integerToken(int32_t i) {
Token t;
t.integer = i;
return t;
}
inline Transliterator::Token Transliterator::pointerToken(void* p) {
Token t;
t.pointer = p;
return t;
}
#endif /* U_HIDE_INTERNAL_API */
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
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::getStaticClassID
static UClassID getStaticClassID(void)
Return the class ID for this class.
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::countAvailableIDs
static int32_t countAvailableIDs(void)
Return the number of IDs currently registered with the system.
icu::Transliterator::_registerAlias
static void _registerAlias(const UnicodeString &aliasID, const UnicodeString &realID)
icu::Transliterator::getAvailableSource
static UnicodeString & getAvailableSource(int32_t index, UnicodeString &result)
Return a registered source specifier.
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::createBasicInstance
static Transliterator * createBasicInstance(const UnicodeString &id, const UnicodeString *canon)
Create a transliterator from a basic ID.
icu::Transliterator::countAvailableSources
static int32_t countAvailableSources(void)
Return the number of registered source specifiers.
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::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::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::_registerSpecialInverse
static void _registerSpecialInverse(const UnicodeString &target, const UnicodeString &inverseTarget, UBool bidirectional)
Register two targets as being inverses of one another.
icu::Transliterator::_countAvailableSources
static int32_t _countAvailableSources(void)
Non-mutexed internal method.
icu::Transliterator::getID
virtual const UnicodeString & getID(void) const
Returns a programmatic identifier for this transliterator.
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::getDynamicClassID
virtual UClassID getDynamicClassID(void) const override=0
Returns a unique class ID polymorphically.
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::getFilter
const UnicodeFilter * getFilter(void) const
Returns the filter used by this transliterator, or nullptr if this transliterator uses no filter.
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::orphanFilter
UnicodeFilter * orphanFilter(void)
Returns the filter used by this transliterator, or nullptr if this transliterator uses no filter.
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::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:223
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:296
icu::UnicodeString::truncate
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
Definition: unistr.h:4757
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:4649
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:435
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
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:415
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:301