Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Code page functions |
| 3 | * |
| 4 | * Copyright 2000 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <assert.h> |
| 22 | #include <stdio.h> |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
James Juran | f4d5fef | 2001-01-26 20:43:40 +0000 | [diff] [blame] | 24 | #include <string.h> |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 25 | |
| 26 | #include "winbase.h" |
| 27 | #include "winerror.h" |
| 28 | #include "winnls.h" |
| 29 | #include "wine/unicode.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 30 | #include "wine/debug.h" |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 32 | WINE_DEFAULT_DEBUG_CHANNEL(string); |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 33 | |
| 34 | /* current code pages */ |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 35 | static const union cptable *ansi_cptable; |
| 36 | static const union cptable *oem_cptable; |
| 37 | static const union cptable *mac_cptable; |
| 38 | |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 39 | /* retrieve a code page table from the locale info */ |
| 40 | static const union cptable *get_locale_cp( LCID lcid, LCTYPE type ) |
| 41 | { |
| 42 | const union cptable *table = NULL; |
| 43 | char buf[32]; |
| 44 | |
| 45 | if (GetLocaleInfoA( lcid, type, buf, sizeof(buf) )) table = cp_get_table( atoi(buf) ); |
| 46 | return table; |
| 47 | } |
| 48 | |
| 49 | /* setup default codepage info before we can get at the locale stuff */ |
| 50 | static void init_codepages(void) |
| 51 | { |
| 52 | ansi_cptable = cp_get_table( 1252 ); |
| 53 | oem_cptable = cp_get_table( 437 ); |
| 54 | mac_cptable = cp_get_table( 10000 ); |
| 55 | assert( ansi_cptable ); |
| 56 | assert( oem_cptable ); |
| 57 | assert( mac_cptable ); |
| 58 | } |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 59 | |
| 60 | /* find the table for a given codepage, handling CP_ACP etc. pseudo-codepages */ |
| 61 | static const union cptable *get_codepage_table( unsigned int codepage ) |
| 62 | { |
| 63 | const union cptable *ret = NULL; |
| 64 | |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 65 | if (!ansi_cptable) init_codepages(); |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 66 | |
| 67 | switch(codepage) |
| 68 | { |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 69 | case CP_ACP: return ansi_cptable; |
| 70 | case CP_OEMCP: return oem_cptable; |
| 71 | case CP_MACCP: return mac_cptable; |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 72 | case CP_THREAD_ACP: return get_locale_cp( GetThreadLocale(), LOCALE_IDEFAULTANSICODEPAGE ); |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 73 | case CP_UTF7: |
| 74 | case CP_UTF8: |
| 75 | break; |
| 76 | default: |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 77 | if (codepage == ansi_cptable->info.codepage) return ansi_cptable; |
| 78 | if (codepage == oem_cptable->info.codepage) return oem_cptable; |
| 79 | if (codepage == mac_cptable->info.codepage) return mac_cptable; |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 80 | ret = cp_get_table( codepage ); |
| 81 | break; |
| 82 | } |
| 83 | return ret; |
| 84 | } |
| 85 | |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 86 | /* initialize default code pages from locale info */ |
| 87 | /* FIXME: should be done in init_codepages, but it can't right now */ |
| 88 | /* since it needs KERNEL32 to be loaded for the locale info. */ |
| 89 | void CODEPAGE_Init(void) |
| 90 | { |
Alexandre Julliard | 996c0bf | 2001-12-05 22:14:57 +0000 | [diff] [blame] | 91 | extern void __wine_init_codepages( const union cptable *ansi, const union cptable *oem ); |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 92 | const union cptable *table; |
| 93 | LCID lcid = GetUserDefaultLCID(); |
| 94 | |
| 95 | if (!ansi_cptable) init_codepages(); /* just in case */ |
Alexandre Julliard | 996c0bf | 2001-12-05 22:14:57 +0000 | [diff] [blame] | 96 | |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 97 | if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTANSICODEPAGE ))) ansi_cptable = table; |
| 98 | if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTMACCODEPAGE ))) mac_cptable = table; |
| 99 | if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTCODEPAGE ))) oem_cptable = table; |
Alexandre Julliard | 996c0bf | 2001-12-05 22:14:57 +0000 | [diff] [blame] | 100 | __wine_init_codepages( ansi_cptable, oem_cptable ); |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 101 | |
| 102 | TRACE( "ansi=%03d oem=%03d mac=%03d\n", ansi_cptable->info.codepage, |
| 103 | oem_cptable->info.codepage, mac_cptable->info.codepage ); |
| 104 | } |
| 105 | |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 106 | /****************************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 107 | * GetACP (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 108 | * |
| 109 | * RETURNS |
| 110 | * Current ANSI code-page identifier, default if no current defined |
| 111 | */ |
| 112 | UINT WINAPI GetACP(void) |
| 113 | { |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 114 | if (!ansi_cptable) init_codepages(); |
| 115 | return ansi_cptable->info.codepage; |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | |
| 119 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 120 | * GetOEMCP (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 121 | */ |
| 122 | UINT WINAPI GetOEMCP(void) |
| 123 | { |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 124 | if (!oem_cptable) init_codepages(); |
| 125 | return oem_cptable->info.codepage; |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
| 129 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 130 | * IsValidCodePage (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 131 | */ |
| 132 | BOOL WINAPI IsValidCodePage( UINT codepage ) |
| 133 | { |
| 134 | return cp_get_table( codepage ) != NULL; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 139 | * IsDBCSLeadByteEx (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 140 | */ |
| 141 | BOOL WINAPI IsDBCSLeadByteEx( UINT codepage, BYTE testchar ) |
| 142 | { |
| 143 | const union cptable *table = get_codepage_table( codepage ); |
| 144 | return table && is_dbcs_leadbyte( table, testchar ); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 149 | * IsDBCSLeadByte (KERNEL32.@) |
Patrik Stridvall | 044855c | 2001-07-11 18:56:41 +0000 | [diff] [blame] | 150 | * IsDBCSLeadByte (KERNEL.207) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 151 | */ |
| 152 | BOOL WINAPI IsDBCSLeadByte( BYTE testchar ) |
| 153 | { |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 154 | if (!ansi_cptable) init_codepages(); |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 155 | return is_dbcs_leadbyte( ansi_cptable, testchar ); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 160 | * GetCPInfo (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 161 | */ |
| 162 | BOOL WINAPI GetCPInfo( UINT codepage, LPCPINFO cpinfo ) |
| 163 | { |
| 164 | const union cptable *table = get_codepage_table( codepage ); |
| 165 | |
| 166 | if (!table) |
| 167 | { |
| 168 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 169 | return FALSE; |
| 170 | } |
| 171 | if (table->info.def_char & 0xff00) |
| 172 | { |
| 173 | cpinfo->DefaultChar[0] = table->info.def_char & 0xff00; |
| 174 | cpinfo->DefaultChar[1] = table->info.def_char & 0x00ff; |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | cpinfo->DefaultChar[0] = table->info.def_char & 0xff; |
| 179 | cpinfo->DefaultChar[1] = 0; |
| 180 | } |
| 181 | if ((cpinfo->MaxCharSize = table->info.char_size) == 2) |
| 182 | memcpy( cpinfo->LeadByte, table->dbcs.lead_bytes, sizeof(cpinfo->LeadByte) ); |
| 183 | else |
| 184 | cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0; |
| 185 | |
| 186 | return TRUE; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 191 | * EnumSystemCodePagesA (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 192 | */ |
| 193 | BOOL WINAPI EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum, DWORD flags ) |
| 194 | { |
| 195 | const union cptable *table; |
| 196 | char buffer[10]; |
| 197 | int index = 0; |
| 198 | |
| 199 | for (;;) |
| 200 | { |
| 201 | if (!(table = cp_enum_table( index++ ))) break; |
| 202 | sprintf( buffer, "%d", table->info.codepage ); |
| 203 | if (!lpfnCodePageEnum( buffer )) break; |
| 204 | } |
| 205 | return TRUE; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 210 | * EnumSystemCodePagesW (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 211 | */ |
| 212 | BOOL WINAPI EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags ) |
| 213 | { |
| 214 | const union cptable *table; |
| 215 | WCHAR buffer[10], *p; |
| 216 | int page, index = 0; |
| 217 | |
| 218 | for (;;) |
| 219 | { |
| 220 | if (!(table = cp_enum_table( index++ ))) break; |
| 221 | p = buffer + sizeof(buffer)/sizeof(WCHAR); |
| 222 | *--p = 0; |
| 223 | page = table->info.codepage; |
| 224 | do |
| 225 | { |
| 226 | *--p = '0' + (page % 10); |
| 227 | page /= 10; |
| 228 | } while( page ); |
| 229 | if (!lpfnCodePageEnum( p )) break; |
| 230 | } |
| 231 | return TRUE; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 236 | * MultiByteToWideChar (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 237 | * |
| 238 | * PARAMS |
| 239 | * page [in] Codepage character set to convert from |
| 240 | * flags [in] Character mapping flags |
| 241 | * src [in] Source string buffer |
| 242 | * srclen [in] Length of source string buffer |
| 243 | * dst [in] Destination buffer |
| 244 | * dstlen [in] Length of destination buffer |
| 245 | * |
| 246 | * NOTES |
| 247 | * The returned length includes the null terminator character. |
| 248 | * |
| 249 | * RETURNS |
| 250 | * Success: If dstlen > 0, number of characters written to destination |
| 251 | * buffer. If dstlen == 0, number of characters needed to do |
| 252 | * conversion. |
| 253 | * Failure: 0. Occurs if not enough space is available. |
| 254 | * |
| 255 | * ERRORS |
| 256 | * ERROR_INSUFFICIENT_BUFFER |
| 257 | * ERROR_INVALID_PARAMETER |
| 258 | * ERROR_NO_UNICODE_TRANSLATION |
| 259 | * |
| 260 | */ |
| 261 | INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen, |
| 262 | LPWSTR dst, INT dstlen ) |
| 263 | { |
| 264 | const union cptable *table; |
| 265 | int ret; |
| 266 | |
Wolfgang Schwotzer | d9b8f9b | 2000-07-28 23:58:48 +0000 | [diff] [blame] | 267 | if (!src || (!dst && dstlen)) |
| 268 | { |
| 269 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 270 | return 0; |
| 271 | } |
| 272 | |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 273 | if (srclen == -1) srclen = strlen(src) + 1; |
| 274 | |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 275 | if (flags & MB_USEGLYPHCHARS) FIXME("MB_USEGLYPHCHARS not supported\n"); |
| 276 | |
Alexandre Julliard | aea7853 | 2000-08-11 00:44:33 +0000 | [diff] [blame] | 277 | switch(page) |
| 278 | { |
| 279 | case CP_UTF7: |
| 280 | FIXME("UTF not supported\n"); |
| 281 | SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); |
| 282 | return 0; |
| 283 | case CP_UTF8: |
| 284 | ret = utf8_mbstowcs( flags, src, srclen, dst, dstlen ); |
| 285 | break; |
| 286 | default: |
| 287 | if (!(table = get_codepage_table( page ))) |
| 288 | { |
| 289 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 290 | return 0; |
| 291 | } |
| 292 | ret = cp_mbstowcs( table, flags, src, srclen, dst, dstlen ); |
| 293 | break; |
| 294 | } |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 295 | |
| 296 | if (ret < 0) |
| 297 | { |
| 298 | switch(ret) |
| 299 | { |
| 300 | case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break; |
| 301 | case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break; |
| 302 | } |
| 303 | ret = 0; |
| 304 | } |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 310 | * WideCharToMultiByte (KERNEL32.@) |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 311 | * |
| 312 | * PARAMS |
| 313 | * page [in] Codepage character set to convert to |
| 314 | * flags [in] Character mapping flags |
| 315 | * src [in] Source string buffer |
| 316 | * srclen [in] Length of source string buffer |
| 317 | * dst [in] Destination buffer |
| 318 | * dstlen [in] Length of destination buffer |
| 319 | * defchar [in] Default character to use for conversion if no exact |
| 320 | * conversion can be made |
| 321 | * used [out] Set if default character was used in the conversion |
| 322 | * |
| 323 | * NOTES |
| 324 | * The returned length includes the null terminator character. |
| 325 | * |
| 326 | * RETURNS |
| 327 | * Success: If dstlen > 0, number of characters written to destination |
| 328 | * buffer. If dstlen == 0, number of characters needed to do |
| 329 | * conversion. |
| 330 | * Failure: 0. Occurs if not enough space is available. |
| 331 | * |
| 332 | * ERRORS |
| 333 | * ERROR_INSUFFICIENT_BUFFER |
| 334 | * ERROR_INVALID_PARAMETER |
| 335 | */ |
| 336 | INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen, |
| 337 | LPSTR dst, INT dstlen, LPCSTR defchar, BOOL *used ) |
| 338 | { |
| 339 | const union cptable *table; |
| 340 | int ret, used_tmp; |
| 341 | |
Wolfgang Schwotzer | d9b8f9b | 2000-07-28 23:58:48 +0000 | [diff] [blame] | 342 | if (!src || (!dst && dstlen)) |
| 343 | { |
| 344 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 345 | return 0; |
| 346 | } |
| 347 | |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 348 | if (srclen == -1) srclen = strlenW(src) + 1; |
| 349 | |
Alexandre Julliard | aea7853 | 2000-08-11 00:44:33 +0000 | [diff] [blame] | 350 | switch(page) |
| 351 | { |
| 352 | case CP_UTF7: |
| 353 | FIXME("UTF-7 not supported\n"); |
| 354 | SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); |
| 355 | return 0; |
| 356 | case CP_UTF8: |
| 357 | ret = utf8_wcstombs( src, srclen, dst, dstlen ); |
| 358 | break; |
| 359 | default: |
| 360 | if (!(table = get_codepage_table( page ))) |
| 361 | { |
| 362 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 363 | return 0; |
| 364 | } |
| 365 | ret = cp_wcstombs( table, flags, src, srclen, dst, dstlen, |
| 366 | defchar, used ? &used_tmp : NULL ); |
| 367 | if (used) *used = used_tmp; |
| 368 | break; |
| 369 | } |
Alexandre Julliard | f7bf7ef | 2000-06-10 04:42:33 +0000 | [diff] [blame] | 370 | |
| 371 | if (ret == -1) |
| 372 | { |
| 373 | SetLastError( ERROR_INSUFFICIENT_BUFFER ); |
| 374 | ret = 0; |
| 375 | } |
| 376 | return ret; |
| 377 | } |
Alexandre Julliard | c97bb4c | 2000-08-11 20:53:40 +0000 | [diff] [blame] | 378 | |
| 379 | |
| 380 | /****************************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 381 | * GetStringTypeW (KERNEL32.@) |
Alexandre Julliard | c97bb4c | 2000-08-11 20:53:40 +0000 | [diff] [blame] | 382 | * |
| 383 | */ |
| 384 | BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype ) |
| 385 | { |
| 386 | if (count == -1) count = strlenW(src) + 1; |
| 387 | switch(type) |
| 388 | { |
| 389 | case CT_CTYPE1: |
| 390 | while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff; |
| 391 | break; |
| 392 | case CT_CTYPE2: |
| 393 | while (count--) *chartype++ = get_char_typeW( *src++ ) >> 12; |
| 394 | break; |
| 395 | case CT_CTYPE3: |
| 396 | FIXME("CT_CTYPE3 not supported.\n"); |
| 397 | default: |
| 398 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 399 | return FALSE; |
| 400 | } |
| 401 | return TRUE; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | /****************************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 406 | * GetStringTypeExW (KERNEL32.@) |
Alexandre Julliard | c97bb4c | 2000-08-11 20:53:40 +0000 | [diff] [blame] | 407 | */ |
| 408 | BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype ) |
| 409 | { |
| 410 | /* locale is ignored for Unicode */ |
| 411 | return GetStringTypeW( type, src, count, chartype ); |
| 412 | } |
Dmitry Timoshkov | c59655e | 2002-02-04 18:34:32 +0000 | [diff] [blame] | 413 | |
| 414 | /****************************************************************************** |
| 415 | * GetStringTypeA [KERNEL32.@] |
| 416 | */ |
| 417 | BOOL WINAPI GetStringTypeA(LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype) |
| 418 | { |
| 419 | char buf[20]; |
| 420 | UINT cp; |
| 421 | INT countW; |
| 422 | LPWSTR srcW; |
| 423 | BOOL ret = FALSE; |
| 424 | |
| 425 | if(count == -1) count = strlen(src) + 1; |
| 426 | |
| 427 | if(!GetLocaleInfoA(locale, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_NOUSEROVERRIDE, |
| 428 | buf, sizeof(buf))) |
| 429 | { |
| 430 | FIXME("For locale %04lx using current ANSI code page\n", locale); |
| 431 | cp = GetACP(); |
| 432 | } |
| 433 | else |
| 434 | cp = atoi(buf); |
| 435 | |
| 436 | countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0); |
| 437 | if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR)))) |
| 438 | { |
| 439 | MultiByteToWideChar(cp, 0, src, count, srcW, countW); |
| 440 | ret = GetStringTypeW(type, srcW, count, chartype); |
| 441 | HeapFree(GetProcessHeap(), 0, srcW); |
| 442 | } |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | /****************************************************************************** |
| 447 | * GetStringTypeExA [KERNEL32.@] |
| 448 | */ |
| 449 | BOOL WINAPI GetStringTypeExA(LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype) |
| 450 | { |
| 451 | return GetStringTypeA(locale, type, src, count, chartype); |
| 452 | } |