Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
nsUnicodeToTeXCMMIt1 Class Reference

A character set converter from Unicode to TeXCMMIt1 (TeX's Computer Modern Math Italic). More...

#include <nsUnicodeToTeXCMMIt1.h>

Inheritance diagram for nsUnicodeToTeXCMMIt1:
Inheritance graph
[legend]
Collaboration diagram for nsUnicodeToTeXCMMIt1:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { kOnError_Signal, kOnError_CallBack, kOnError_Replace }

Public Member Functions

 nsUnicodeToTeXCMMIt1 ()
 Class constructor.
NS_IMETHOD FillInfo (PRUint32 *aInfo)
NS_IMETHOD Convert (const PRUnichar *aSrc, PRInt32 *aSrcLength, char *aDest, PRInt32 *aDestLength)
 Converts the data from Unicode to a Charset.
NS_IMETHOD Finish (char *aDest, PRInt32 *aDestLength)
 Finishes the conversion.
NS_IMETHOD Reset ()
 Resets the charset converter so it may be recycled for a completely different and urelated buffer of data.
NS_IMETHOD SetOutputErrorBehavior (PRInt32 aBehavior, nsIUnicharEncoder *aEncoder, PRUnichar aChar)
 Specify what to do when a character cannot be mapped into the dest charset.
NS_IMETHOD GetMaxLength (const PRUnichar *aSrc, PRInt32 aSrcLength, PRInt32 *aDestLength)
 Returns a quick estimation of the size of the buffer needed to hold the converted data.

Protected Member Functions

NS_IMETHOD ConvertNoBuffNoErr (const PRUnichar *aSrc, PRInt32 *aSrcLength, char *aDest, PRInt32 *aDestLength)
 Convert method but without the buffer management stuff and without error handling stuff.
NS_IMETHOD ConvertNoBuff (const PRUnichar *aSrc, PRInt32 *aSrcLength, char *aDest, PRInt32 *aDestLength)
 Convert method but without the buffer management stuff and with error handling stuff.
NS_IMETHOD FinishNoBuff (char *aDest, PRInt32 *aDestLength)
 Finish method but without the buffer management stuff.
nsresult FlushBuffer (char **aDest, const char *aDestEnd)
 Copy as much as possible from the internal buffer to the destination.

Protected Attributes

nsIUnicodeEncodeHelpermHelper
uShiftTablemShiftTable
uMappingTablemMappingTable
char * mBuffer
 Internal buffer for partial conversions.
PRInt32 mBufferCapacity
char * mBufferStart
char * mBufferEnd
PRInt32 mErrBehavior
 Error handling stuff.
nsCOMPtr< nsIUnicharEncodermErrEncoder
PRUnichar mErrChar
PRUint32 mMaxLengthFactor

Detailed Description

A character set converter from Unicode to TeXCMMIt1 (TeX's Computer Modern Math Italic).

Definition at line 51 of file nsUnicodeToTeXCMMIt1.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
kOnError_Signal 
kOnError_CallBack 
kOnError_Replace 

Definition at line 136 of file nsIUnicodeEncoder.h.

       {
    kOnError_Signal,        // on an error, stop and signal
    kOnError_CallBack,      // on an error, call the error handler
    kOnError_Replace       // on an error, replace with a different character
  };

Constructor & Destructor Documentation

Class constructor.

Definition at line 56 of file nsUnicodeToTeXCMMIt1.cpp.


Member Function Documentation

NS_IMETHODIMP nsEncoderSupport::Convert ( const PRUnichar aSrc,
PRInt32 aSrcLength,
char *  aDest,
PRInt32 aDestLength 
) [virtual, inherited]

Converts the data from Unicode to a Charset.

About the byte ordering:

  • The input stream is Unicode, having the byte order which is internal for the machine on which the converter is running on.
  • For output, if the converter cares (that depends of the charset, for example a singlebyte will ignore the byte ordering) it should assume network order. If necessary and requested, we can add a method SetOutputByteOrder() so that the reverse order can be used, too. That method would have as default the assumed network order.

Unless there is not enough output space, this method must consume all the available input data! We don't have partial input for the Unicode charset. And for the last converted char, even if there is not enought output space, a partial ouput must be done until all available space will be used. The rest of the output should be buffered until more space becomes available. But this is not also true about the error handling method!!! So be very, very careful...

Parameters:
aSrc[IN] the source data buffer
aSrcLength[IN/OUT] the length of source data buffer; after conversion will contain the number of Unicode characters read
aDest[OUT] the destination data buffer
aDestLength[IN/OUT] the length of the destination data buffer; after conversion will contain the number of bytes written
Returns:
NS_OK_UENC_MOREOUTPUT if only a partial conversion was done; more output space is needed to continue NS_ERROR_UENC_NOMAPPING if character without mapping was encountered and the behavior was set to "signal".

Implements nsIUnicodeEncoder.

Definition at line 475 of file nsUCSupport.cpp.

{
  // we do all operations using pointers internally
  const PRUnichar * src = aSrc;
  const PRUnichar * srcEnd = aSrc + *aSrcLength;
  char * dest = aDest;
  char * destEnd = aDest + *aDestLength;

  PRInt32 bcr, bcw; // byte counts for read & write;
  nsresult res;

  res = FlushBuffer(&dest, destEnd);
  if (res == NS_OK_UENC_MOREOUTPUT) goto final;

  bcr = srcEnd - src;
  bcw = destEnd - dest;
  res = ConvertNoBuff(src, &bcr, dest, &bcw);
  src += bcr;
  dest += bcw;
  if ((res == NS_OK_UENC_MOREOUTPUT) && (dest < destEnd)) {
    // convert exactly one character into the internal buffer
    // at this point, there should be at least a char in the input
    for (;;) {
      bcr = 1;
      bcw = mBufferCapacity;
      res = ConvertNoBuff(src, &bcr, mBuffer, &bcw);

      if (res == NS_OK_UENC_MOREOUTPUT) {
        delete [] mBuffer;
        mBufferCapacity *= 2;
        mBuffer = new char [mBufferCapacity];
      } else {
        src += bcr;
        mBufferStart = mBufferEnd = mBuffer;
        mBufferEnd += bcw;
        break;
      }
    }

    res = FlushBuffer(&dest, destEnd);
  }

final:
  *aSrcLength   -= srcEnd - src;
  *aDestLength  -= destEnd - dest;
  return res;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEncoderSupport::ConvertNoBuff ( const PRUnichar aSrc,
PRInt32 aSrcLength,
char *  aDest,
PRInt32 aDestLength 
) [protected, inherited]

Convert method but without the buffer management stuff and with error handling stuff.

Reimplemented in nsUnicodeToGBK, nsUnicodeToHZ, nsUnicodeToGB2312GL, and nsUnicodeToGB2312V2.

Definition at line 394 of file nsUCSupport.cpp.

{
  // we do all operations using pointers internally
  const PRUnichar * src = aSrc;
  const PRUnichar * srcEnd = aSrc + *aSrcLength;
  char * dest = aDest;
  char * destEnd = aDest + *aDestLength;

  PRInt32 bcr, bcw; // byte counts for read & write;
  nsresult res;

  for (;;) {
    bcr = srcEnd - src;
    bcw = destEnd - dest;
    res = ConvertNoBuffNoErr(src, &bcr, dest, &bcw);
    src += bcr;
    dest += bcw;

    if (res == NS_ERROR_UENC_NOMAPPING) {
      if (mErrBehavior == kOnError_Replace) {
        const PRUnichar buff[] = {mErrChar};
        bcr = 1;
        bcw = destEnd - dest;
        src--; // back the input: maybe the guy won't consume consume anything.
        res = ConvertNoBuffNoErr(buff, &bcr, dest, &bcw);
        src += bcr;
        dest += bcw;
        if (res != NS_OK) break;
      } else if (mErrBehavior == kOnError_CallBack) {
        bcw = destEnd - dest;
        src--;
        res = mErrEncoder->Convert(*src, dest, &bcw);
        dest += bcw;
        // if enought output space then the last char was used
        if (res != NS_OK_UENC_MOREOUTPUT) src++;
        if (res != NS_OK) break;
      } else break;
    }
    else break;
  }

  *aSrcLength   -= srcEnd - src;
  *aDestLength  -= destEnd - dest;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsTableEncoderSupport::ConvertNoBuffNoErr ( const PRUnichar aSrc,
PRInt32 aSrcLength,
char *  aDest,
PRInt32 aDestLength 
) [protected, virtual, inherited]

Convert method but without the buffer management stuff and without error handling stuff.

Implements nsEncoderSupport.

Definition at line 624 of file nsUCSupport.cpp.

{
  nsresult res;

  if (mHelper == nsnull) {
    res = CallCreateInstance(kUnicodeEncodeHelperCID, &mHelper);
    if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
  }

  res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength, 
      mShiftTable, mMappingTable);
  return res;
}

Here is the call graph for this function:

NS_IMETHODIMP nsTableEncoderSupport::FillInfo ( PRUint32 aInfo) [virtual, inherited]

Implements nsEncoderSupport.

Reimplemented in nsUnicodeToBIG5NoAscii.

Definition at line 609 of file nsUCSupport.cpp.

{
  nsresult res;

  if (mHelper == nsnull) {
    res = CallCreateInstance(kUnicodeEncodeHelperCID, &mHelper);
    if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
  }

  res = mHelper->FillInfo(aInfo, mMappingTable);
  return res;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEncoderSupport::Finish ( char *  aDest,
PRInt32 aDestLength 
) [virtual, inherited]

Finishes the conversion.

The converter has the possibility to write some extra data and flush its final state.

Parameters:
aDest[OUT] the destination data buffer
aDestLength[IN/OUT] the length of destination data buffer; after conversion it will contain the number of bytes written
Returns:
NS_OK_UENC_MOREOUTPUT if only a partial conversion was done; more output space is needed to continue

Implements nsIUnicodeEncoder.

Definition at line 526 of file nsUCSupport.cpp.

{
  // we do all operations using pointers internally
  char * dest = aDest;
  char * destEnd = aDest + *aDestLength;

  PRInt32 bcw; // byte count for write;
  nsresult res;

  res = FlushBuffer(&dest, destEnd);
  if (res == NS_OK_UENC_MOREOUTPUT) goto final;

  // do the finish into the internal buffer.
  for (;;) {
    bcw = mBufferCapacity;
    res = FinishNoBuff(mBuffer, &bcw);

    if (res == NS_OK_UENC_MOREOUTPUT) {
      delete [] mBuffer;
      mBufferCapacity *= 2;
      mBuffer = new char [mBufferCapacity];
    } else {
      mBufferStart = mBufferEnd = mBuffer;
      mBufferEnd += bcw;
      break;
    }
  }

  res = FlushBuffer(&dest, destEnd);

final:
  *aDestLength  -= destEnd - dest;
  return res;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEncoderSupport::FinishNoBuff ( char *  aDest,
PRInt32 aDestLength 
) [protected, inherited]

Finish method but without the buffer management stuff.

Reimplemented in nsBasicUTF7Encoder, and nsUnicodeToISO2022JP.

Definition at line 443 of file nsUCSupport.cpp.

{
  *aDestLength = 0;
  return NS_OK;
}

Here is the caller graph for this function:

nsresult nsEncoderSupport::FlushBuffer ( char **  aDest,
const char *  aDestEnd 
) [protected, inherited]

Copy as much as possible from the internal buffer to the destination.

Definition at line 450 of file nsUCSupport.cpp.

{
  PRInt32 bcr, bcw; // byte counts for read & write;
  nsresult res = NS_OK;
  char * dest = *aDest;

  if (mBufferStart < mBufferEnd) {
    bcr = mBufferEnd - mBufferStart;
    bcw = aDestEnd - dest;
    if (bcw < bcr) bcr = bcw;
    memcpy(dest, mBufferStart, bcr);
    dest += bcr;
    mBufferStart += bcr;

    if (mBufferStart < mBufferEnd) res = NS_OK_UENC_MOREOUTPUT;
  }

  *aDest = dest;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEncoderSupport::GetMaxLength ( const PRUnichar aSrc,
PRInt32  aSrcLength,
PRInt32 aDestLength 
) [virtual, inherited]

Returns a quick estimation of the size of the buffer needed to hold the converted data.

Remember: this estimation is >= with the actual size of the buffer needed. It will be computed for the "worst case"

Parameters:
aSrc[IN] the source data buffer
aSrcLength[IN] the length of source data buffer
aDestLength[OUT] the needed size of the destination buffer
Returns:
NS_OK_UENC_EXACTLENGTH if an exact length was computed NS_OK if all we have is an approximation

Implements nsIUnicodeEncoder.

Definition at line 582 of file nsUCSupport.cpp.

{
  *aDestLength = aSrcLength * mMaxLengthFactor;
  return NS_OK;
}
NS_IMETHODIMP nsEncoderSupport::Reset ( ) [virtual, inherited]

Resets the charset converter so it may be recycled for a completely different and urelated buffer of data.

Implements nsIUnicodeEncoder.

Reimplemented in nsBasicUTF7Encoder, and nsUnicodeToISO2022JP.

Definition at line 561 of file nsUCSupport.cpp.

NS_IMETHODIMP nsEncoderSupport::SetOutputErrorBehavior ( PRInt32  aBehavior,
nsIUnicharEncoder aEncoder,
PRUnichar  aChar 
) [virtual, inherited]

Specify what to do when a character cannot be mapped into the dest charset.

Parameters:
aOrder[IN] the behavior; taken from the enum

Implements nsIUnicodeEncoder.

Definition at line 567 of file nsUCSupport.cpp.

{
  if (aBehavior == kOnError_CallBack && aEncoder == nsnull) 
    return NS_ERROR_NULL_POINTER;

  mErrEncoder = aEncoder;
  mErrBehavior = aBehavior;
  mErrChar = aChar;
  return NS_OK;
}

Member Data Documentation

char* nsEncoderSupport::mBuffer [protected, inherited]

Internal buffer for partial conversions.

Definition at line 332 of file nsUCSupport.h.

Definition at line 333 of file nsUCSupport.h.

char* nsEncoderSupport::mBufferEnd [protected, inherited]

Definition at line 335 of file nsUCSupport.h.

char* nsEncoderSupport::mBufferStart [protected, inherited]

Definition at line 334 of file nsUCSupport.h.

PRInt32 nsEncoderSupport::mErrBehavior [protected, inherited]

Error handling stuff.

Definition at line 340 of file nsUCSupport.h.

PRUnichar nsEncoderSupport::mErrChar [protected, inherited]

Definition at line 342 of file nsUCSupport.h.

Definition at line 341 of file nsUCSupport.h.

Definition at line 427 of file nsUCSupport.h.

Definition at line 429 of file nsUCSupport.h.

Definition at line 343 of file nsUCSupport.h.

Definition at line 428 of file nsUCSupport.h.


The documentation for this class was generated from the following files: