| 1 | /*
|
|---|
| 2 | * Code page functions
|
|---|
| 3 | *
|
|---|
| 4 | * Based on Wine code (memory\codepage.c)
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 2000 Alexandre Julliard
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #include <assert.h>
|
|---|
| 13 | #include <stdio.h>
|
|---|
| 14 | #include <stdlib.h>
|
|---|
| 15 | #include <string.h>
|
|---|
| 16 |
|
|---|
| 17 | #include "winbase.h"
|
|---|
| 18 | #include "winerror.h"
|
|---|
| 19 | #include "winnls.h"
|
|---|
| 20 | #include "wine/unicode.h"
|
|---|
| 21 | #include "debugtools.h"
|
|---|
| 22 |
|
|---|
| 23 | #ifdef __WIN32OS2__
|
|---|
| 24 | #include <options.h>
|
|---|
| 25 | #include "codepage.h"
|
|---|
| 26 |
|
|---|
| 27 | #define DBG_LOCALLOG DBG_codepage
|
|---|
| 28 | #include "dbglocal.h"
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | DEFAULT_DEBUG_CHANNEL(string);
|
|---|
| 32 |
|
|---|
| 33 | /* current code pages */
|
|---|
| 34 | static const union cptable *ansi_cptable;
|
|---|
| 35 | static const union cptable *oem_cptable;
|
|---|
| 36 | static const union cptable *mac_cptable;
|
|---|
| 37 |
|
|---|
| 38 | /* retrieve a code page table from the locale info */
|
|---|
| 39 | static const union cptable *get_locale_cp( LCID lcid, LCTYPE type )
|
|---|
| 40 | {
|
|---|
| 41 | const union cptable *table = NULL;
|
|---|
| 42 | char buf[32];
|
|---|
| 43 |
|
|---|
| 44 | if (GetLocaleInfoA( lcid, type, buf, sizeof(buf) )) table = cp_get_table( atoi(buf) );
|
|---|
| 45 | return table;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | /* setup default codepage info before we can get at the locale stuff */
|
|---|
| 49 | static void init_codepages(void)
|
|---|
| 50 | {
|
|---|
| 51 | ansi_cptable = cp_get_table( 1252 );
|
|---|
| 52 | oem_cptable = cp_get_table( 437 );
|
|---|
| 53 | mac_cptable = cp_get_table( 10000 );
|
|---|
| 54 | assert( ansi_cptable );
|
|---|
| 55 | assert( oem_cptable );
|
|---|
| 56 | assert( mac_cptable );
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /* find the table for a given codepage, handling CP_ACP etc. pseudo-codepages */
|
|---|
| 60 | static const union cptable *get_codepage_table( unsigned int codepage )
|
|---|
| 61 | {
|
|---|
| 62 | const union cptable *ret = NULL;
|
|---|
| 63 |
|
|---|
| 64 | if (!ansi_cptable) init_codepages();
|
|---|
| 65 |
|
|---|
| 66 | switch(codepage)
|
|---|
| 67 | {
|
|---|
| 68 | case CP_ACP: return ansi_cptable;
|
|---|
| 69 | case CP_OEMCP: return oem_cptable;
|
|---|
| 70 | case CP_MACCP: return mac_cptable;
|
|---|
| 71 | case CP_THREAD_ACP: return get_locale_cp( GetThreadLocale(), LOCALE_IDEFAULTANSICODEPAGE );
|
|---|
| 72 | case CP_UTF7:
|
|---|
| 73 | case CP_UTF8:
|
|---|
| 74 | break;
|
|---|
| 75 | default:
|
|---|
| 76 | if (codepage == ansi_cptable->info.codepage) return ansi_cptable;
|
|---|
| 77 | if (codepage == oem_cptable->info.codepage) return oem_cptable;
|
|---|
| 78 | if (codepage == mac_cptable->info.codepage) return mac_cptable;
|
|---|
| 79 | ret = cp_get_table( codepage );
|
|---|
| 80 | break;
|
|---|
| 81 | }
|
|---|
| 82 | return ret;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | /* initialize default code pages from locale info */
|
|---|
| 86 | /* FIXME: should be done in init_codepages, but it can't right now */
|
|---|
| 87 | /* since it needs KERNEL32 to be loaded for the locale info. */
|
|---|
| 88 | void CODEPAGE_Init(void)
|
|---|
| 89 | {
|
|---|
| 90 | const union cptable *table;
|
|---|
| 91 | LCID lcid = GetUserDefaultLCID();
|
|---|
| 92 |
|
|---|
| 93 | if (!ansi_cptable) init_codepages(); /* just in case */
|
|---|
| 94 |
|
|---|
| 95 | if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTANSICODEPAGE ))) ansi_cptable = table;
|
|---|
| 96 | if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTMACCODEPAGE ))) mac_cptable = table;
|
|---|
| 97 | if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTCODEPAGE ))) oem_cptable = table;
|
|---|
| 98 |
|
|---|
| 99 | TRACE( "ansi=%03d oem=%03d mac=%03d\n", ansi_cptable->info.codepage,
|
|---|
| 100 | oem_cptable->info.codepage, mac_cptable->info.codepage );
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | #ifdef __WIN32OS2__
|
|---|
| 104 | ULONG GetDisplayCodepage()
|
|---|
| 105 | {
|
|---|
| 106 | if (!ansi_cptable) CODEPAGE_Init();
|
|---|
| 107 |
|
|---|
| 108 | return ansi_cptable->info.codepage;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | ULONG GetWindowsCodepage()
|
|---|
| 112 | {
|
|---|
| 113 | if (!ansi_cptable) CODEPAGE_Init();
|
|---|
| 114 |
|
|---|
| 115 | return ansi_cptable->info.codepage;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static UconvObject GetObjectByCP(ULONG codepage)
|
|---|
| 119 | {
|
|---|
| 120 | UconvObject rc = 0;
|
|---|
| 121 | UniChar codepage_str[12];
|
|---|
| 122 |
|
|---|
| 123 | BOOL ret = UniMapCpToUcsCp(codepage, codepage_str, sizeof(codepage_str));
|
|---|
| 124 | if ( ret == ULS_SUCCESS )
|
|---|
| 125 | {
|
|---|
| 126 | ret = UniCreateUconvObject( codepage_str, &rc );
|
|---|
| 127 | if ( ret != ULS_SUCCESS )
|
|---|
| 128 | rc = 0;
|
|---|
| 129 | }
|
|---|
| 130 | dprintf(("UniCreateUconvObject for CP %d (%08x)\n", codepage, rc ));
|
|---|
| 131 | return rc;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | static UconvObject DisplayUconv = NULL;
|
|---|
| 135 | static UconvObject WindowsUconv = NULL;
|
|---|
| 136 |
|
|---|
| 137 | UconvObject GetDisplayUconvObject()
|
|---|
| 138 | {
|
|---|
| 139 | if (!DisplayUconv)
|
|---|
| 140 | DisplayUconv = GetObjectByCP(GetDisplayCodepage());
|
|---|
| 141 |
|
|---|
| 142 | return DisplayUconv;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | UconvObject GetWindowsUconvObject()
|
|---|
| 146 | {
|
|---|
| 147 | if (!WindowsUconv)
|
|---|
| 148 | WindowsUconv = GetObjectByCP(GetWindowsCodepage());
|
|---|
| 149 |
|
|---|
| 150 | return WindowsUconv;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | #endif
|
|---|
| 154 |
|
|---|
| 155 | /******************************************************************************
|
|---|
| 156 | * GetACP (KERNEL32)
|
|---|
| 157 | *
|
|---|
| 158 | * RETURNS
|
|---|
| 159 | * Current ANSI code-page identifier, default if no current defined
|
|---|
| 160 | */
|
|---|
| 161 | UINT WINAPI GetACP(void)
|
|---|
| 162 | {
|
|---|
| 163 | if (!ansi_cptable) init_codepages();
|
|---|
| 164 | #ifdef __WIN32OS2__
|
|---|
| 165 | dprintf(("GetACP %d", ansi_cptable->info.codepage));
|
|---|
| 166 | #endif
|
|---|
| 167 | return ansi_cptable->info.codepage;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 | /***********************************************************************
|
|---|
| 172 | * GetOEMCP (KERNEL32)
|
|---|
| 173 | */
|
|---|
| 174 | UINT WINAPI GetOEMCP(void)
|
|---|
| 175 | {
|
|---|
| 176 | if (!oem_cptable) init_codepages();
|
|---|
| 177 | #ifdef __WIN32OS2__
|
|---|
| 178 | dprintf(("GetOEMCP %d", oem_cptable->info.codepage));
|
|---|
| 179 | #endif
|
|---|
| 180 | return oem_cptable->info.codepage;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 | /***********************************************************************
|
|---|
| 185 | * IsValidCodePage (KERNEL32)
|
|---|
| 186 | */
|
|---|
| 187 | BOOL WINAPI IsValidCodePage( UINT codepage )
|
|---|
| 188 | {
|
|---|
| 189 | #ifdef __WIN32OS2__
|
|---|
| 190 | dprintf(("IsValidCodePage %d", codepage));
|
|---|
| 191 | #endif
|
|---|
| 192 | return cp_get_table( codepage ) != NULL;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | /***********************************************************************
|
|---|
| 197 | * IsDBCSLeadByteEx (KERNEL32)
|
|---|
| 198 | */
|
|---|
| 199 | BOOL WINAPI IsDBCSLeadByteEx( UINT codepage, BYTE testchar )
|
|---|
| 200 | {
|
|---|
| 201 | #ifdef __WIN32OS2__
|
|---|
| 202 | dprintf2(("IsDBCSLeadByteEx %d %x", codepage, testchar));
|
|---|
| 203 | #endif
|
|---|
| 204 |
|
|---|
| 205 | const union cptable *table = get_codepage_table( codepage );
|
|---|
| 206 | return table && is_dbcs_leadbyte( table, testchar );
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | /***********************************************************************
|
|---|
| 211 | * IsDBCSLeadByte (KERNEL32)
|
|---|
| 212 | */
|
|---|
| 213 | BOOL WINAPI IsDBCSLeadByte( BYTE testchar )
|
|---|
| 214 | {
|
|---|
| 215 | if (!ansi_cptable) init_codepages();
|
|---|
| 216 | return is_dbcs_leadbyte( ansi_cptable, testchar );
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 | /***********************************************************************
|
|---|
| 221 | * GetCPInfo (KERNEL32)
|
|---|
| 222 | */
|
|---|
| 223 | BOOL WINAPI GetCPInfo( UINT codepage, LPCPINFO cpinfo )
|
|---|
| 224 | {
|
|---|
| 225 | const union cptable *table = get_codepage_table( codepage );
|
|---|
| 226 |
|
|---|
| 227 | #ifdef __WIN32OS2__
|
|---|
| 228 | dprintf(("GetCPInfo %d %x", codepage, cpinfo));
|
|---|
| 229 | #endif
|
|---|
| 230 |
|
|---|
| 231 | if (!table)
|
|---|
| 232 | {
|
|---|
| 233 | SetLastError( ERROR_INVALID_PARAMETER );
|
|---|
| 234 | return FALSE;
|
|---|
| 235 | }
|
|---|
| 236 | if (table->info.def_char & 0xff00)
|
|---|
| 237 | {
|
|---|
| 238 | cpinfo->DefaultChar[0] = table->info.def_char & 0xff00;
|
|---|
| 239 | cpinfo->DefaultChar[1] = table->info.def_char & 0x00ff;
|
|---|
| 240 | }
|
|---|
| 241 | else
|
|---|
| 242 | {
|
|---|
| 243 | cpinfo->DefaultChar[0] = table->info.def_char & 0xff;
|
|---|
| 244 | cpinfo->DefaultChar[1] = 0;
|
|---|
| 245 | }
|
|---|
| 246 | if ((cpinfo->MaxCharSize = table->info.char_size) == 2)
|
|---|
| 247 | memcpy( cpinfo->LeadByte, table->dbcs.lead_bytes, sizeof(cpinfo->LeadByte) );
|
|---|
| 248 | else
|
|---|
| 249 | cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
|
|---|
| 250 |
|
|---|
| 251 | return TRUE;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 | /***********************************************************************
|
|---|
| 256 | * EnumSystemCodePagesA (KERNEL32)
|
|---|
| 257 | */
|
|---|
| 258 | BOOL WINAPI EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum, DWORD flags )
|
|---|
| 259 | {
|
|---|
| 260 | const union cptable *table;
|
|---|
| 261 | char buffer[10];
|
|---|
| 262 | int index = 0;
|
|---|
| 263 |
|
|---|
| 264 | #ifdef __WIN32OS2__
|
|---|
| 265 | dprintf(("EnumSystemCodePagesA %x %x", lpfnCodePageEnum, flags));
|
|---|
| 266 | #endif
|
|---|
| 267 |
|
|---|
| 268 | for (;;)
|
|---|
| 269 | {
|
|---|
| 270 | if (!(table = cp_enum_table( index++ ))) break;
|
|---|
| 271 | sprintf( buffer, "%d", table->info.codepage );
|
|---|
| 272 | if (!lpfnCodePageEnum( buffer )) break;
|
|---|
| 273 | }
|
|---|
| 274 | return TRUE;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 | /***********************************************************************
|
|---|
| 279 | * EnumSystemCodePagesW (KERNEL32)
|
|---|
| 280 | */
|
|---|
| 281 | BOOL WINAPI EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags )
|
|---|
| 282 | {
|
|---|
| 283 | const union cptable *table;
|
|---|
| 284 | WCHAR buffer[10], *p;
|
|---|
| 285 | int page, index = 0;
|
|---|
| 286 |
|
|---|
| 287 | #ifdef __WIN32OS2__
|
|---|
| 288 | dprintf(("EnumSystemCodePagesW %x %x", lpfnCodePageEnum, flags));
|
|---|
| 289 | #endif
|
|---|
| 290 |
|
|---|
| 291 | for (;;)
|
|---|
| 292 | {
|
|---|
| 293 | if (!(table = cp_enum_table( index++ ))) break;
|
|---|
| 294 | p = buffer + sizeof(buffer)/sizeof(WCHAR);
|
|---|
| 295 | *--p = 0;
|
|---|
| 296 | page = table->info.codepage;
|
|---|
| 297 | do
|
|---|
| 298 | {
|
|---|
| 299 | *--p = '0' + (page % 10);
|
|---|
| 300 | page /= 10;
|
|---|
| 301 | } while( page );
|
|---|
| 302 | if (!lpfnCodePageEnum( p )) break;
|
|---|
| 303 | }
|
|---|
| 304 | return TRUE;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 | /***********************************************************************
|
|---|
| 309 | * MultiByteToWideChar (KERNEL32)
|
|---|
| 310 | *
|
|---|
| 311 | * PARAMS
|
|---|
| 312 | * page [in] Codepage character set to convert from
|
|---|
| 313 | * flags [in] Character mapping flags
|
|---|
| 314 | * src [in] Source string buffer
|
|---|
| 315 | * srclen [in] Length of source string buffer
|
|---|
| 316 | * dst [in] Destination buffer
|
|---|
| 317 | * dstlen [in] Length of destination buffer
|
|---|
| 318 | *
|
|---|
| 319 | * NOTES
|
|---|
| 320 | * The returned length includes the null terminator character.
|
|---|
| 321 | *
|
|---|
| 322 | * RETURNS
|
|---|
| 323 | * Success: If dstlen > 0, number of characters written to destination
|
|---|
| 324 | * buffer. If dstlen == 0, number of characters needed to do
|
|---|
| 325 | * conversion.
|
|---|
| 326 | * Failure: 0. Occurs if not enough space is available.
|
|---|
| 327 | *
|
|---|
| 328 | * ERRORS
|
|---|
| 329 | * ERROR_INSUFFICIENT_BUFFER
|
|---|
| 330 | * ERROR_INVALID_PARAMETER
|
|---|
| 331 | * ERROR_NO_UNICODE_TRANSLATION
|
|---|
| 332 | *
|
|---|
| 333 | */
|
|---|
| 334 | INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
|
|---|
| 335 | LPWSTR dst, INT dstlen )
|
|---|
| 336 | {
|
|---|
| 337 | const union cptable *table;
|
|---|
| 338 | int ret;
|
|---|
| 339 |
|
|---|
| 340 | #ifdef __WIN32OS2__
|
|---|
| 341 | dprintf2(("MultiByteToWideChar %d %x %x %d %x %d", page, flags, src, srclen, dst, dstlen));
|
|---|
| 342 | #endif
|
|---|
| 343 |
|
|---|
| 344 | //Docs say source ptr can't be the same as destination (Windows ME, NT4-SP6)
|
|---|
| 345 | if (!src || (!dst && dstlen) || ((void *)src == (void *)dst))
|
|---|
| 346 | {
|
|---|
| 347 | SetLastError( ERROR_INVALID_PARAMETER );
|
|---|
| 348 | return 0;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | //Even though the docs claim this only works for -1, testing shows it
|
|---|
| 352 | //is done for any negative value (Windows ME, NT4-SP6)
|
|---|
| 353 | if (srclen <= -1) srclen = strlen(src) + 1;
|
|---|
| 354 |
|
|---|
| 355 | if (flags & MB_USEGLYPHCHARS) FIXME("MB_USEGLYPHCHARS not supported\n");
|
|---|
| 356 |
|
|---|
| 357 | switch(page)
|
|---|
| 358 | {
|
|---|
| 359 | case CP_UTF7:
|
|---|
| 360 | FIXME("UTF not supported\n");
|
|---|
| 361 | SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|---|
| 362 | return 0;
|
|---|
| 363 | case CP_UTF8:
|
|---|
| 364 | ret = utf8_mbstowcs( flags, src, srclen, dst, dstlen );
|
|---|
| 365 | break;
|
|---|
| 366 | default:
|
|---|
| 367 | if (!(table = get_codepage_table( page )))
|
|---|
| 368 | {
|
|---|
| 369 | SetLastError( ERROR_INVALID_PARAMETER );
|
|---|
| 370 | return 0;
|
|---|
| 371 | }
|
|---|
| 372 | ret = cp_mbstowcs( table, flags, src, srclen, dst, dstlen );
|
|---|
| 373 | break;
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | if (ret < 0)
|
|---|
| 377 | {
|
|---|
| 378 | switch(ret)
|
|---|
| 379 | {
|
|---|
| 380 | case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break;
|
|---|
| 381 | case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break;
|
|---|
| 382 | }
|
|---|
| 383 | ret = 0;
|
|---|
| 384 | }
|
|---|
| 385 | return ret;
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 | /***********************************************************************
|
|---|
| 390 | * WideCharToMultiByte (KERNEL32)
|
|---|
| 391 | *
|
|---|
| 392 | * PARAMS
|
|---|
| 393 | * page [in] Codepage character set to convert to
|
|---|
| 394 | * flags [in] Character mapping flags
|
|---|
| 395 | * src [in] Source string buffer
|
|---|
| 396 | * srclen [in] Length of source string buffer
|
|---|
| 397 | * dst [in] Destination buffer
|
|---|
| 398 | * dstlen [in] Length of destination buffer
|
|---|
| 399 | * defchar [in] Default character to use for conversion if no exact
|
|---|
| 400 | * conversion can be made
|
|---|
| 401 | * used [out] Set if default character was used in the conversion
|
|---|
| 402 | *
|
|---|
| 403 | * NOTES
|
|---|
| 404 | * The returned length includes the null terminator character.
|
|---|
| 405 | *
|
|---|
| 406 | * RETURNS
|
|---|
| 407 | * Success: If dstlen > 0, number of characters written to destination
|
|---|
| 408 | * buffer. If dstlen == 0, number of characters needed to do
|
|---|
| 409 | * conversion.
|
|---|
| 410 | * Failure: 0. Occurs if not enough space is available.
|
|---|
| 411 | *
|
|---|
| 412 | * ERRORS
|
|---|
| 413 | * ERROR_INSUFFICIENT_BUFFER
|
|---|
| 414 | * ERROR_INVALID_PARAMETER
|
|---|
| 415 | */
|
|---|
| 416 | INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen,
|
|---|
| 417 | LPSTR dst, INT dstlen, LPCSTR defchar, BOOL *used )
|
|---|
| 418 | {
|
|---|
| 419 | const union cptable *table;
|
|---|
| 420 | int ret, used_tmp;
|
|---|
| 421 |
|
|---|
| 422 | #ifdef __WIN32OS2__
|
|---|
| 423 | dprintf2(("WideCharToMultiByte %d %x %x %d %x %d", page, flags, src, srclen, dst, dstlen));
|
|---|
| 424 | #endif
|
|---|
| 425 |
|
|---|
| 426 | //Docs say source ptr can't be the same as destination (Windows ME, NT4-SP6)
|
|---|
| 427 | if (!src || (!dst && dstlen) || ((void *)src == (void *)dst))
|
|---|
| 428 | {
|
|---|
| 429 | SetLastError( ERROR_INVALID_PARAMETER );
|
|---|
| 430 | return 0;
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | //Even though the docs claim this only works for -1, testing shows it
|
|---|
| 434 | //is done for any negative value (Windows ME, NT4 - SP6)
|
|---|
| 435 | if (srclen <= -1) srclen = strlenW(src) + 1;
|
|---|
| 436 |
|
|---|
| 437 | switch(page)
|
|---|
| 438 | {
|
|---|
| 439 | case CP_UTF7:
|
|---|
| 440 | FIXME("UTF-7 not supported\n");
|
|---|
| 441 | SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|---|
| 442 | return 0;
|
|---|
| 443 | case CP_UTF8:
|
|---|
| 444 | ret = utf8_wcstombs( src, srclen, dst, dstlen );
|
|---|
| 445 | break;
|
|---|
| 446 | default:
|
|---|
| 447 | if (!(table = get_codepage_table( page )))
|
|---|
| 448 | {
|
|---|
| 449 | SetLastError( ERROR_INVALID_PARAMETER );
|
|---|
| 450 | return 0;
|
|---|
| 451 | }
|
|---|
| 452 | ret = cp_wcstombs( table, flags, src, srclen, dst, dstlen,
|
|---|
| 453 | defchar, used ? &used_tmp : NULL );
|
|---|
| 454 | if (used) *used = used_tmp;
|
|---|
| 455 | break;
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | if (ret == -1)
|
|---|
| 459 | {
|
|---|
| 460 | SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|---|
| 461 | ret = 0;
|
|---|
| 462 | }
|
|---|
| 463 | return ret;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 | /******************************************************************************
|
|---|
| 468 | * GetStringTypeW (KERNEL32)
|
|---|
| 469 | *
|
|---|
| 470 | */
|
|---|
| 471 | BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
|
|---|
| 472 | {
|
|---|
| 473 | #ifdef __WIN32OS2__
|
|---|
| 474 | dprintf(("GetStringTypeW %x %x %d %x", type, src, count, chartype));
|
|---|
| 475 | #endif
|
|---|
| 476 |
|
|---|
| 477 | if (count == -1) count = strlenW(src) + 1;
|
|---|
| 478 | switch(type)
|
|---|
| 479 | {
|
|---|
| 480 | case CT_CTYPE1:
|
|---|
| 481 | while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
|
|---|
| 482 | break;
|
|---|
| 483 | case CT_CTYPE2:
|
|---|
| 484 | while (count--) *chartype++ = get_char_typeW( *src++ ) >> 12;
|
|---|
| 485 | break;
|
|---|
| 486 | case CT_CTYPE3:
|
|---|
| 487 | FIXME("CT_CTYPE3 not supported.\n");
|
|---|
| 488 | default:
|
|---|
| 489 | SetLastError( ERROR_INVALID_PARAMETER );
|
|---|
| 490 | return FALSE;
|
|---|
| 491 | }
|
|---|
| 492 | return TRUE;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 | /******************************************************************************
|
|---|
| 497 | * GetStringTypeExW (KERNEL32)
|
|---|
| 498 | */
|
|---|
| 499 | BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
|
|---|
| 500 | {
|
|---|
| 501 | /* locale is ignored for Unicode */
|
|---|
| 502 | return GetStringTypeW( type, src, count, chartype );
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | WCHAR WIN32API tolowerW( WCHAR ch )
|
|---|
| 506 | {
|
|---|
| 507 | extern const WCHAR casemap_lower[];
|
|---|
| 508 | return ch + casemap_lower[casemap_lower[ch >> 8] + (ch & 0xff)];
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 | WCHAR WIN32API toupperW( WCHAR ch )
|
|---|
| 512 | {
|
|---|
| 513 | extern const WCHAR casemap_upper[];
|
|---|
| 514 | return ch + casemap_upper[casemap_upper[ch >> 8] + (ch & 0xff)];
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | /* the character type contains the C1_* flags in the low 12 bits */
|
|---|
| 518 | /* and the C2_* type in the high 4 bits */
|
|---|
| 519 | unsigned short get_char_typeW( WCHAR ch )
|
|---|
| 520 | {
|
|---|
| 521 | extern const unsigned short wctype_table[];
|
|---|
| 522 | return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)];
|
|---|
| 523 | }
|
|---|