Back to index

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

#include <nsScriptableUConv.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSISCRIPTABLEUNICODECONVERTER 
nsScriptableUnicodeConverter ()
virtual ~nsScriptableUnicodeConverter ()
ACString ConvertFromUnicode (in AString aSrc)
 Converts the data from Unicode to one Charset.
ACString Finish ()
 Returns the terminator string.
AString ConvertToUnicode (in ACString aSrc)
 Converts the data from one Charset to Unicode.
AString convertFromByteArray ([const, array, size_is(aCount)] in octet aData, in unsigned long aCount)
 Converts an array of bytes to a unicode string.
void convertToByteArray (in AString aString, out unsigned long aLen,[array, size_is(aLen), retval] out octet aData)
 Convert a unicode string to an array of bytes.
nsIInputStream convertToInputStream (in AString aString)
 Converts a unicode string to an input stream.

Public Attributes

attribute string charset
 Current character set.

Protected Member Functions

nsresult FinishWithLength (char **_retval, PRInt32 *aLength)
nsresult ConvertFromUnicodeWithLength (const nsAString &aSrc, PRInt32 *aOutLen, char **_retval)
nsresult InitConverter ()

Protected Attributes

nsCAutoString mCharset
nsCOMPtr< nsIUnicodeEncodermEncoder
nsCOMPtr< nsIUnicodeDecodermDecoder

Detailed Description

Definition at line 47 of file nsScriptableUConv.h.


Constructor & Destructor Documentation

Definition at line 57 of file nsScriptableUConv.cpp.

Here is the call graph for this function:

Definition at line 62 of file nsScriptableUConv.cpp.

Here is the call graph for this function:


Member Function Documentation

AString nsIScriptableUnicodeConverter::convertFromByteArray ( [const, array, size_is(aCount)] in octet  aData,
in unsigned long  aCount 
) [inherited]

Converts an array of bytes to a unicode string.

ACString nsIScriptableUnicodeConverter::ConvertFromUnicode ( in AString  aSrc) [inherited]

Converts the data from Unicode to one Charset.

Returns the converted string. After converting, Finish should be called and its return value appended to this return value.

nsresult nsScriptableUnicodeConverter::ConvertFromUnicodeWithLength ( const nsAString &  aSrc,
PRInt32 aOutLen,
char **  _retval 
) [protected]

Definition at line 68 of file nsScriptableUConv.cpp.

{
  if (!mEncoder)
    return NS_ERROR_FAILURE;

  nsresult rv = NS_OK;
  PRInt32 inLength = aSrc.Length();
  const nsAFlatString& flatSrc = PromiseFlatString(aSrc);
  rv = mEncoder->GetMaxLength(flatSrc.get(), inLength, aOutLen);
  if (NS_SUCCEEDED(rv)) {
    *_retval = (char*) nsMemory::Alloc(*aOutLen+1);
    if (!*_retval)
      return NS_ERROR_OUT_OF_MEMORY;

    rv = mEncoder->Convert(flatSrc.get(), &inLength, *_retval, aOutLen);
    if (NS_SUCCEEDED(rv))
    {
      (*_retval)[*aOutLen] = '\0';
      return NS_OK;
    }
    nsMemory::Free(*_retval);
  }
  *_retval = nsnull;
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

void nsIScriptableUnicodeConverter::convertToByteArray ( in AString  aString,
out unsigned long  aLen,
[array, size_is(aLen), retval] out octet  aData 
) [inherited]

Convert a unicode string to an array of bytes.

Finish does not need to be called.

Converts a unicode string to an input stream.

The bytes in the stream are encoded according to the charset attribute. The returned stream will be nonblocking.

AString nsIScriptableUnicodeConverter::ConvertToUnicode ( in ACString  aSrc) [inherited]

Converts the data from one Charset to Unicode.

ACString nsIScriptableUnicodeConverter::Finish ( ) [inherited]

Returns the terminator string.

Should be called after ConvertFromUnicode() and appended to that function's return value.

nsresult nsScriptableUnicodeConverter::FinishWithLength ( char **  _retval,
PRInt32 aLength 
) [protected]

Definition at line 113 of file nsScriptableUConv.cpp.

{
  if (!mEncoder)
    return NS_ERROR_FAILURE;

  PRInt32 finLength = 32;

  *_retval = (char *) nsMemory::Alloc(finLength);
  if (!*_retval)
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv = mEncoder->Finish(*_retval, &finLength);
  if (NS_SUCCEEDED(rv))
    (*_retval)[finLength] = '\0';
  else
    nsMemory::Free(*_retval);

  *aLength = finLength;

  return rv;

}

Here is the call graph for this function:

Definition at line 275 of file nsScriptableUConv.cpp.

{
  nsresult rv = NS_OK;
  mEncoder = NULL ;

  nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);

  if (NS_SUCCEEDED( rv) && (nsnull != ccm)) {
    // get charset atom due to getting unicode converter
    
    // get an unicode converter
    rv = ccm->GetUnicodeEncoder(mCharset.get(), getter_AddRefs(mEncoder));
    if(NS_SUCCEEDED(rv)) {
      rv = mEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?');
      if(NS_SUCCEEDED(rv)) {
        rv = ccm->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mDecoder));
      }
    }
  }

  return rv ;
}

Here is the call graph for this function:


Member Data Documentation

Current character set.

Exceptions:
NS_ERROR_UCONV_NOCONVThe requested charset is not supported.

Definition at line 103 of file nsIScriptableUConv.idl.

Definition at line 59 of file nsScriptableUConv.h.

Definition at line 61 of file nsScriptableUConv.h.

Definition at line 60 of file nsScriptableUConv.h.


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