Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes
CPlatformUCSConversion Class Reference

#include <UMacUnicode.h>

Collaboration diagram for CPlatformUCSConversion:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CPlatformUCSConversion ()
virtual ~CPlatformUCSConversion ()
NS_IMETHOD UCSToPlatform (const nsAString &aIn, nsACString &aOut)
NS_IMETHOD UCSToPlatform (const nsAString &aIn, Str255 &aOut)
NS_IMETHOD PlatformToUCS (const nsACString &ain, nsAString &aOut)
NS_IMETHOD PlatformToUCS (const Str255 &aIn, nsAString &aOut)

Static Public Member Functions

static CPlatformUCSConversionGetInstance ()

Private Member Functions

nsresult PrepareEncoder ()
nsresult PrepareDecoder ()

Static Private Attributes

static CPlatformUCSConversionmgInstance = nsnull
static UnicodeToTextInfo sEncoderInfo = nsnull
static TextToUnicodeInfo sDecoderInfo = nsnull

Detailed Description

Definition at line 48 of file UMacUnicode.h.


Constructor & Destructor Documentation

Definition at line 65 of file UMacUnicode.cpp.

{
}

Here is the caller graph for this function:

virtual CPlatformUCSConversion::~CPlatformUCSConversion ( ) [inline, virtual]

Definition at line 51 of file UMacUnicode.h.

{};

Member Function Documentation

Definition at line 71 of file UMacUnicode.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP CPlatformUCSConversion::PlatformToUCS ( const nsACString &  ain,
nsAString &  aOut 
)

Definition at line 175 of file UMacUnicode.cpp.

{
    nsresult rv = PrepareDecoder();
    if (NS_FAILED(rv)) return rv;
    
    OSStatus err = noErr;
    UniChar stackBuffer[512];

    aOut.Truncate(0);
    nsReadingIterator<char> done_reading;
    aIn.EndReading(done_reading);

    // for each chunk of |aIn|...
    PRUint32 fragmentLength = 0;
    nsReadingIterator<char> iter;
    for (aIn.BeginReading(iter); iter != done_reading && err == noErr; iter.advance(PRInt32(fragmentLength)))
    {
        fragmentLength = PRUint32(iter.size_forward());        
        UInt32 bytesLeft = fragmentLength;
        nsReadingIterator<char> sub_iter(iter);
        
        do {
            UInt32 bytesRead = 0, bytesWritten = 0;
            err = ::ConvertFromTextToUnicode(sDecoderInfo,
                                             bytesLeft,
                                             sub_iter.get(),
                                             kUnicodeUseFallbacksMask | kUnicodeLooseMappingsMask,
                                             0, nsnull, nsnull, nsnull,
                                             sizeof(stackBuffer),
                                             &bytesRead,
                                             &bytesWritten,
                                             stackBuffer);
            if (err == kTECUsedFallbacksStatus)
                err = noErr;
            else if (err == kTECOutputBufferFullStatus) {
                bytesLeft -= bytesRead;
                sub_iter.advance(bytesRead);
            }
            aOut.Append((PRUnichar *)stackBuffer, bytesWritten / sizeof(PRUnichar));
        }
        while (err == kTECOutputBufferFullStatus);
    }
    return (err == noErr) ? NS_OK : NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP CPlatformUCSConversion::PlatformToUCS ( const Str255 &  aIn,
nsAString &  aOut 
)

Definition at line 221 of file UMacUnicode.cpp.

{
    char charBuf[256];
    
    memcpy(charBuf, &aIn[1], aIn[0]);
    charBuf[aIn[0]] = '\0';
    return PlatformToUCS(nsDependentCString(charBuf, aIn[0]), aOut);
}

Here is the call graph for this function:

Definition at line 95 of file UMacUnicode.cpp.

{
    nsresult rv = NS_OK;
    if (!sDecoderInfo) {
        OSStatus err;
        err = ::CreateTextToUnicodeInfoByEncoding(getSystemEncoding(), &sDecoderInfo);
        if (err)
            rv = NS_ERROR_FAILURE;
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file UMacUnicode.cpp.

{
    nsresult rv = NS_OK;
    if (!sEncoderInfo) {
        OSStatus err;
        err = ::CreateUnicodeToTextInfoByEncoding(getSystemEncoding(), &sEncoderInfo);
        if (err)
            rv = NS_ERROR_FAILURE;
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP CPlatformUCSConversion::UCSToPlatform ( const nsAString &  aIn,
nsACString &  aOut 
)

Definition at line 109 of file UMacUnicode.cpp.

{
    nsresult rv = PrepareEncoder();
    if (NS_FAILED(rv)) return rv;
    
    OSStatus err = noErr;
    char stackBuffer[512];

    aOut.Truncate(0);
    nsReadingIterator<PRUnichar> done_reading;
    aIn.EndReading(done_reading);

    // for each chunk of |aIn|...
    PRUint32 fragmentLength = 0;
    nsReadingIterator<PRUnichar> iter;
    for (aIn.BeginReading(iter); iter != done_reading && err == noErr; iter.advance(PRInt32(fragmentLength)))
    {
        fragmentLength = PRUint32(iter.size_forward());        
        UInt32 bytesLeft = fragmentLength * sizeof(UniChar);
        nsReadingIterator<PRUnichar> sub_iter(iter);
        
        do {
            UInt32 bytesRead = 0, bytesWritten = 0;
            err = ::ConvertFromUnicodeToText(sEncoderInfo,
                                             bytesLeft,
                                             (const UniChar*)sub_iter.get(),
                                             kUnicodeUseFallbacksMask | kUnicodeLooseMappingsMask,
                                             0, nsnull, nsnull, nsnull,
                                             sizeof(stackBuffer),
                                             &bytesRead,
                                             &bytesWritten,
                                             stackBuffer);
            if (err == kTECUsedFallbacksStatus)
                err = noErr;
            else if (err == kTECOutputBufferFullStatus) {
                bytesLeft -= bytesRead;
                sub_iter.advance(bytesRead / sizeof(UniChar));
            }
            aOut.Append(stackBuffer, bytesWritten);
        }
        while (err == kTECOutputBufferFullStatus);
    }
    return (err == noErr) ? NS_OK : NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP CPlatformUCSConversion::UCSToPlatform ( const nsAString &  aIn,
Str255 &  aOut 
)

Definition at line 156 of file UMacUnicode.cpp.

{
    nsresult res;
    nsCAutoString cStr;
    
    res = UCSToPlatform(aIn, cStr);
    if (NS_SUCCEEDED(res))
    {
        PRUint32 outLength = cStr.Length();
        if (outLength > 255)
            outLength = 255;
        memcpy(&aOut[1], cStr.get(), outLength);
        aOut[0] = outLength;
    }
    return res;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 62 of file UMacUnicode.h.

TextToUnicodeInfo CPlatformUCSConversion::sDecoderInfo = nsnull [static, private]

Definition at line 64 of file UMacUnicode.h.

UnicodeToTextInfo CPlatformUCSConversion::sEncoderInfo = nsnull [static, private]

Definition at line 63 of file UMacUnicode.h.


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