Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions
nsUnicodeDecodeHelper Class Reference

The actual implementation of the nsIUnicodeDecodeHelper interface. More...

#include <nsUnicodeDecodeHelper.h>

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

List of all members.

Public Member Functions

 nsUnicodeDecodeHelper ()
 Class constructor.
virtual ~nsUnicodeDecodeHelper ()
 Class destructor.
NS_IMETHOD ConvertByTable (const char *aSrc, PRInt32 *aSrcLength, PRUnichar *aDest, PRInt32 *aDestLength, uShiftTable *aShiftTable, uMappingTable *aMappingTable)
 Converts data using a lookup table.
NS_IMETHOD ConvertByMultiTable (const char *aSrc, PRInt32 *aSrcLength, PRUnichar *aDest, PRInt32 *aDestLength, PRInt32 aTableCount, const uRange *aRangeArray, uShiftTable **aShiftTable, uMappingTable **aMappingTable)
 Converts data using a set of lookup tables.
NS_IMETHOD ConvertByFastTable (const char *aSrc, PRInt32 *aSrcLength, PRUnichar *aDest, PRInt32 *aDestLength, const PRUnichar *aFastTable, PRInt32 aTableSize)
 Converts data using a fast lookup table.
NS_IMETHOD CreateFastTable (uShiftTable *aShiftTable, uMappingTable *aMappingTable, PRUnichar *aFastTable, PRInt32 aTableSize)
 Create a cache-like fast lookup table from a normal one.
NS_IMETHOD CreateCache (nsMappingCacheType aType, nsIMappingCache *aResult)
 Create a Mapping Cache.
NS_IMETHOD DestroyCache (nsIMappingCache aResult)
 Destroy a Mapping Cache.

Detailed Description

The actual implementation of the nsIUnicodeDecodeHelper interface.

18/Mar/1998

Author:
Catalin Rotaru [CATA]

Definition at line 52 of file nsUnicodeDecodeHelper.h.


Constructor & Destructor Documentation

Class constructor.

Definition at line 52 of file nsUnicodeDecodeHelper.cpp.

{
}

Class destructor.

Definition at line 56 of file nsUnicodeDecodeHelper.cpp.

{
}

Member Function Documentation

NS_IMETHODIMP nsUnicodeDecodeHelper::ConvertByFastTable ( const char *  aSrc,
PRInt32 aSrcLength,
PRUnichar aDest,
PRInt32 aDestLength,
const PRUnichar aFastTable,
PRInt32  aTableSize 
) [virtual]

Converts data using a fast lookup table.

Implements nsIUnicodeDecodeHelper.

Definition at line 218 of file nsUnicodeDecodeHelper.cpp.

{
  PRUint8 * src = (PRUint8 *)aSrc;
  PRUint8 * srcEnd = src;
  PRUnichar * dest = aDest;

  nsresult res;
  if (*aSrcLength > *aDestLength) {
    srcEnd += (*aDestLength);
    res = NS_PARTIAL_MORE_OUTPUT;
  } else {
    srcEnd += (*aSrcLength);
    res = NS_OK;
  }

  for (; src<srcEnd;) *dest++ = aFastTable[*src++];

  *aSrcLength = src - (PRUint8 *)aSrc;
  *aDestLength  = dest - aDest;
  return res;
}
NS_IMETHODIMP nsUnicodeDecodeHelper::ConvertByMultiTable ( const char *  aSrc,
PRInt32 aSrcLength,
PRUnichar aDest,
PRInt32 aDestLength,
PRInt32  aTableCount,
const uRange aRangeArray,
uShiftTable **  aShiftTable,
uMappingTable **  aMappingTable 
) [virtual]

Converts data using a set of lookup tables.

Implements nsIUnicodeDecodeHelper.

Definition at line 109 of file nsUnicodeDecodeHelper.cpp.

