Back to index

lightning-sunbird  0.9+nobinonly
Functions
a2w.cpp File Reference
#include "mozce_internal.h"

Go to the source code of this file.

Functions

int a2w_buffer (const char *inACPString, int inACPChars, unsigned short *outWideString, int inWideChars)
unsigned short * a2w_malloc (const char *inACPString, int inACPChars, int *outWideChars)

Function Documentation

int a2w_buffer ( const char *  inACPString,
int  inACPChars,
unsigned short *  outWideString,
int  inWideChars 
)

Definition at line 43 of file a2w.cpp.

{
    int retval = 0;
    
    /*
    **  Start off by terminating the out argument if appropriate.
    */
    if(NULL != outWideString && 0 != inWideChars)
    {
        *outWideString = L'\0';
    }
    
    /*
    **  Sanity check arguments.
    */
    if(NULL != inACPString && 0 != inACPChars && (0 == inWideChars || NULL != outWideString))
    {
        /*
        **  Attempt the conversion.
        */
        retval = MultiByteToWideChar(
                                     CP_ACP,
                                     0,
                                     inACPString,
                                     inACPChars,
                                     outWideString,
                                     inWideChars
                                     );
    }
    
    return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned short* a2w_malloc ( const char *  inACPString,
int  inACPChars,
int outWideChars 
)

Definition at line 77 of file a2w.cpp.

{
    LPWSTR retval = NULL;
    
    /*
    **  Initialize any out arguments.
    */
    if(NULL != outWideChars)
    {
        *outWideChars = 0;
    }
    
    /*
    **  Initialize the acp char length if requested.
    **  We do this here to avoid doing it twice in calls to a2w_buffer.
    */
    if(-1 == inACPChars)
    {
        if(NULL != inACPString)
        {
            /*
            **  Plus one so the terminating character is included.
            */
            inACPChars = (int)strlen(inACPString) + 1;
        }
        else
        {
            inACPChars = 0;
        }
    }
    
    /*
    **  Sanity check arguments.
    */
    if(NULL != inACPString && 0 != inACPChars)
    {
        int charsRequired = 0;
        
        /*
        **  Determine the size of buffer required for the conversion.
        */
        charsRequired = a2w_buffer(inACPString, inACPChars, NULL, 0);
        if(0 != charsRequired)
        {
            LPWSTR heapBuffer = NULL;
            
            heapBuffer = (LPWSTR)malloc((size_t)charsRequired * sizeof(WCHAR));
            if(NULL != heapBuffer)
            {
                int wideChars = 0;
                
                /*
                **  Real thing this time.
                */
                wideChars = a2w_buffer(inACPString, inACPChars, heapBuffer, charsRequired);
                if(0 != wideChars)
                {
                    retval = heapBuffer;
                    if(NULL != outWideChars)
                    {
                        *outWideChars = wideChars;
                    }
                }
                else
                {
                    /*
                    **  Something wrong.
                    **  Clean up.
                    */
                    free(heapBuffer);
                }
            }
        }
    }
    
    return retval;
}

Here is the call graph for this function: