Class: TTranscoder

Declaration: Transcoder.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

MCollectible

Inherited By:

TASCIITranscoder TMacintoshTranscoder TRuleBasedTranscoder TUTF7Transcoder TUTF8Transcoder

Purpose:

An abstract base class that defines the basic protocol for conversion of character data in a foreign (non-Unicode) encoding to and from Unicode.

Instantiation:

Abstract class; do not allocate directly.

Deriving Classes:

Derived classes are derived for each foreign encoding standard. Reasonable values for the character encoding, name, and maximum bytes per character should be maintained. Deriving classes need not implement CreateStringFromText because the default calls ExtractFromText.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TTranscoder::TTranscoder

  1. TTranscoder (const TTranscoder & copyIn)
  2. TTranscoder ()
  3. TTranscoder (const TToken & encoding)

Interface Category:

API.

Purpose:

  1. Copy constructor. This constructor is protected.
  2. Default constructor. This constructor is protected.
  3. Initializes a transcoder for a specific encoding. This constructor is protected.

Calling Context:

  1. Called to copy an object.
  2. Called by the stream-in operators.
  3. Most commonly called by derived classes.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::SetMaximumBytesPerCharacter

virtual void SetMaximumBytesPerCharacter (TTextCount bytes)

Interface Category:

API.

Purpose:

Allows derived classes to set the maximum bytes for foreign character value.

Calling Context:

Called by derived classes to update this value. Typically called during the editing process as rules are added.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This function is protected.

Member Function: TTranscoder::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: TTranscoder::IsEqual

virtual bool IsEqual (const MCollectible * obj) const

Interface Category:

API.

Purpose:

Compares two objects for equality.

Calling Context:

Called to compare compatible objects.

Parameters:

Return Value:

Returns true if the objects match.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::operator<<=

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

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

Called to stream in data.

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: TTranscoder::operator>>=

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

Interface Category:

API.

Purpose:

Stream-out operator.

Calling Context:

Called to stream out data.

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: TTranscoder::operator=

TTranscoder & operator =(const TTranscoder & from)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

Called when an object is assigned to another compatible object.

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: TTranscoder::~TTranscoder

virtual ~ TTranscoder ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::DoCreateStringFromText

virtual TTextCount DoCreateStringFromText (unsigned char * & string, const TText & uniText, const TTextRange & uniTextConversionRange, TTranscoder :: ETranscodingScope scope) const

Interface Category:

API.

Purpose:

A protected function called to create a null-terminated string from Unicode text. Default calls DoExtractFromText.

Calling Context:

Called by CreateStringFromText.

Parameters:

Return Value:

The number of characters that were converted.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This function is protected.

Member Function: TTranscoder::DoExtractFromText

virtual TTextCount DoExtractFromText (const TText & uniText, const TTextRange & uniTextConversionRange, unsigned char * chars, TTextCount & charsLength, TTranscoder :: ETranscodingScope scope) const

Interface Category:

API.

Purpose:

A protected function called to convert UniChars in a TText to chars in foreign (non_Unicode) encoding.

Calling Context:

Called by ExtractFromText.

Parameters:

Return Value:

The number of characters that were converted.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a protected pure virtual function and needs to be overridden.

Member Function: TTranscoder::DoAppendToText

virtual TTextCount DoAppendToText (const unsigned char * chars, TTextCount charLength, TText & uniText, TTranscoder :: ETranscodingScope scope) const

Interface Category:

API.

Purpose:

A protected function called to convert foreign data in chars to UniChars and append it to a TText.

Calling Context:

Called by AppendToText.

Parameters:

Return Value:

The number of characters that were converted.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a protected pure virtual function and needs to be overridden.

Member Function: TTranscoder::DoCanConvert

  1. virtual TTextCount DoCanConvert (const TText & uniText, const TTextRange & uniTextConversionRange, TTranscoder :: ETranscodingScope scope =TTranscoder :: kFullRoundTrip) const
  2. virtual TTextCount DoCanConvert (const unsigned char * foreignText, TTextCount length, TTranscoder :: ETranscodingScope scope =TTranscoder :: kFullRoundTrip) const

Interface Category:

API.

