Ignore:
Timestamp:
Sep 18, 2012, 8:13:51 PM (13 years ago)
Author:
abwillis
Message:

ADD GetCPInfoExA and GetCPInfoExW part of ticket #25.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/codepage.c

    r21916 r22017  
    194194
    195195/***********************************************************************
    196  *           GetCPInfo   (KERNEL32)
     196 *           GetCPInfo   (KERNEL32.@)
     197 *
     198 * Get information about a code page.
     199 *
     200 * PARAMS
     201 *  codepage [I] Code page number
     202 *  cpinfo   [O] Destination for code page information
     203 *
     204 * RETURNS
     205 *  Success: TRUE. cpinfo is updated with the information about codepage.
     206 *  Failure: FALSE, if codepage is invalid or cpinfo is NULL.
    197207 */
    198208BOOL WINAPI GetCPInfo( UINT codepage, LPCPINFO cpinfo )
    199209{
    200     const union cptable *table = get_codepage_table( codepage );
     210    const union cptable *table;
    201211
    202212#ifdef __WIN32OS2__
     
    204214#endif
    205215
    206     if (!table)
    207     {
     216    if (!cpinfo)
     217    {
     218        SetLastError( ERROR_INVALID_PARAMETER );
     219        return FALSE;
     220    }
     221
     222    if (!(table = get_codepage_table( codepage )))
     223    {
     224        switch(codepage)
     225        {
     226            case CP_UTF7:
     227            case CP_UTF8:
     228                cpinfo->DefaultChar[0] = 0x3f;
     229                cpinfo->DefaultChar[1] = 0;
     230                cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
     231                cpinfo->MaxCharSize = (codepage == CP_UTF7) ? 5 : 4;
     232                return TRUE;
     233        }
     234
    208235        SetLastError( ERROR_INVALID_PARAMETER );
    209236        return FALSE;
     
    224251        cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
    225252
     253    return TRUE;
     254}
     255
     256/***********************************************************************
     257 *           GetCPInfoExA   (KERNEL32.@)
     258 *
     259 * Get extended information about a code page.
     260 *
     261 * PARAMS
     262 *  codepage [I] Code page number
     263 *  dwFlags  [I] Reserved, must to 0.
     264 *  cpinfo   [O] Destination for code page information
     265 *
     266 * RETURNS
     267 *  Success: TRUE. cpinfo is updated with the information about codepage.
     268 *  Failure: FALSE, if codepage is invalid or cpinfo is NULL.
     269 */
     270BOOL WINAPI GetCPInfoExA( UINT codepage, DWORD dwFlags, LPCPINFOEXA cpinfo )
     271{
     272    CPINFOEXW cpinfoW;
     273
     274    if (!GetCPInfoExW( codepage, dwFlags, &cpinfoW ))
     275      return FALSE;
     276
     277    /* the layout is the same except for CodePageName */
     278    memcpy(cpinfo, &cpinfoW, sizeof(CPINFOEXA));
     279    WideCharToMultiByte(CP_ACP, 0, cpinfoW.CodePageName, -1, cpinfo->CodePageName, sizeof(cpinfo->CodePageName), NULL, NULL);
     280    return TRUE;
     281}
     282
     283/***********************************************************************
     284 *           GetCPInfoExW   (KERNEL32.@)
     285 *
     286 * Unicode version of GetCPInfoExA.
     287 */
     288BOOL WINAPI GetCPInfoExW( UINT codepage, DWORD dwFlags, LPCPINFOEXW cpinfo )
     289{
     290    if (!GetCPInfo( codepage, (LPCPINFO)cpinfo ))
     291      return FALSE;
     292
     293    switch(codepage)
     294    {
     295        case CP_UTF7:
     296        {
     297            static const WCHAR utf7[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','7',')',0};
     298
     299            cpinfo->CodePage = CP_UTF7;
     300            cpinfo->UnicodeDefaultChar = 0x3f;
     301            strcpyW(cpinfo->CodePageName, utf7);
     302            break;
     303        }
     304
     305        case CP_UTF8:
     306        {
     307            static const WCHAR utf8[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','8',')',0};
     308
     309            cpinfo->CodePage = CP_UTF8;
     310            cpinfo->UnicodeDefaultChar = 0x3f;
     311            strcpyW(cpinfo->CodePageName, utf8);
     312            break;
     313        }
     314
     315        default:
     316        {
     317            const union cptable *table = get_codepage_table( codepage );
     318
     319            cpinfo->CodePage = table->info.codepage;
     320            cpinfo->UnicodeDefaultChar = table->info.def_unicode_char;
     321            MultiByteToWideChar( CP_ACP, 0, table->info.name, -1, cpinfo->CodePageName,
     322                                 sizeof(cpinfo->CodePageName)/sizeof(WCHAR));
     323            break;
     324        }
     325    }
    226326    return TRUE;
    227327}
Note: See TracChangeset for help on using the changeset viewer.