Class: TTransliterator

Declaration: Transliterate.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

MCollectible

Inherited By:

THexTransliterator TRuleBasedTransliterator

Purpose:

TTransliterator is an abstract base class that transforms text based upon well-defined rules or an algorithm. Derived classes of TTransliterator can be used to perform intra-script transformation, such as accent composition and upper or lower casing, or inter-script phonetic transcription. Inter-script transliteration provides an alternative way of entering non-Roman text. For example, instead of using a Hebrew keyboard, Hebrew text can be entered with an American keyboard using Roman to Hebrew transliteration. This class is also used to aid typing by providing smart quotes and other punctuation modifiers. TTransliterator provides functions for translating text as well as reversing the effect. These functions must be overridden by the concrete derived classes. TTransliterator is designed to enable chaining multiple objects together. One or more such objects can work within the editable text classes to allow for transliteration during typing input.

Instantiation:

TTransliterator is an abstract class and cannot be instantiated directly.

Deriving Classes:

TTransliterator is an abstract class. Derived classes should override the pure virtual member functions to provide the translation mechanism.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TTransliterator::~TTransliterator

virtual ~ TTransliterator ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::GetMaxExpandFactor

virtual TTextCount GetMaxExpandFactor () const

Interface Category:

API.

Purpose:

Returns the maximum expansion possible for this transliterator when doing forward translation. For example, if any single character can turn into four characters, the expansion factor is 4.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

The expansion factor.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This function is pure virtual. The maximum expansion cannot exceed 256 characters.

Member Function: TTransliterator::GetMaxBackExpandFactor

virtual TTextCount GetMaxBackExpandFactor () const

Interface Category:

API.

Purpose:

Return the maximum expansion possible for this transliterator when doing backward translation. For example, if any single character can turn into four characters, the expansion factor is 4.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

The expansion factor.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This function is pure virtual. The maximum expansion cannot exceed 256 characters.

Member Function: TTransliterator::GetName

virtual void GetName (TLocalizableName & name) const

Interface Category:

API.

Purpose:

Gets the localizable name of this transliterator.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::SetName

virtual void SetName (const TLocalizableName & name)

Interface Category:

API.

Purpose:

Specifies the localizable name of this transliterator.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::operator=

TTransliterator & operator =(const TTransliterator & tran)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

A non-const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::operator<<=

virtual TStream & operator <<= (TStream & fromWhere)

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself in from.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::operator>>=

virtual TStream & operator >>=(TStream & toWhere) const

Interface Category:

API.

Purpose:

Stream-out operator.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself out to.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::Hash

virtual long Hash () const

Interface Category:

API.

Purpose:

Generates a hash value.

Calling Context:

Called to generate a hash value.

Parameters:

Return Value:

The numeric value of the hash.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTransliterator::TTransliterator

  1. TTransliterator ()
  2. TTransliterator (const TTransliterator & tran)
  3. TTransliterator (const TLocalizableName & name)

Interface Category:

API.

Purpose:

  1. Default constructor. This constructor is protected.
  2. Copy constructor. This constructor is protected.
  3. Constructs a transliterator with a particular name. Finds a transliterator with this name. If not found, constructs an empty one with the argument as its name. This constructor is protected.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None

Member Function: TTransliterator::GetTranslateRange

virtual void GetTranslateRange (const TText & currentText, const TTextRange & newTextRange, TTextRange & rangeToTranslate) const

Interface Category:

API.

Purpose:

Given the current text, this function determines how much preceding/succeeding context is needed and returns the range that can be passed into the Translate functions as sourceRange.

Calling Context:

This function is called internally by TranslateInline.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This protected function is pure virtual and must be overridden.

Member Function: TTransliterator::GetMaxPreceed

virtual TTextCount GetMaxPreceed () const

Interface Category:

API.

Purpose:

The maximum number of characters before the current offset that needs to be considered for correct forward translation.

Calling Context:

This function is called by GetTranslateRange.

Parameters:

Return Value:

Maximum number of preceding characters.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This protected function is pure virtual and must be overridden.

Member Function: TTransliterator::GetMaxSucceed

virtual TTextCount GetMaxSucceed () const

Interface Category:

API.

Purpose:

The maximum number of characters after the current offset that needs to be considered for correct forward translation.

Calling Context:

This function is called by GetTranslateRange.

Parameters:

Return Value:

Maximum number of preceding characters.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This protected function is pure virtual and must be overridden.

Member Function: TTransliterator::DoTranslateBack

virtual bool DoTranslateBack (TText & sourceText, const TTextRange & sourceRange, TTextRange & replacementRange, TTextCount & numNewChars) const

Interface Category:

API.

Purpose:

Performs the actual translate back operation.

Calling Context:

Called by the public translate back functions.

Parameters:

Return Value:

Returns true if text is translated.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This protected function is pure virtual and must be overridden.

Member Function: TTransliterator::DoTranslate

virtual bool DoTranslate (TText & sourceText, const TTextRange & sourceRange, TTextRange & replacementRange, TTextCount & numNewChars) const

Interface Category:

API.

Purpose:

Performs the actual translate operation.

Calling Context:

Called by the public translate functions.

Parameters:

Return Value:

Returns true if text is translated.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This protected function is pure virtual and must be overridden.

Member Function: TTransliterator::TranslateInline

  1. virtual bool TranslateInline (const TText & currentText, const TTextRange & newRange, const TText & newText, TText & replacementText, TTextRange & replacementRange) const
  2. virtual bool TranslateInline (TText & currentText, const TTextRange & newRange, const TText & newText, TTextRange & replacementRange, TTextCount & numNewChars) const

Interface Category:

API.

Purpose:

  1. Invoked for inline transliteration such as when the user is typing. Returns the replacement text and range so that the caller can edit the input text.
  2. Similar to the first function, except that the text is changed directly.

Calling Context:

This function is designed to be called directly and has no special requirements.

Parameters:

Return Value:

Returns true if translation was performed.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

By default, the second function calls the first, which calls DoTranslate. These functions should not be overridden. Instead, override DoTranslate to change behavior.

Member Function: TTransliterator::TranslateBack

  1. virtual bool TranslateBack (TText & text) const
  2. virtual bool TranslateBack (const TText & sourceText, const TTextRange & sourceRange, TText & replacementText, TTextRange & replacementRange) const
  3. virtual bool TranslateBack (TText & sourceText, const TTextRange & sourceRange, TTextRange & replacementRange, TTextCount & numNewChars) const

Interface Category:

API.

Purpose:

  1. This function directly translates back the specified text object.
  2. Given a text object (sourceText) and a range within it (sourceRange), this function returns the replacement (translated back) text and range.
  3. Given a text object and a range within it, this function calls DoTranslateBack to directly change the text object and return the range replaced and the number of new characters inserted.

Calling Context:

This function is designed to be called directly and has no special requirements. It is also called internally by functions such as TranslateInline.

Parameters:

Return Value:

Returns true if translation back was performed.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The first and second functions call the third by default. Note that it is not always possible to reverse the translation effect and return the text to its original state, so the result will sometimes be an approximation of the original. Also, in some derived classes, reverse translation does not make sense. In such cases, the third TranslateBack should be overridden to do nothing.

Member Function: TTransliterator::Translate

  1. virtual bool Translate (TText & text) const
  2. virtual bool Translate (const TText & sourceText, const TTextRange & sourceRange, TText & replacementText, TTextRange & replacementRange) const
  3. virtual bool Translate (TText & sourceText, const TTextRange & sourceRange, TTextRange & replacementRange, TTextCount & numNewChars) const

Interface Category:

API.

Purpose:

  1. This function directly translates the specified text object.
  2. Given a text object (sourceText) and a range within it (sourceRange), this function returns the replacement text and range.
  3. Given a text object and a range within it, this function calls DoTranslate to directly change the text object and return the range replaced and the number of new characters inserted.

Calling Context:

This function is designed to be called directly and has no special requirements. It is also called internally by functions such as TranslateInline.

Parameters:

Return Value:

Returns true if translation was performed.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The first and second functions call the third by default.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.