Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Public Attributes
WinCEUConvAdapter Class Reference
Inheritance diagram for WinCEUConvAdapter:
Inheritance graph
[legend]
Collaboration diagram for WinCEUConvAdapter:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { kOnError_Recover, kOnError_Signal }
enum  { kOnError_Signal, kOnError_CallBack, kOnError_Replace }

Public Member Functions

 WinCEUConvAdapter ()
virtual ~WinCEUConvAdapter ()
nsresult Init (const char *from, const char *to)
NS_IMETHOD Convert (const char *aSrc, PRInt32 *aSrcLength, PRUnichar *aDest, PRInt32 *aDestLength)
 Converts the data from one Charset to Unicode.
NS_IMETHOD GetMaxLength (const char *aSrc, PRInt32 aSrcLength, PRInt32 *aDestLength)
 Returns a quick estimation of the size of the buffer needed to hold the converted data.
NS_IMETHOD Reset ()
 Resets the charset converter so it may be recycled for a completely different and urelated buffer of data.
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 GetMaxLength (const PRUnichar *aSrc, PRInt32 aSrcLength, PRInt32 *aDestLength)
 Returns a quick estimation of the size of the buffer needed to hold the converted 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 FillInfo (PRUint32 *aInfo)

Public Attributes

 NS_DECL_ISUPPORTS
PRUint32 mCodepage

Detailed Description

Definition at line 76 of file nsWinCEUConvService.cpp.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
kOnError_Recover 
kOnError_Signal 

Definition at line 98 of file nsIUnicodeDecoder.h.

       {
    kOnError_Recover,       // on an error, recover and continue
    kOnError_Signal         // on an error, stop and signal
  };
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

Definition at line 136 of file nsWinCEUConvService.cpp.

{
}

Member Function Documentation

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

Converts the data from one Charset to Unicode.

About the byte ordering:

  • For input, 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 SetInputByteOrder() so that the reverse order can be used, too. That method would have as default the assumed network order.
  • The output stream is Unicode, having the byte order which is internal for the machine on which the converter is running on.

Unless there is not enough output space, this method must consume all the available input data! The eventual incomplete final character data will be stored internally in the converter and used when the method is called again for continuing the conversion. This way, the caller will not have to worry about managing incomplete input data by mergeing it with the next buffer.

Error conditions: If the read value does not belong to this character set, one should replace it with the Unicode special 0xFFFD. When an actual input error is encountered, like a format error, the converter stop and return error. Hoever, we should keep in mind that we need to be lax in decoding.

Converter required behavior: In this order: when output space is full - return right away. When input data is wrong, return input pointer right after the wrong byte. When partial input, it will be consumed and cached. All the time input pointer will show how much was actually consumed and how much was actually written.

Parameters:
aSrc[IN] the source data buffer
aSrcLength[IN/OUT] the length of source data buffer; after conversion will contain the number of bytes read
aDest[OUT] the destination data buffer
aDestLength[IN/OUT] the length of the destination data buffer; after conversion will contain the number of Unicode characters written
Returns:
NS_PARTIAL_MORE_INPUT if only a partial conversion was done; more input is needed to continue NS_PARTIAL_MORE_OUTPUT if only a partial conversion was done; more output space is needed to continue NS_ERROR_ILLEGAL_INPUT if an illegal input sequence was encountered and the behavior was set to "signal"

Implements nsIUnicodeDecoder.

Definition at line 237 of file nsWinCEUConvService.cpp.

{
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  int count = MultiByteToWideChar(mCodepage,
                                  0,
                                  aSrc,
                                  *aSrcLength,
                                  aDest,
                                  *aDestLength);
  
  if (count == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
  {
    // fall back on the current system Windows "ANSI" code page
    count = MultiByteToWideChar(CP_ACP,
                                0,
                                aSrc,
                                *aSrcLength,
                                aDest,
                                *aDestLength);
  }
  
#ifdef ALERT_DBG
  if (count == 0)
    DisplayLastError("MultiByteToWideChar");
#endif
  
  *aDestLength = count;
  *aSrcLength  = count;
  return NS_OK;
}

Here is the call graph for this function:

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

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 318 of file nsWinCEUConvService.cpp.

{
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  char * defaultChar = "?";
  int count = WideCharToMultiByte(mCodepage,
                                  0,
                                  aSrc,
                                  *aSrcLength,
                                  aDest,
                                  *aDestLength,
                                  defaultChar,
                                  NULL);
  
#ifdef ALERT_DBG
  if (count == 0)
    DisplayLastError("WideCharToMultiByte");
#endif
  
  *aSrcLength = count;
  *aDestLength = count;
  
  return NS_OK;
}

Here is the call graph for this function:

Implements nsICharRepresentable.

Definition at line 391 of file nsWinCEUConvService.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP WinCEUConvAdapter::Finish ( char *  aDest,
PRInt32 aDestLength 
) [virtual]

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 349 of file nsWinCEUConvService.cpp.

{
  *aDestLength = 0;
  return NS_OK;
}
NS_IMETHODIMP WinCEUConvAdapter::GetMaxLength ( const char *  aSrc,
PRInt32  aSrcLength,
PRInt32 aDestLength 
) [virtual]

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_EXACT_LENGTH if an exact length was computed NS_OK is all we have is an approximation

Implements nsIUnicodeDecoder.

Definition at line 274 of file nsWinCEUConvService.cpp.

{
  if (mCodepage == -1 || aSrc == nsnull )
    return NS_ERROR_FAILURE;
  
  int count = MultiByteToWideChar(mCodepage,
                                  MB_PRECOMPOSED,
                                  aSrc,
                                  aSrcLength,
                                  NULL,
                                  NULL);
  
  if (count == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
  {
    // fall back on the current system Windows "ANSI" code page
    
    count = MultiByteToWideChar(CP_ACP,
                                MB_PRECOMPOSED,
                                aSrc,
                                aSrcLength,
                                NULL,
                                NULL);
  }
  
#ifdef ALERT_DBG  
  if (count == 0)
    DisplayLastError("MultiByteToWideChar (0)");
#endif
  
  *aDestLength = count;
  return NS_OK;
}

Here is the call graph for this function:

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

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 356 of file nsWinCEUConvService.cpp.

{
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  int count = WideCharToMultiByte(mCodepage,
                                  0,
                                  aSrc,
                                  aSrcLength,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL);
#ifdef ALERT_DBG
  if (count == 0)
    DisplayLastError("WideCharToMultiByte (0)");
#endif
  
  *aDestLength = count;
  return NS_OK;
}

Here is the call graph for this function:

nsresult WinCEUConvAdapter::Init ( const char *  from,
const char *  to 
)

Definition at line 203 of file nsWinCEUConvService.cpp.

{
  const char* cpstring = nsnull;
  
  if (!strcmp(from, "UCS-2"))
  {
    cpstring = to;
  }
  else
  {
    cpstring = from;
  }
  
  int i = 0;
  while (1)
  {
    if (theCsCPMap[i].charset[0] == nsnull)
      break;
    
    if (!strcmp(theCsCPMap[i].charset, cpstring))
    {
      mCodepage = theCsCPMap[i].codepage;
      break;
    }
    i++;
  }
  
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  return NS_OK;
}

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

Implements nsIUnicodeDecoder.

Definition at line 310 of file nsWinCEUConvService.cpp.

{
  return NS_OK;
}

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 383 of file nsWinCEUConvService.cpp.

{
  return NS_OK;
}

Member Data Documentation

Definition at line 123 of file nsWinCEUConvService.cpp.

Definition at line 87 of file nsWinCEUConvService.cpp.


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