{
  PRUint8 * src = (PRUint8 *)aSrc;
  PRInt32 srcLen = *aSrcLength;
  PRUnichar * dest = aDest;
  PRUnichar * destEnd = aDest + *aDestLength;

  PRUnichar med;
  PRInt32 bcr; // byte count for read
  nsresult res = NS_OK;
  PRInt32 i;

  while ((srcLen > 0) && (dest < destEnd)) 
  {
    PRBool done= PR_FALSE;
    PRBool passRangeCheck = PR_FALSE;
    PRBool passScan = PR_FALSE;
    for (i=0; (!done) && (i<aTableCount); i++)  
    {
      if ((aRangeArray[i].min <= *src) && (*src <= aRangeArray[i].max)) 
      {
        passRangeCheck = PR_TRUE;
        if (uScan(aShiftTable[i], NULL, src, 
                   NS_REINTERPRET_CAST(PRUint16*, &med), srcLen, 
                   (PRUint32 *)&bcr)) 
        {
          passScan = PR_TRUE;
          done = uMapCode((uTable*) aMappingTable[i], 
                          NS_STATIC_CAST(PRUint16, med), 
                          NS_REINTERPRET_CAST(PRUint16*, dest)); 
        } // if (uScan ... )
      } // if Range
    } // for loop

    if(passRangeCheck && (! passScan))
    {
      res = NS_OK_UDEC_MOREINPUT;
      break;
    }
    if(! done)
    {
      bcr = 1;
      if ((PRUint8)*src < 0x20) {
        // somehow some table miss the 0x00 - 0x20 part
        *dest = *src;
      } else if(*src == (PRUint8) 0xa0) {
        // handle nbsp
        *dest = 0x00a0;
      } else {
        // we need to decide how many byte we skip. We can use uScan to do this
        for (i=0; i<aTableCount; i++)  
        {
          if ((aRangeArray[i].min <= *src) && (*src <= aRangeArray[i].max)) 
          {
            if (uScan(aShiftTable[i], NULL, src, 
                   NS_REINTERPRET_CAST(PRUint16*, &med), srcLen, 
                   (PRUint32*)&bcr)) 
            { 
               // match the patten
              
               PRInt32 k; 
               for(k = 1; k < bcr; k++)
               {
                 if(0 == (src[k]  & 0x80))
                 { // only skip if all bytes > 0x80
                   // if we hit bytes <= 0x80, skip only one byte
                   bcr = 1;
                   break; 
                 }
               }
               break;
            }
          }
        }
        // treat it as NSBR if bcr == 1 and it is 0xa0
        *dest = ((1==bcr)&&(*src == (PRUint8)0xa0 )) ? 0x00a0 : 0xfffd;
      }
    }

    src += bcr;
    srcLen -= bcr;
    dest++;
  } // while

  if ((srcLen > 0) && (res == NS_OK)) res = NS_OK_UDEC_MOREOUTPUT;

  *aSrcLength = src - (PRUint8 *)aSrc;
  *aDestLength  = dest - aDest;
  return res;
}

Here is the call graph for this function:

NS_IMETHODIMP nsUnicodeDecodeHelper::ConvertByTable ( const char *  aSrc,
PRInt32 aSrcLength,
PRUnichar aDest,
PRInt32 aDestLength,
uShiftTable aShiftTable,
uMappingTable aMappingTable 
) [virtual]

Converts data using a lookup table.

Implements nsIUnicodeDecodeHelper.

Definition at line 63 of file nsUnicodeDecodeHelper.cpp.

{
  const char * src = aSrc;
  PRInt32 srcLen = *aSrcLength;
  PRUnichar * dest = aDest;
  PRUnichar * destEnd = aDest + *aDestLength;

  PRUnichar med;
  PRInt32 bcr; // byte count for read
  nsresult res = NS_OK;

  while ((srcLen > 0) && (dest < destEnd)) {
    if (!uScan(aShiftTable, NULL, (PRUint8 *)src, NS_REINTERPRET_CAST(PRUint16*, &med), srcLen, 
    (PRUint32 *)&bcr)) {
      res = NS_OK_UDEC_MOREINPUT;
      break;
    }

    if (!uMapCode((uTable*) aMappingTable, NS_STATIC_CAST(PRUint16, med), NS_REINTERPRET_CAST(PRUint16*, dest))) {
      if (med < 0x20) {
        // somehow some table miss the 0x00 - 0x20 part
        *dest = med;
      } else {
        // Unicode replacement value for unmappable chars
        *dest = 0xfffd;
      }
    }

    src += bcr;
    srcLen -= bcr;
    dest++;
  }

  if ((srcLen > 0) && (res == NS_OK)) res = NS_OK_UDEC_MOREOUTPUT;

  *aSrcLength = src - aSrc;
  *aDestLength  = dest - aDest;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Create a Mapping Cache.

Implements nsIUnicodeDecodeHelper.

Definition at line 208 of file nsUnicodeDecodeHelper.cpp.

NS_IMETHODIMP nsUnicodeDecodeHelper::CreateFastTable ( uShiftTable aShiftTable,
uMappingTable aMappingTable,
PRUnichar aFastTable,
PRInt32  aTableSize 
) [virtual]

Create a cache-like fast lookup table from a normal one.

Implements nsIUnicodeDecodeHelper.

Definition at line 246 of file nsUnicodeDecodeHelper.cpp.

{
  PRInt32 tableSize = aTableSize;
  PRInt32 buffSize = aTableSize;
  char * buff = new char [buffSize];
  if (buff == NULL) return NS_ERROR_OUT_OF_MEMORY;

  char * p = buff;
  for (PRInt32 i=0; i<aTableSize; i++) *(p++) = i;
  nsresult res = ConvertByTable(buff, &buffSize, aFastTable, &tableSize, 
      aShiftTable, aMappingTable);

  delete [] buff;
  return res;
}

Here is the call graph for this function:

Destroy a Mapping Cache.

Implements nsIUnicodeDecodeHelper.

Definition at line 213 of file nsUnicodeDecodeHelper.cpp.

{
   return nsMappingCache::DestroyCache(aCache);
}

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