Purpose:

  1. A protected function called to return the number of characters that can be converted from Unicode to the particular type of non-Unicode text managed by the derived class implementing this function.
  2. A protected function called to return the number of characters that can be converted to Unicode from the particular type of non-Unicode text managed by the derived class implementing this function.

Calling Context:

Called by CanConvert.

Parameters:

Return Value:

The number of characters that can be converted.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is a protected pure virtual function and needs to be overridden.

Member Function: TTranscoder::SetCharacterEncoding

virtual void SetCharacterEncoding (const TToken & encoding)

Interface Category:

API.

Purpose:

Sets the character encoding for this TTranscoding object.

Calling Context:

Called by clients who are creating a transcoder.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This function is protected.

Member Function: TTranscoder::GetCharacterEncoding

virtual void GetCharacterEncoding (TToken & encoding) const

Interface Category:

API.

Purpose:

Gets the character encoding for this TTranscoding object.

Calling Context:

Called directly by clients.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::GetBufferSize

virtual TTextCount GetBufferSize (const TText & uniText, const TTextRange & uniTextRange, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const

Interface Category:

API.

Purpose:

Calculates the actual amount of storage required for a foreign text string that is to be transcoded from Unicode. Requires iterating over the entire TText.

Calling Context:

Typically called before transcoding from Unicode.

Parameters:

Return Value:

Returns a TTextCount for the size of the resulting foreign character string.

Exceptions:

Throws TTranscodingException::kTranscodingNotInstalled if a transcoding cannot be found.

Concurrency:

Not multithread safe.

Other Considerations:

This is a pure virtual function and needs to be overridden.

Member Function: TTranscoder::GetMaximumBytesPerCharacter

virtual TTextCount GetMaximumBytesPerCharacter (TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const

Interface Category:

API.

Purpose:

Provides a quick estimate of the number of bytes required to provide storage for strings converted from Unicode.

Calling Context:

Called to quickly estimate a maximum length for the char buffer used in ExtractFromText. If the number of Unicode characters in a TText is multiplied by GetMaximumBytesPerCharacter, the result is guaranteed to produce a buffer sufficiently long for converting that TText to the foreign (non-Unicode) characters managed by the derived class.

Parameters:

Return Value:

If the default scope (kNoRoundTrip) is used, this function returns the number of bytes per single character in the foreign character set handled by this transcoding. If any but the default scope is used, it returns the length of the longest expansion for a single exception character in the transcoding, that is, the maximum number of bytes required to represent a single Unicode character in the foreign character set.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::CanConvert

  1. TTextCount CanConvert (const TText & uniText, const TTextRange & uniTextConversionRange, TTranscoder :: ETranscodingScope scope =TTranscoder :: kFullRoundTrip) const
  2. TTextCount CanConvert (const unsigned char * foreignText, TTextCount length, TTranscoder :: ETranscodingScope scope =TTranscoder :: kFullRoundTrip) const
  3. TTextCount CanConvert (const signed char * foreignText, TTextCount length, TTranscoder :: ETranscodingScope scope =TTranscoder :: kFullRoundTrip) const
  4. TTextCount CanConvert (const char * foreignText, TTextCount length, TTranscoder :: ETranscodingScope scope =TTranscoder :: kFullRoundTrip) const

Interface Category:

API.

Purpose:

  1. A fast way of determining the number of UniChars in the parameter uniText that can be converted to foreign encoding with the given scope.
  2. A fast way of determining the number of characters in foreignText that can be converted to Unicode with the given scope.
  3. A fast way of determining the number of characters in foreignText that can be converted to Unicode with the given scope.
  4. A fast way of determining the number of characters in foreignText that can be converted to Unicode with the given scope.

Calling Context:

  1. Called before transcoding to select a transcoder that can convert the largest number of characters from Unicode. Can also be used, for example, to warn users that characters typed into a dialogue cannot all be converted from Unicode.
  2. Called before transcoding to select a transcoder that can convert the largest number of characters to Unicode.
  3. Called before transcoding to select a transcoder that can convert the largest number of characters to Unicode.
  4. Called before transcoding to select a transcoder that can convert the largest number of characters to Unicode.

Parameters:

Return Value:

The index of the first character that cannot be converted or the length of the string if all characters can be converted.

Exceptions:

Throws TTranscodingException::kTranscodingNotInstalled if a transcoding cannot be found.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::CreateStringFromText

  1. TTextCount CreateStringFromText (unsigned char * & string, const TText & uniText, const TTextRange & uniTextConversionRange =TTextRange :: GetMaximumRange (), TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const
  2. TTextCount CreateStringFromText (signed char * & string, const TText & uniText, const TTextRange & uniTextConversionRange =TTextRange :: GetMaximumRange (), TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const
  3. TTextCount CreateStringFromText (char * & string, const TText & uniText, const TTextRange & uniTextConversionRange =TTextRange :: GetMaximumRange (), TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const

Interface Category:

API.

Purpose:

  1. Provides an interface for transcoding from Unicode to unsigned char that frees clients from the details of computing and allocating storage for foreign chars.
  2. Provides an interface for transcoding from Unicode to signed char that frees clients from the details of computing and allocating storage for foreign chars.
  3. Provides an interface for transcoding from Unicode to char that frees clients from the details of computing and allocating storage for foreign chars.

Calling Context:

  1. Call this function directly.
  2. Call this function directly.
  3. Call this function directly.

Parameters:

Return Value:

TTextCount is the actual length of the converted foreign chars. The chars are returned in the string parameter.

Exceptions:

Throws TTranscodingException::kTranscodingNotInstalled if a transcoding cannot be found.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::ExtractFromText

  1. TTextCount ExtractFromText (const TText & uniText, const TTextRange & uniTextConversionRange, unsigned char * chars, TTextCount & charsLength, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const
  2. TTextCount ExtractFromText (const TText & uniText, const TTextRange & uniTextConversionRange, signed char * chars, TTextCount & charsLength, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const
  3. TTextCount ExtractFromText (const TText & uniText, const TTextRange & uniTextConversionRange, char * chars, TTextCount & charsLength, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const

Interface Category:

API.

Purpose:

  1. Converts Unicode characters in TText to foreign encoding in unsigned char*.
  2. Converts Unicode characters in TText to foreign encoding in signed chars.
  3. Converts Unicode characters in TText to foreign encoding in chars.

Calling Context:

Typically called when exporting text out of the Taligent system or to subsystems that require a non-Unicode interface. The caller has complete control over the output char buffer. This is so that successive calls can be made efficiently by copying the output into a fixed size buffer. Where storage management is not a concern, use CreateStringFromText.
  1. Called to transcode unsigned char* data.
  2. Called to transcode signed char* data.
  3. Called to transcode char* data.

Parameters:

Return Value:

The number of UniChars converted. If this is less than the original length of the TText parameter, the caller might want to call ExtractFromText again.

Exceptions:

Throws TTranscodingException::kTranscodingNotInstalled if a transcoding cannot be found.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TTranscoder::AppendToText

  1. TTextCount AppendToText (const unsigned char * chars, TTextCount charLength, TText & uniText, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const
  2. TTextCount AppendToText (const signed char * chars, TTextCount charLength, TText & uniText, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const
  3. TTextCount AppendToText (const char * chars, TTextCount charLength, TText & uniText, TTranscoder :: ETranscodingScope scope =kNoRoundTrip) const

Interface Category:

API.

Purpose:

  1. Converts a string of unsigned char from a foreign encoding to Unicode and appends to the TText parameter.
  2. Converts a string of signed char from a foreign encoding to Unicode and appends to the TText parameter.
  3. Converts a string of char from a foreign encoding to Unicode and appends to the TText parameter.

Calling Context:

  1. Typically called when importing non-Unicode unsigned char* data into the Taligent system.
  2. Typically called when importing non-Unicode signed char data into the Taligent system.
  3. Typically called when importing non-Unicode char data into the Taligent system.

Parameters:

Return Value:

Returns TTextCount for the number of foreign chars actually converted. If this number is less than charLength, then the client should call AppendToText for another pass. The converted UniChars are returned in the TText parameter.

Exceptions:

Throws TTranscodingException::kTranscodingNotInstalled if a transcoding cannot be found.

Concurrency:

Not multithread safe.

Other Considerations:

None.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.