* Sync up to trunk head (r64921).
[reactos.git] / dll / win32 / kernel32 / winnls / string / lang.c
1 /*
2 * Locale support
3 *
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2002 Alexandre Julliard for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #include <k32.h>
25
26 #define NDEBUG
27 #include <debug.h>
28 DEBUG_CHANNEL(nls);
29
30 #include "lcformat_private.h"
31
32 #define REG_SZ 1
33 extern int wine_fold_string(int flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen);
34 extern int wine_get_sortkey(int flags, const WCHAR *src, int srclen, char *dst, int dstlen);
35 extern int wine_compare_string(int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2);
36
37 extern HMODULE kernel32_handle;
38
39 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
40 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
41
42 static const WCHAR szLocaleKeyName[] = {
43 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
44 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
45 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
46 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
47 };
48
49 static const WCHAR szLangGroupsKeyName[] = {
50 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
51 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
52 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
53 'C','o','n','t','r','o','l','\\','N','l','s','\\',
54 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
55 };
56
57 #ifndef __REACTOS__
58 /* Charset to codepage map, sorted by name. */
59 static const struct charset_entry
60 {
61 const char *charset_name;
62 UINT codepage;
63 } charset_names[] =
64 {
65 { "BIG5", 950 },
66 { "CP1250", 1250 },
67 { "CP1251", 1251 },
68 { "CP1252", 1252 },
69 { "CP1253", 1253 },
70 { "CP1254", 1254 },
71 { "CP1255", 1255 },
72 { "CP1256", 1256 },
73 { "CP1257", 1257 },
74 { "CP1258", 1258 },
75 { "CP932", 932 },
76 { "CP936", 936 },
77 { "CP949", 949 },
78 { "CP950", 950 },
79 { "EUCJP", 20932 },
80 { "GB2312", 936 },
81 { "IBM037", 37 },
82 { "IBM1026", 1026 },
83 { "IBM424", 424 },
84 { "IBM437", 437 },
85 { "IBM500", 500 },
86 { "IBM850", 850 },
87 { "IBM852", 852 },
88 { "IBM855", 855 },
89 { "IBM857", 857 },
90 { "IBM860", 860 },
91 { "IBM861", 861 },
92 { "IBM862", 862 },
93 { "IBM863", 863 },
94 { "IBM864", 864 },
95 { "IBM865", 865 },
96 { "IBM866", 866 },
97 { "IBM869", 869 },
98 { "IBM874", 874 },
99 { "IBM875", 875 },
100 { "ISO88591", 28591 },
101 { "ISO885910", 28600 },
102 { "ISO885913", 28603 },
103 { "ISO885914", 28604 },
104 { "ISO885915", 28605 },
105 { "ISO885916", 28606 },
106 { "ISO88592", 28592 },
107 { "ISO88593", 28593 },
108 { "ISO88594", 28594 },
109 { "ISO88595", 28595 },
110 { "ISO88596", 28596 },
111 { "ISO88597", 28597 },
112 { "ISO88598", 28598 },
113 { "ISO88599", 28599 },
114 { "KOI8R", 20866 },
115 { "KOI8U", 21866 },
116 { "UTF8", CP_UTF8 }
117 };
118 #endif
119
120 struct locale_name
121 {
122 WCHAR win_name[128]; /* Windows name ("en-US") */
123 WCHAR lang[128]; /* language ("en") (note: buffer contains the other strings too) */
124 WCHAR *country; /* country ("US") */
125 WCHAR *charset; /* charset ("UTF-8") for Unix format only */
126 WCHAR *script; /* script ("Latn") for Windows format only */
127 WCHAR *modifier; /* modifier or sort order */
128 LCID lcid; /* corresponding LCID */
129 int matches; /* number of elements matching LCID (0..4) */
130 UINT codepage; /* codepage corresponding to charset */
131 };
132
133 /* locale ids corresponding to the various Unix locale parameters */
134 static LCID lcid_LC_COLLATE;
135 static LCID lcid_LC_CTYPE;
136 static LCID lcid_LC_MONETARY;
137 static LCID lcid_LC_NUMERIC;
138 static LCID lcid_LC_TIME;
139 static LCID lcid_LC_PAPER;
140 static LCID lcid_LC_MEASUREMENT;
141 static LCID lcid_LC_TELEPHONE;
142
143 #ifndef __REACTOS__
144 /* Copy Ascii string to Unicode without using codepages */
145 static inline void strcpynAtoW( WCHAR *dst, const char *src, size_t n )
146 {
147 while (n > 1 && *src)
148 {
149 *dst++ = (unsigned char)*src++;
150 n--;
151 }
152 if (n) *dst = 0;
153 }
154 #endif
155
156 /***********************************************************************
157 * get_lcid_codepage
158 *
159 * Retrieve the ANSI codepage for a given locale.
160 */
161 static inline UINT get_lcid_codepage( LCID lcid )
162 {
163 UINT ret;
164 if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
165 sizeof(ret)/sizeof(WCHAR) )) ret = 0;
166 return ret;
167 }
168
169 /***********************************************************************
170 * convert_default_lcid
171 *
172 * Get the default LCID to use for a given lctype in GetLocaleInfo.
173 */
174 static LCID convert_default_lcid( LCID lcid, LCTYPE lctype )
175 {
176 if (lcid == LOCALE_SYSTEM_DEFAULT ||
177 lcid == LOCALE_USER_DEFAULT ||
178 lcid == LOCALE_NEUTRAL)
179 {
180 LCID default_id = 0;
181
182 switch(lctype & 0xffff)
183 {
184 case LOCALE_SSORTNAME:
185 default_id = lcid_LC_COLLATE;
186 break;
187
188 case LOCALE_FONTSIGNATURE:
189 case LOCALE_IDEFAULTANSICODEPAGE:
190 case LOCALE_IDEFAULTCODEPAGE:
191 case LOCALE_IDEFAULTEBCDICCODEPAGE:
192 case LOCALE_IDEFAULTMACCODEPAGE:
193 case LOCALE_IDEFAULTUNIXCODEPAGE:
194 default_id = lcid_LC_CTYPE;
195 break;
196
197 case LOCALE_ICURRDIGITS:
198 case LOCALE_ICURRENCY:
199 case LOCALE_IINTLCURRDIGITS:
200 case LOCALE_INEGCURR:
201 case LOCALE_INEGSEPBYSPACE:
202 case LOCALE_INEGSIGNPOSN:
203 case LOCALE_INEGSYMPRECEDES:
204 case LOCALE_IPOSSEPBYSPACE:
205 case LOCALE_IPOSSIGNPOSN:
206 case LOCALE_IPOSSYMPRECEDES:
207 case LOCALE_SCURRENCY:
208 case LOCALE_SINTLSYMBOL:
209 case LOCALE_SMONDECIMALSEP:
210 case LOCALE_SMONGROUPING:
211 case LOCALE_SMONTHOUSANDSEP:
212 case LOCALE_SNATIVECURRNAME:
213 default_id = lcid_LC_MONETARY;
214 break;
215
216 case LOCALE_IDIGITS:
217 case LOCALE_IDIGITSUBSTITUTION:
218 case LOCALE_ILZERO:
219 case LOCALE_INEGNUMBER:
220 case LOCALE_SDECIMAL:
221 case LOCALE_SGROUPING:
222 //case LOCALE_SNAN:
223 case LOCALE_SNATIVEDIGITS:
224 case LOCALE_SNEGATIVESIGN:
225 //case LOCALE_SNEGINFINITY:
226 //case LOCALE_SPOSINFINITY:
227 case LOCALE_SPOSITIVESIGN:
228 case LOCALE_STHOUSAND:
229 default_id = lcid_LC_NUMERIC;
230 break;
231
232 case LOCALE_ICALENDARTYPE:
233 case LOCALE_ICENTURY:
234 case LOCALE_IDATE:
235 case LOCALE_IDAYLZERO:
236 case LOCALE_IFIRSTDAYOFWEEK:
237 case LOCALE_IFIRSTWEEKOFYEAR:
238 case LOCALE_ILDATE:
239 case LOCALE_IMONLZERO:
240 case LOCALE_IOPTIONALCALENDAR:
241 case LOCALE_ITIME:
242 case LOCALE_ITIMEMARKPOSN:
243 case LOCALE_ITLZERO:
244 case LOCALE_S1159:
245 case LOCALE_S2359:
246 case LOCALE_SABBREVDAYNAME1:
247 case LOCALE_SABBREVDAYNAME2:
248 case LOCALE_SABBREVDAYNAME3:
249 case LOCALE_SABBREVDAYNAME4:
250 case LOCALE_SABBREVDAYNAME5:
251 case LOCALE_SABBREVDAYNAME6:
252 case LOCALE_SABBREVDAYNAME7:
253 case LOCALE_SABBREVMONTHNAME1:
254 case LOCALE_SABBREVMONTHNAME2:
255 case LOCALE_SABBREVMONTHNAME3:
256 case LOCALE_SABBREVMONTHNAME4:
257 case LOCALE_SABBREVMONTHNAME5:
258 case LOCALE_SABBREVMONTHNAME6:
259 case LOCALE_SABBREVMONTHNAME7:
260 case LOCALE_SABBREVMONTHNAME8:
261 case LOCALE_SABBREVMONTHNAME9:
262 case LOCALE_SABBREVMONTHNAME10:
263 case LOCALE_SABBREVMONTHNAME11:
264 case LOCALE_SABBREVMONTHNAME12:
265 case LOCALE_SABBREVMONTHNAME13:
266 case LOCALE_SDATE:
267 case LOCALE_SDAYNAME1:
268 case LOCALE_SDAYNAME2:
269 case LOCALE_SDAYNAME3:
270 case LOCALE_SDAYNAME4:
271 case LOCALE_SDAYNAME5:
272 case LOCALE_SDAYNAME6:
273 case LOCALE_SDAYNAME7:
274 //case LOCALE_SDURATION:
275 case LOCALE_SLONGDATE:
276 case LOCALE_SMONTHNAME1:
277 case LOCALE_SMONTHNAME2:
278 case LOCALE_SMONTHNAME3:
279 case LOCALE_SMONTHNAME4:
280 case LOCALE_SMONTHNAME5:
281 case LOCALE_SMONTHNAME6:
282 case LOCALE_SMONTHNAME7:
283 case LOCALE_SMONTHNAME8:
284 case LOCALE_SMONTHNAME9:
285 case LOCALE_SMONTHNAME10:
286 case LOCALE_SMONTHNAME11:
287 case LOCALE_SMONTHNAME12:
288 case LOCALE_SMONTHNAME13:
289 case LOCALE_SSHORTDATE:
290 //case LOCALE_SSHORTESTDAYNAME1:
291 //case LOCALE_SSHORTESTDAYNAME2:
292 //case LOCALE_SSHORTESTDAYNAME3:
293 //case LOCALE_SSHORTESTDAYNAME4:
294 //case LOCALE_SSHORTESTDAYNAME5:
295 //case LOCALE_SSHORTESTDAYNAME6:
296 //case LOCALE_SSHORTESTDAYNAME7:
297 case LOCALE_STIME:
298 case LOCALE_STIMEFORMAT:
299 case LOCALE_SYEARMONTH:
300 default_id = lcid_LC_TIME;
301 break;
302
303 case LOCALE_IPAPERSIZE:
304 default_id = lcid_LC_PAPER;
305 break;
306
307 case LOCALE_IMEASURE:
308 default_id = lcid_LC_MEASUREMENT;
309 break;
310
311 case LOCALE_ICOUNTRY:
312 default_id = lcid_LC_TELEPHONE;
313 break;
314 }
315 if (default_id) lcid = default_id;
316 }
317 return ConvertDefaultLocale( lcid );
318 }
319
320 /***********************************************************************
321 * is_genitive_name_supported
322 *
323 * Determine could LCTYPE basically support genitive name form or not.
324 */
325 static BOOL is_genitive_name_supported( LCTYPE lctype )
326 {
327 switch(lctype & 0xffff)
328 {
329 case LOCALE_SMONTHNAME1:
330 case LOCALE_SMONTHNAME2:
331 case LOCALE_SMONTHNAME3:
332 case LOCALE_SMONTHNAME4:
333 case LOCALE_SMONTHNAME5:
334 case LOCALE_SMONTHNAME6:
335 case LOCALE_SMONTHNAME7:
336 case LOCALE_SMONTHNAME8:
337 case LOCALE_SMONTHNAME9:
338 case LOCALE_SMONTHNAME10:
339 case LOCALE_SMONTHNAME11:
340 case LOCALE_SMONTHNAME12:
341 case LOCALE_SMONTHNAME13:
342 return TRUE;
343 default:
344 return FALSE;
345 }
346 }
347
348 /***********************************************************************
349 * create_registry_key
350 *
351 * Create the Control Panel\\International registry key.
352 */
353 static inline HANDLE create_registry_key(void)
354 {
355 static const WCHAR cplW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l',0};
356 static const WCHAR intlW[] = {'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
357 OBJECT_ATTRIBUTES attr;
358 UNICODE_STRING nameW;
359 HANDLE cpl_key, hkey = 0;
360
361 if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
362
363 attr.Length = sizeof(attr);
364 attr.RootDirectory = hkey;
365 attr.ObjectName = &nameW;
366 attr.Attributes = 0;
367 attr.SecurityDescriptor = NULL;
368 attr.SecurityQualityOfService = NULL;
369 RtlInitUnicodeString( &nameW, cplW );
370
371 if (!NtCreateKey( &cpl_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
372 {
373 NtClose( attr.RootDirectory );
374 attr.RootDirectory = cpl_key;
375 RtlInitUnicodeString( &nameW, intlW );
376 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) hkey = 0;
377 }
378 NtClose( attr.RootDirectory );
379 return hkey;
380 }
381
382 /***********************************************************************
383 * GetUserDefaultLangID (KERNEL32.@)
384 *
385 * Get the default language Id for the current user.
386 *
387 * PARAMS
388 * None.
389 *
390 * RETURNS
391 * The current LANGID of the default language for the current user.
392 */
393 LANGID WINAPI GetUserDefaultLangID(void)
394 {
395 return LANGIDFROMLCID(GetUserDefaultLCID());
396 }
397
398
399 /***********************************************************************
400 * GetSystemDefaultLangID (KERNEL32.@)
401 *
402 * Get the default language Id for the system.
403 *
404 * PARAMS
405 * None.
406 *
407 * RETURNS
408 * The current LANGID of the default language for the system.
409 */
410 LANGID WINAPI GetSystemDefaultLangID(void)
411 {
412 return LANGIDFROMLCID(GetSystemDefaultLCID());
413 }
414
415
416 /***********************************************************************
417 * GetUserDefaultLCID (KERNEL32.@)
418 *
419 * Get the default locale Id for the current user.
420 *
421 * PARAMS
422 * None.
423 *
424 * RETURNS
425 * The current LCID of the default locale for the current user.
426 */
427 LCID WINAPI GetUserDefaultLCID(void)
428 {
429 LCID lcid;
430 NtQueryDefaultLocale( TRUE, &lcid );
431 return lcid;
432 }
433
434
435 /***********************************************************************
436 * GetSystemDefaultLCID (KERNEL32.@)
437 *
438 * Get the default locale Id for the system.
439 *
440 * PARAMS
441 * None.
442 *
443 * RETURNS
444 * The current LCID of the default locale for the system.
445 */
446 LCID WINAPI GetSystemDefaultLCID(void)
447 {
448 LCID lcid;
449 NtQueryDefaultLocale( FALSE, &lcid );
450 return lcid;
451 }
452
453
454 /***********************************************************************
455 * GetUserDefaultUILanguage (KERNEL32.@)
456 *
457 * Get the default user interface language Id for the current user.
458 *
459 * PARAMS
460 * None.
461 *
462 * RETURNS
463 * The current LANGID of the default UI language for the current user.
464 */
465 LANGID WINAPI GetUserDefaultUILanguage(void)
466 {
467 LANGID lang;
468 NtQueryDefaultUILanguage( &lang );
469 return lang;
470 }
471
472
473 /***********************************************************************
474 * GetSystemDefaultUILanguage (KERNEL32.@)
475 *
476 * Get the default user interface language Id for the system.
477 *
478 * PARAMS
479 * None.
480 *
481 * RETURNS
482 * The current LANGID of the default UI language for the system. This is
483 * typically the same language used during the installation process.
484 */
485 LANGID WINAPI GetSystemDefaultUILanguage(void)
486 {
487 LANGID lang;
488 NtQueryInstallUILanguage( &lang );
489 return lang;
490 }
491
492 /******************************************************************************
493 * get_locale_value_name
494 *
495 * Gets the registry value name for a given lctype.
496 */
497 static const WCHAR *get_locale_value_name( DWORD lctype )
498 {
499 static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
500 static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
501 static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
502 static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
503 static const WCHAR iDateW[] = {'i','D','a','t','e',0};
504 static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
505 static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
506 static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
507 static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
508 static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
509 static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
510 static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
511 static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
512 static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
513 static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
514 static const WCHAR iTimePrefixW[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
515 static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
516 static const WCHAR s1159W[] = {'s','1','1','5','9',0};
517 static const WCHAR s2359W[] = {'s','2','3','5','9',0};
518 static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
519 static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
520 static const WCHAR sDateW[] = {'s','D','a','t','e',0};
521 static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
522 static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
523 static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
524 static const WCHAR sListW[] = {'s','L','i','s','t',0};
525 static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
526 static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
527 static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
528 static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
529 static const WCHAR sNativeDigitsW[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
530 static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
531 static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
532 static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
533 static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
534 static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
535 static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
536 static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
537 static const WCHAR NumShapeW[] = {'N','u','m','s','h','a','p','e',0};
538
539 switch (lctype)
540 {
541 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
542 * the values are stored in the registry, confirmed under Windows.
543 */
544 case LOCALE_ICALENDARTYPE: return iCalendarTypeW;
545 case LOCALE_ICURRDIGITS: return iCurrDigitsW;
546 case LOCALE_ICURRENCY: return iCurrencyW;
547 case LOCALE_IDIGITS: return iDigitsW;
548 case LOCALE_IFIRSTDAYOFWEEK: return iFirstDayOfWeekW;
549 case LOCALE_IFIRSTWEEKOFYEAR: return iFirstWeekOfYearW;
550 case LOCALE_ILZERO: return iLZeroW;
551 case LOCALE_IMEASURE: return iMeasureW;
552 case LOCALE_INEGCURR: return iNegCurrW;
553 case LOCALE_INEGNUMBER: return iNegNumberW;
554 case LOCALE_IPAPERSIZE: return iPaperSizeW;
555 case LOCALE_ITIME: return iTimeW;
556 case LOCALE_S1159: return s1159W;
557 case LOCALE_S2359: return s2359W;
558 case LOCALE_SCURRENCY: return sCurrencyW;
559 case LOCALE_SDATE: return sDateW;
560 case LOCALE_SDECIMAL: return sDecimalW;
561 case LOCALE_SGROUPING: return sGroupingW;
562 case LOCALE_SLIST: return sListW;
563 case LOCALE_SLONGDATE: return sLongDateW;
564 case LOCALE_SMONDECIMALSEP: return sMonDecimalSepW;
565 case LOCALE_SMONGROUPING: return sMonGroupingW;
566 case LOCALE_SMONTHOUSANDSEP: return sMonThousandSepW;
567 case LOCALE_SNEGATIVESIGN: return sNegativeSignW;
568 case LOCALE_SPOSITIVESIGN: return sPositiveSignW;
569 case LOCALE_SSHORTDATE: return sShortDateW;
570 case LOCALE_STHOUSAND: return sThousandW;
571 case LOCALE_STIME: return sTimeW;
572 case LOCALE_STIMEFORMAT: return sTimeFormatW;
573 case LOCALE_SYEARMONTH: return sYearMonthW;
574
575 /* The following are not listed under MSDN as supported,
576 * but seem to be used and also stored in the registry.
577 */
578 case LOCALE_ICOUNTRY: return iCountryW;
579 case LOCALE_IDATE: return iDateW;
580 case LOCALE_ILDATE: return iLDateW;
581 case LOCALE_ITLZERO: return iTLZeroW;
582 case LOCALE_SCOUNTRY: return sCountryW;
583 case LOCALE_SABBREVLANGNAME: return sLanguageW;
584
585 /* The following are used in XP and later */
586 case LOCALE_IDIGITSUBSTITUTION: return NumShapeW;
587 case LOCALE_SNATIVEDIGITS: return sNativeDigitsW;
588 case LOCALE_ITIMEMARKPOSN: return iTimePrefixW;
589 }
590 return NULL;
591 }
592
593
594 /******************************************************************************
595 * get_registry_locale_info
596 *
597 * Retrieve user-modified locale info from the registry.
598 * Return length, 0 on error, -1 if not found.
599 */
600 static INT get_registry_locale_info( LPCWSTR value, LPWSTR buffer, INT len )
601 {
602 DWORD size;
603 INT ret;
604 HANDLE hkey;
605 NTSTATUS status;
606 UNICODE_STRING nameW;
607 KEY_VALUE_PARTIAL_INFORMATION *info;
608 static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
609
610 if (!(hkey = create_registry_key())) return -1;
611
612 RtlInitUnicodeString( &nameW, value );
613 size = info_size + len * sizeof(WCHAR);
614
615 if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
616 {
617 NtClose( hkey );
618 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
619 return 0;
620 }
621
622 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
623
624 if (!status)
625 {
626 ret = (size - info_size) / sizeof(WCHAR);
627 /* append terminating null if needed */
628 if (!ret || ((WCHAR *)info->Data)[ret-1])
629 {
630 if (ret < len || !buffer) ret++;
631 else
632 {
633 SetLastError( ERROR_INSUFFICIENT_BUFFER );
634 ret = 0;
635 }
636 }
637 if (ret && buffer)
638 {
639 memcpy( buffer, info->Data, (ret-1) * sizeof(WCHAR) );
640 buffer[ret-1] = 0;
641 }
642 }
643 else if (status == STATUS_BUFFER_OVERFLOW && !buffer)
644 {
645 ret = (size - info_size) / sizeof(WCHAR) + 1;
646 }
647 else if (status == STATUS_OBJECT_NAME_NOT_FOUND)
648 {
649 ret = -1;
650 }
651 else
652 {
653 SetLastError( RtlNtStatusToDosError(status) );
654 ret = 0;
655 }
656 NtClose( hkey );
657 HeapFree( GetProcessHeap(), 0, info );
658 return ret;
659 }
660
661
662 /******************************************************************************
663 * GetLocaleInfoA (KERNEL32.@)
664 *
665 * Get information about an aspect of a locale.
666 *
667 * PARAMS
668 * lcid [I] LCID of the locale
669 * lctype [I] LCTYPE_ flags from "winnls.h"
670 * buffer [O] Destination for the information
671 * len [I] Length of buffer in characters
672 *
673 * RETURNS
674 * Success: The size of the data requested. If buffer is non-NULL, it is filled
675 * with the information.
676 * Failure: 0. Use GetLastError() to determine the cause.
677 *
678 * NOTES
679 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
680 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
681 * which is a bit string.
682 */
683 INT WINAPI GetLocaleInfoA( LCID lcid, LCTYPE lctype, LPSTR buffer, INT len )
684 {
685 WCHAR *bufferW;
686 INT lenW, ret;
687
688 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
689
690 if (len < 0 || (len && !buffer))
691 {
692 SetLastError( ERROR_INVALID_PARAMETER );
693 return 0;
694 }
695 if (lctype & LOCALE_RETURN_GENITIVE_NAMES )
696 {
697 SetLastError( ERROR_INVALID_FLAGS );
698 return 0;
699 }
700
701 if (!len) buffer = NULL;
702
703 if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
704
705 if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
706 {
707 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
708 return 0;
709 }
710 if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
711 {
712 if ((lctype & LOCALE_RETURN_NUMBER) ||
713 ((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_FONTSIGNATURE))
714 {
715 /* it's not an ASCII string, just bytes */
716 ret *= sizeof(WCHAR);
717 if (buffer)
718 {
719 if (ret <= len) memcpy( buffer, bufferW, ret );
720 else
721 {
722 SetLastError( ERROR_INSUFFICIENT_BUFFER );
723 ret = 0;
724 }
725 }
726 }
727 else
728 {
729 UINT codepage = CP_ACP;
730 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
731 ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
732 }
733 }
734 HeapFree( GetProcessHeap(), 0, bufferW );
735 return ret;
736 }
737
738 static int get_value_base_by_lctype( LCTYPE lctype )
739 {
740 return lctype == LOCALE_ILANGUAGE || lctype == LOCALE_IDEFAULTLANGUAGE ? 16 : 10;
741 }
742
743 /******************************************************************************
744 * GetLocaleInfoW (KERNEL32.@)
745 *
746 * See GetLocaleInfoA.
747 */
748 INT WINAPI GetLocaleInfoW( LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len )
749 {
750 LANGID lang_id;
751 HRSRC hrsrc;
752 HGLOBAL hmem;
753 INT ret;
754 UINT lcflags;
755 const WCHAR *p;
756 unsigned int i;
757
758 if (len < 0 || (len && !buffer))
759 {
760 SetLastError( ERROR_INVALID_PARAMETER );
761 return 0;
762 }
763 if (lctype & LOCALE_RETURN_GENITIVE_NAMES &&
764 !is_genitive_name_supported( lctype ))
765 {
766 SetLastError( ERROR_INVALID_FLAGS );
767 return 0;
768 }
769
770 if (!len) buffer = NULL;
771
772 lcid = convert_default_lcid( lcid, lctype );
773
774 lcflags = lctype & LOCALE_LOCALEINFOFLAGSMASK;
775 lctype &= 0xffff;
776
777 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
778
779 /* first check for overrides in the registry */
780
781 if (!(lcflags & LOCALE_NOUSEROVERRIDE) &&
782 lcid == convert_default_lcid( LOCALE_USER_DEFAULT, lctype ))
783 {
784 const WCHAR *value = get_locale_value_name(lctype);
785
786 if (value)
787 {
788 if (lcflags & LOCALE_RETURN_NUMBER)
789 {
790 WCHAR tmp[16];
791 ret = get_registry_locale_info( value, tmp, sizeof(tmp)/sizeof(WCHAR) );
792 if (ret > 0)
793 {
794 WCHAR *end;
795 UINT number = strtolW( tmp, &end, get_value_base_by_lctype( lctype ) );
796 if (*end) /* invalid number */
797 {
798 SetLastError( ERROR_INVALID_FLAGS );
799 return 0;
800 }
801 ret = sizeof(UINT)/sizeof(WCHAR);
802 if (!buffer) return ret;
803 if (ret > len)
804 {
805 SetLastError( ERROR_INSUFFICIENT_BUFFER );
806 return 0;
807 }
808 memcpy( buffer, &number, sizeof(number) );
809 }
810 }
811 else ret = get_registry_locale_info( value, buffer, len );
812
813 if (ret != -1) return ret;
814 }
815 }
816
817 /* now load it from kernel resources */
818
819 lang_id = LANGIDFROMLCID( lcid );
820
821 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
822 if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
823 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
824
825 if (!(hrsrc = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
826 ULongToPtr((lctype >> 4) + 1), lang_id )))
827 {
828 SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
829 return 0;
830 }
831 if (!(hmem = LoadResource( kernel32_handle, hrsrc )))
832 return 0;
833
834 p = LockResource( hmem );
835 for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
836
837 if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
838 else if (is_genitive_name_supported( lctype ) && *p)
839 {
840 /* genitive form's stored after a null separator from a nominative */
841 for (i = 1; i <= *p; i++) if (!p[i]) break;
842
843 if (i <= *p && (lcflags & LOCALE_RETURN_GENITIVE_NAMES))
844 {
845 ret = *p - i + 1;
846 p += i;
847 }
848 else ret = i;
849 }
850 else
851 ret = (lctype == LOCALE_FONTSIGNATURE) ? *p : *p + 1;
852
853 if (!buffer) return ret;
854
855 if (ret > len)
856 {
857 SetLastError( ERROR_INSUFFICIENT_BUFFER );
858 return 0;
859 }
860
861 if (lcflags & LOCALE_RETURN_NUMBER)
862 {
863 UINT number;
864 WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
865 if (!tmp) return 0;
866 memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
867 tmp[*p] = 0;
868 number = strtolW( tmp, &end, get_value_base_by_lctype( lctype ) );
869 if (!*end)
870 memcpy( buffer, &number, sizeof(number) );
871 else /* invalid number */
872 {
873 SetLastError( ERROR_INVALID_FLAGS );
874 ret = 0;
875 }
876 HeapFree( GetProcessHeap(), 0, tmp );
877
878 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
879 lcid, lctype, buffer, len, number );
880 }
881 else
882 {
883 memcpy( buffer, p + 1, ret * sizeof(WCHAR) );
884 if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
885
886 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
887 lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
888 }
889 return ret;
890 }
891
892
893 /******************************************************************************
894 * SetLocaleInfoA [KERNEL32.@]
895 *
896 * Set information about an aspect of a locale.
897 *
898 * PARAMS
899 * lcid [I] LCID of the locale
900 * lctype [I] LCTYPE_ flags from "winnls.h"
901 * data [I] Information to set
902 *
903 * RETURNS
904 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
905 * whenever it is called without LOCALE_NOUSEROVERRIDE.
906 * Failure: FALSE. Use GetLastError() to determine the cause.
907 *
908 * NOTES
909 * - Values are only be set for the current user locale; the system locale
910 * settings cannot be changed.
911 * - Any settings changed by this call are lost when the locale is changed by
912 * the control panel (in Wine, this happens every time you change LANG).
913 * - The native implementation of this function does not check that lcid matches
914 * the current user locale, and simply sets the new values. Wine warns you in
915 * this case, but behaves the same.
916 */
917 BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
918 {
919 UINT codepage = CP_ACP;
920 WCHAR *strW;
921 DWORD len;
922 BOOL ret;
923
924 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
925
926 if (!data)
927 {
928 SetLastError( ERROR_INVALID_PARAMETER );
929 return FALSE;
930 }
931 len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
932 if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
933 {
934 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
935 return FALSE;
936 }
937 MultiByteToWideChar( codepage, 0, data, -1, strW, len );
938 ret = SetLocaleInfoW( lcid, lctype, strW );
939 HeapFree( GetProcessHeap(), 0, strW );
940 return ret;
941 }
942
943
944 /******************************************************************************
945 * SetLocaleInfoW (KERNEL32.@)
946 *
947 * See SetLocaleInfoA.
948 */
949 BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
950 {
951 const WCHAR *value;
952 static const WCHAR intlW[] = {'i','n','t','l',0 };
953 UNICODE_STRING valueW;
954 NTSTATUS status;
955 HANDLE hkey;
956
957 lctype &= 0xffff;
958 value = get_locale_value_name( lctype );
959
960 if (!data || !value)
961 {
962 SetLastError( ERROR_INVALID_PARAMETER );
963 return FALSE;
964 }
965
966 if (lctype == LOCALE_IDATE || lctype == LOCALE_ILDATE)
967 {
968 SetLastError( ERROR_INVALID_FLAGS );
969 return FALSE;
970 }
971
972 TRACE("setting %x (%s) to %s\n", lctype, debugstr_w(value), debugstr_w(data) );
973
974 /* FIXME: should check that data to set is sane */
975
976 /* FIXME: profile functions should map to registry */
977 WriteProfileStringW( intlW, value, data );
978
979 if (!(hkey = create_registry_key())) return FALSE;
980 RtlInitUnicodeString( &valueW, value );
981 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, (PVOID)data, (strlenW(data)+1)*sizeof(WCHAR) );
982
983 if (lctype == LOCALE_SSHORTDATE || lctype == LOCALE_SLONGDATE)
984 {
985 /* Set I-value from S value */
986 WCHAR *lpD, *lpM, *lpY;
987 WCHAR szBuff[2];
988
989 lpD = strrchrW(data, 'd');
990 lpM = strrchrW(data, 'M');
991 lpY = strrchrW(data, 'y');
992
993 if (lpD <= lpM)
994 {
995 szBuff[0] = '1'; /* D-M-Y */
996 }
997 else
998 {
999 if (lpY <= lpM)
1000 szBuff[0] = '2'; /* Y-M-D */
1001 else
1002 szBuff[0] = '0'; /* M-D-Y */
1003 }
1004
1005 szBuff[1] = '\0';
1006
1007 if (lctype == LOCALE_SSHORTDATE)
1008 lctype = LOCALE_IDATE;
1009 else
1010 lctype = LOCALE_ILDATE;
1011
1012 value = get_locale_value_name( lctype );
1013
1014 WriteProfileStringW( intlW, value, szBuff );
1015
1016 RtlInitUnicodeString( &valueW, value );
1017 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
1018 }
1019
1020 NtClose( hkey );
1021
1022 if (status) SetLastError( RtlNtStatusToDosError(status) );
1023 return !status;
1024 }
1025
1026 /***********************************************************************
1027 * GetThreadLocale (KERNEL32.@)
1028 *
1029 * Get the current threads locale.
1030 *
1031 * PARAMS
1032 * None.
1033 *
1034 * RETURNS
1035 * The LCID currently associated with the calling thread.
1036 */
1037 LCID WINAPI GetThreadLocale(void)
1038 {
1039 LCID ret = NtCurrentTeb()->CurrentLocale;
1040 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
1041 return ret;
1042 }
1043
1044 /**********************************************************************
1045 * SetThreadLocale (KERNEL32.@)
1046 *
1047 * Set the current threads locale.
1048 *
1049 * PARAMS
1050 * lcid [I] LCID of the locale to set
1051 *
1052 * RETURNS
1053 * Success: TRUE. The threads locale is set to lcid.
1054 * Failure: FALSE. Use GetLastError() to determine the cause.
1055 */
1056 BOOL WINAPI SetThreadLocale( LCID lcid )
1057 {
1058 TRACE("(0x%04X)\n", lcid);
1059
1060 lcid = ConvertDefaultLocale(lcid);
1061
1062 if (lcid != GetThreadLocale())
1063 {
1064 if (!IsValidLocale(lcid, LCID_SUPPORTED))
1065 {
1066 SetLastError(ERROR_INVALID_PARAMETER);
1067 return FALSE;
1068 }
1069
1070 NtCurrentTeb()->CurrentLocale = lcid;
1071 }
1072 return TRUE;
1073 }
1074
1075 /******************************************************************************
1076 * ConvertDefaultLocale (KERNEL32.@)
1077 *
1078 * Convert a default locale identifier into a real identifier.
1079 *
1080 * PARAMS
1081 * lcid [I] LCID identifier of the locale to convert
1082 *
1083 * RETURNS
1084 * lcid unchanged, if not a default locale or its sublanguage is
1085 * not SUBLANG_NEUTRAL.
1086 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1087 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1088 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1089 */
1090 LCID WINAPI ConvertDefaultLocale( LCID lcid )
1091 {
1092 LANGID langid;
1093
1094 switch (lcid)
1095 {
1096 case LOCALE_SYSTEM_DEFAULT:
1097 lcid = GetSystemDefaultLCID();
1098 break;
1099 case LOCALE_USER_DEFAULT:
1100 case LOCALE_NEUTRAL:
1101 lcid = GetUserDefaultLCID();
1102 break;
1103 default:
1104 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1105 langid = LANGIDFROMLCID(lcid);
1106 if (SUBLANGID(langid) == SUBLANG_NEUTRAL)
1107 {
1108 langid = MAKELANGID(PRIMARYLANGID(langid), SUBLANG_DEFAULT);
1109 lcid = MAKELCID(langid, SORTIDFROMLCID(lcid));
1110 }
1111 }
1112 return lcid;
1113 }
1114
1115
1116 /******************************************************************************
1117 * IsValidLocale (KERNEL32.@)
1118 *
1119 * Determine if a locale is valid.
1120 *
1121 * PARAMS
1122 * lcid [I] LCID of the locale to check
1123 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1124 *
1125 * RETURNS
1126 * TRUE, if lcid is valid,
1127 * FALSE, otherwise.
1128 *
1129 * NOTES
1130 * Wine does not currently make the distinction between supported and installed. All
1131 * languages supported are installed by default.
1132 */
1133 BOOL WINAPI IsValidLocale( LCID lcid, DWORD flags )
1134 {
1135 /* check if language is registered in the kernel32 resources */
1136 return FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
1137 (LPCWSTR)LOCALE_ILANGUAGE, LANGIDFROMLCID(lcid)) != 0;
1138 }
1139
1140
1141 static BOOL CALLBACK enum_lang_proc_a( HMODULE hModule, LPCSTR type,
1142 LPCSTR name, WORD LangID, LONG_PTR lParam )
1143 {
1144 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
1145 char buf[20];
1146
1147 sprintf(buf, "%08x", (UINT)LangID);
1148 return lpfnLocaleEnum( buf );
1149 }
1150
1151 static BOOL CALLBACK enum_lang_proc_w( HMODULE hModule, LPCWSTR type,
1152 LPCWSTR name, WORD LangID, LONG_PTR lParam )
1153 {
1154 static const WCHAR formatW[] = {'%','0','8','x',0};
1155 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
1156 WCHAR buf[20];
1157 sprintfW( buf, formatW, (UINT)LangID );
1158 return lpfnLocaleEnum( buf );
1159 }
1160
1161 /******************************************************************************
1162 * EnumSystemLocalesA (KERNEL32.@)
1163 *
1164 * Call a users function for each locale available on the system.
1165 *
1166 * PARAMS
1167 * lpfnLocaleEnum [I] Callback function to call for each locale
1168 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1169 *
1170 * RETURNS
1171 * Success: TRUE.
1172 * Failure: FALSE. Use GetLastError() to determine the cause.
1173 */
1174 BOOL WINAPI EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum, DWORD dwFlags )
1175 {
1176 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
1177 EnumResourceLanguagesA( kernel32_handle, (LPSTR)RT_STRING,
1178 (LPCSTR)LOCALE_ILANGUAGE, enum_lang_proc_a,
1179 (LONG_PTR)lpfnLocaleEnum);
1180 return TRUE;
1181 }
1182
1183
1184 /******************************************************************************
1185 * EnumSystemLocalesW (KERNEL32.@)
1186 *
1187 * See EnumSystemLocalesA.
1188 */
1189 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum, DWORD dwFlags )
1190 {
1191 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
1192 EnumResourceLanguagesW( kernel32_handle, (LPWSTR)RT_STRING,
1193 (LPCWSTR)LOCALE_ILANGUAGE, enum_lang_proc_w,
1194 (LONG_PTR)lpfnLocaleEnum);
1195 return TRUE;
1196 }
1197
1198 /***********************************************************************
1199 * VerLanguageNameA (KERNEL32.@)
1200 *
1201 * Get the name of a language.
1202 *
1203 * PARAMS
1204 * wLang [I] LANGID of the language
1205 * szLang [O] Destination for the language name
1206 *
1207 * RETURNS
1208 * Success: The size of the language name. If szLang is non-NULL, it is filled
1209 * with the name.
1210 * Failure: 0. Use GetLastError() to determine the cause.
1211 *
1212 */
1213 DWORD WINAPI VerLanguageNameA( DWORD wLang, LPSTR szLang, DWORD nSize )
1214 {
1215 return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1216 }
1217
1218
1219 /***********************************************************************
1220 * VerLanguageNameW (KERNEL32.@)
1221 *
1222 * See VerLanguageNameA.
1223 */
1224 DWORD WINAPI VerLanguageNameW( DWORD wLang, LPWSTR szLang, DWORD nSize )
1225 {
1226 return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1227 }
1228
1229 /******************************************************************************
1230 * GetStringTypeW (KERNEL32.@)
1231 *
1232 * See GetStringTypeA.
1233 */
1234 BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1235 {
1236 static const unsigned char type2_map[16] =
1237 {
1238 C2_NOTAPPLICABLE, /* unassigned */
1239 C2_LEFTTORIGHT, /* L */
1240 C2_RIGHTTOLEFT, /* R */
1241 C2_EUROPENUMBER, /* EN */
1242 C2_EUROPESEPARATOR, /* ES */
1243 C2_EUROPETERMINATOR, /* ET */
1244 C2_ARABICNUMBER, /* AN */
1245 C2_COMMONSEPARATOR, /* CS */
1246 C2_BLOCKSEPARATOR, /* B */
1247 C2_SEGMENTSEPARATOR, /* S */
1248 C2_WHITESPACE, /* WS */
1249 C2_OTHERNEUTRAL, /* ON */
1250 C2_RIGHTTOLEFT, /* AL */
1251 C2_NOTAPPLICABLE, /* NSM */
1252 C2_NOTAPPLICABLE, /* BN */
1253 C2_OTHERNEUTRAL /* LRE, LRO, RLE, RLO, PDF */
1254 };
1255
1256 if (count == -1) count = strlenW(src) + 1;
1257 switch(type)
1258 {
1259 case CT_CTYPE1:
1260 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
1261 break;
1262 case CT_CTYPE2:
1263 while (count--) *chartype++ = type2_map[get_char_typeW( *src++ ) >> 12];
1264 break;
1265 case CT_CTYPE3:
1266 {
1267 WARN("CT_CTYPE3: semi-stub.\n");
1268 while (count--)
1269 {
1270 int c = *src;
1271 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
1272
1273 type1 = get_char_typeW( *src++ ) & 0xfff;
1274 /* try to construct type3 from type1 */
1275 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
1276 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1277 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1278 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1279 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1280 if ((c>=0x0600)&&(c<=0x06FF)) type3 |= C3_KASHIDA;
1281 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1282
1283 if ((c>=0xD800)&&(c<=0xDBFF)) type3 |= C3_HIGHSURROGATE;
1284 if ((c>=0xDC00)&&(c<=0xDFFF)) type3 |= C3_LOWSURROGATE;
1285
1286 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1287 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1288 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1289 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1290 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1291 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1292 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1293 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1294
1295 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1296 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1297 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1298 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1299 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1300 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1301 *chartype++ = type3;
1302 }
1303 break;
1304 }
1305 default:
1306 SetLastError( ERROR_INVALID_PARAMETER );
1307 return FALSE;
1308 }
1309 return TRUE;
1310 }
1311
1312
1313 /******************************************************************************
1314 * GetStringTypeExW (KERNEL32.@)
1315 *
1316 * See GetStringTypeExA.
1317 */
1318 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1319 {
1320 /* locale is ignored for Unicode */
1321 return GetStringTypeW( type, src, count, chartype );
1322 }
1323
1324
1325 /******************************************************************************
1326 * GetStringTypeA (KERNEL32.@)
1327 *
1328 * Get characteristics of the characters making up a string.
1329 *
1330 * PARAMS
1331 * locale [I] Locale Id for the string
1332 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1333 * src [I] String to analyse
1334 * count [I] Length of src in chars, or -1 if src is NUL terminated
1335 * chartype [O] Destination for the calculated characteristics
1336 *
1337 * RETURNS
1338 * Success: TRUE. chartype is filled with the requested characteristics of each char
1339 * in src.
1340 * Failure: FALSE. Use GetLastError() to determine the cause.
1341 */
1342 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1343 {
1344 UINT cp;
1345 INT countW;
1346 LPWSTR srcW;
1347 BOOL ret = FALSE;
1348
1349 if(count == -1) count = strlen(src) + 1;
1350
1351 if (!(cp = get_lcid_codepage( locale )))
1352 {
1353 FIXME("For locale %04x using current ANSI code page\n", locale);
1354 cp = GetACP();
1355 }
1356
1357 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1358 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1359 {
1360 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1361 /*
1362 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1363 * string, with multibyte characters there maybe be more bytes in count
1364 * than character space in the buffer!
1365 */
1366 ret = GetStringTypeW(type, srcW, countW, chartype);
1367 HeapFree(GetProcessHeap(), 0, srcW);
1368 }
1369 return ret;
1370 }
1371
1372 /******************************************************************************
1373 * GetStringTypeExA (KERNEL32.@)
1374 *
1375 * Get characteristics of the characters making up a string.
1376 *
1377 * PARAMS
1378 * locale [I] Locale Id for the string
1379 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1380 * src [I] String to analyse
1381 * count [I] Length of src in chars, or -1 if src is NUL terminated
1382 * chartype [O] Destination for the calculated characteristics
1383 *
1384 * RETURNS
1385 * Success: TRUE. chartype is filled with the requested characteristics of each char
1386 * in src.
1387 * Failure: FALSE. Use GetLastError() to determine the cause.
1388 */
1389 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1390 {
1391 return GetStringTypeA(locale, type, src, count, chartype);
1392 }
1393
1394 /*************************************************************************
1395 * LCMapStringEx (KERNEL32.@)
1396 *
1397 * Map characters in a locale sensitive string.
1398 *
1399 * PARAMS
1400 * name [I] Locale name for the conversion.
1401 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h")
1402 * src [I] String to map
1403 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1404 * dst [O] Destination for mapped string
1405 * dstlen [I] Length of dst in characters
1406 * version [I] reserved, must be NULL
1407 * reserved [I] reserved, must be NULL
1408 * lparam [I] reserved, must be 0
1409 *
1410 * RETURNS
1411 * Success: The length of the mapped string in dst, including the NUL terminator.
1412 * Failure: 0. Use GetLastError() to determine the cause.
1413 */
1414 INT WINAPI LCMapStringEx(LPCWSTR name, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen,
1415 LPNLSVERSIONINFO version, LPVOID reserved, LPARAM lparam)
1416 {
1417 LPWSTR dst_ptr;
1418
1419 if (version) FIXME("unsupported version structure %p\n", version);
1420 if (reserved) FIXME("unsupported reserved pointer %p\n", reserved);
1421 if (lparam) FIXME("unsupported lparam %lx\n", lparam);
1422
1423 if (!src || !srclen || dstlen < 0)
1424 {
1425 SetLastError(ERROR_INVALID_PARAMETER);
1426 return 0;
1427 }
1428
1429 /* mutually exclusive flags */
1430 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
1431 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
1432 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
1433 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
1434 {
1435 SetLastError(ERROR_INVALID_FLAGS);
1436 return 0;
1437 }
1438
1439 if (!dstlen) dst = NULL;
1440
1441 if (flags & LCMAP_SORTKEY)
1442 {
1443 INT ret;
1444 if (src == dst)
1445 {
1446 SetLastError(ERROR_INVALID_FLAGS);
1447 return 0;
1448 }
1449
1450 if (srclen < 0) srclen = strlenW(src);
1451
1452 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1453 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1454
1455 ret = wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
1456 if (ret == 0)
1457 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1458 else
1459 ret++;
1460 return ret;
1461 }
1462
1463 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1464 if (flags & SORT_STRINGSORT)
1465 {
1466 SetLastError(ERROR_INVALID_FLAGS);
1467 return 0;
1468 }
1469
1470 if (srclen < 0) srclen = strlenW(src) + 1;
1471
1472 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1473 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1474
1475 if (!dst) /* return required string length */
1476 {
1477 INT len;
1478
1479 for (len = 0; srclen; src++, srclen--)
1480 {
1481 WCHAR wch = *src;
1482 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1483 * and skips white space and punctuation characters for
1484 * NORM_IGNORESYMBOLS.
1485 */
1486 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1487 continue;
1488 len++;
1489 }
1490 return len;
1491 }
1492
1493 if (flags & LCMAP_UPPERCASE)
1494 {
1495 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1496 {
1497 WCHAR wch = *src;
1498 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1499 continue;
1500 *dst_ptr++ = toupperW(wch);
1501 dstlen--;
1502 }
1503 }
1504 else if (flags & LCMAP_LOWERCASE)
1505 {
1506 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1507 {
1508 WCHAR wch = *src;
1509 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1510 continue;
1511 *dst_ptr++ = tolowerW(wch);
1512 dstlen--;
1513 }
1514 }
1515 else
1516 {
1517 if (src == dst)
1518 {
1519 SetLastError(ERROR_INVALID_FLAGS);
1520 return 0;
1521 }
1522 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1523 {
1524 WCHAR wch = *src;
1525 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1526 continue;
1527 *dst_ptr++ = wch;
1528 dstlen--;
1529 }
1530 }
1531
1532 if (srclen)
1533 {
1534 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1535 return 0;
1536 }
1537
1538 return dst_ptr - dst;
1539 }
1540
1541 /*************************************************************************
1542 * LCMapStringW (KERNEL32.@)
1543 *
1544 * See LCMapStringA.
1545 */
1546 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
1547 LPWSTR dst, INT dstlen)
1548 {
1549 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1550 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1551
1552 return LCMapStringEx(NULL, flags, src, srclen, dst, dstlen, NULL, NULL, 0);
1553 }
1554
1555 /*************************************************************************
1556 * LCMapStringA (KERNEL32.@)
1557 *
1558 * Map characters in a locale sensitive string.
1559 *
1560 * PARAMS
1561 * lcid [I] LCID for the conversion.
1562 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
1563 * src [I] String to map
1564 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1565 * dst [O] Destination for mapped string
1566 * dstlen [I] Length of dst in characters
1567 *
1568 * RETURNS
1569 * Success: The length of the mapped string in dst, including the NUL terminator.
1570 * Failure: 0. Use GetLastError() to determine the cause.
1571 */
1572 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
1573 LPSTR dst, INT dstlen)
1574 {
1575 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
1576 LPWSTR srcW, dstW;
1577 INT ret = 0, srclenW, dstlenW;
1578 UINT locale_cp = CP_ACP;
1579
1580 if (!src || !srclen || dstlen < 0)
1581 {
1582 SetLastError(ERROR_INVALID_PARAMETER);
1583 return 0;
1584 }
1585
1586 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1587
1588 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
1589 if (srclenW)
1590 srcW = bufW;
1591 else
1592 {
1593 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
1594 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1595 if (!srcW)
1596 {
1597 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1598 return 0;
1599 }
1600 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
1601 }
1602
1603 if (flags & LCMAP_SORTKEY)
1604 {
1605 if (src == dst)
1606 {
1607 SetLastError(ERROR_INVALID_FLAGS);
1608 goto map_string_exit;
1609 }
1610 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
1611 if (ret == 0)
1612 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1613 else
1614 ret++;
1615 goto map_string_exit;
1616 }
1617
1618 if (flags & SORT_STRINGSORT)
1619 {
1620 SetLastError(ERROR_INVALID_FLAGS);
1621 goto map_string_exit;
1622 }
1623
1624 dstlenW = LCMapStringEx(NULL, flags, srcW, srclenW, NULL, 0, NULL, NULL, 0);
1625 if (!dstlenW)
1626 goto map_string_exit;
1627
1628 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
1629 if (!dstW)
1630 {
1631 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1632 goto map_string_exit;
1633 }
1634
1635 LCMapStringEx(NULL, flags, srcW, srclenW, dstW, dstlenW, NULL, NULL, 0);
1636 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
1637 HeapFree(GetProcessHeap(), 0, dstW);
1638
1639 map_string_exit:
1640 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
1641 return ret;
1642 }
1643
1644 /*************************************************************************
1645 * FoldStringA (KERNEL32.@)
1646 *
1647 * Map characters in a string.
1648 *
1649 * PARAMS
1650 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
1651 * src [I] String to map
1652 * srclen [I] Length of src, or -1 if src is NUL terminated
1653 * dst [O] Destination for mapped string
1654 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
1655 *
1656 * RETURNS
1657 * Success: The length of the string written to dst, including the terminating NUL. If
1658 * dstlen is 0, the value returned is the same, but nothing is written to dst,
1659 * and dst may be NULL.
1660 * Failure: 0. Use GetLastError() to determine the cause.
1661 */
1662 INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen,
1663 LPSTR dst, INT dstlen)
1664 {
1665 INT ret = 0, srclenW = 0;
1666 WCHAR *srcW = NULL, *dstW = NULL;
1667
1668 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1669 {
1670 SetLastError(ERROR_INVALID_PARAMETER);
1671 return 0;
1672 }
1673
1674 srclenW = MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1675 src, srclen, NULL, 0);
1676 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1677
1678 if (!srcW)
1679 {
1680 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1681 goto FoldStringA_exit;
1682 }
1683
1684 MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1685 src, srclen, srcW, srclenW);
1686
1687 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
1688
1689 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
1690 if (ret && dstlen)
1691 {
1692 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
1693
1694 if (!dstW)
1695 {
1696 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1697 goto FoldStringA_exit;
1698 }
1699
1700 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
1701 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
1702 {
1703 ret = 0;
1704 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1705 }
1706 }
1707
1708 HeapFree(GetProcessHeap(), 0, dstW);
1709
1710 FoldStringA_exit:
1711 HeapFree(GetProcessHeap(), 0, srcW);
1712 return ret;
1713 }
1714
1715 /*************************************************************************
1716 * FoldStringW (KERNEL32.@)
1717 *
1718 * See FoldStringA.
1719 */
1720 INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen,
1721 LPWSTR dst, INT dstlen)
1722 {
1723 int ret;
1724
1725 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
1726 {
1727 case 0:
1728 if (dwFlags)
1729 break;
1730 /* Fall through for dwFlags == 0 */
1731 case MAP_PRECOMPOSED|MAP_COMPOSITE:
1732 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
1733 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
1734 SetLastError(ERROR_INVALID_FLAGS);
1735 return 0;
1736 }
1737
1738 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1739 {
1740 SetLastError(ERROR_INVALID_PARAMETER);
1741 return 0;
1742 }
1743
1744 ret = wine_fold_string(dwFlags, src, srclen, dst, dstlen);
1745 if (!ret)
1746 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1747 return ret;
1748 }
1749
1750 /******************************************************************************
1751 * CompareStringW (KERNEL32.@)
1752 *
1753 * See CompareStringA.
1754 */
1755 INT WINAPI CompareStringW(LCID lcid, DWORD style,
1756 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
1757 {
1758 INT ret;
1759
1760 if (!str1 || !str2)
1761 {
1762 SetLastError(ERROR_INVALID_PARAMETER);
1763 return 0;
1764 }
1765
1766 if( style & ~(NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS|
1767 SORT_STRINGSORT|NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH|LOCALE_USE_CP_ACP|0x10000000) )
1768 {
1769 SetLastError(ERROR_INVALID_FLAGS);
1770 return 0;
1771 }
1772
1773 /* this style is related to diacritics in Arabic, Japanese, and Hebrew */
1774 if (style & 0x10000000)
1775 WARN("Ignoring unknown style 0x10000000\n");
1776
1777 if (len1 < 0) len1 = strlenW(str1);
1778 if (len2 < 0) len2 = strlenW(str2);
1779
1780 ret = wine_compare_string(style, str1, len1, str2, len2);
1781
1782 if (ret) /* need to translate result */
1783 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
1784 return CSTR_EQUAL;
1785 }
1786
1787 /******************************************************************************
1788 * CompareStringA (KERNEL32.@)
1789 *
1790 * Compare two locale sensitive strings.
1791 *
1792 * PARAMS
1793 * lcid [I] LCID for the comparison
1794 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
1795 * str1 [I] First string to compare
1796 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
1797 * str2 [I] Second string to compare
1798 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
1799 *
1800 * RETURNS
1801 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
1802 * str1 is less than, equal to or greater than str2 respectively.
1803 * Failure: FALSE. Use GetLastError() to determine the cause.
1804 */
1805 INT WINAPI CompareStringA(LCID lcid, DWORD flags,
1806 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
1807 {
1808 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
1809 WCHAR *buf2W = buf1W + 130;
1810 LPWSTR str1W, str2W;
1811 INT len1W = 0, len2W = 0, ret;
1812 UINT locale_cp = CP_ACP;
1813
1814 if (!str1 || !str2)
1815 {
1816 SetLastError(ERROR_INVALID_PARAMETER);
1817 return 0;
1818 }
1819 if (len1 < 0) len1 = strlen(str1);
1820 if (len2 < 0) len2 = strlen(str2);
1821
1822 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1823
1824 if (len1)
1825 {
1826 if (len1 <= 130) len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
1827 if (len1W)
1828 str1W = buf1W;
1829 else
1830 {
1831 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
1832 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
1833 if (!str1W)
1834 {
1835 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1836 return 0;
1837 }
1838 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
1839 }
1840 }
1841 else
1842 {
1843 len1W = 0;
1844 str1W = buf1W;
1845 }
1846
1847 if (len2)
1848 {
1849 if (len2 <= 130) len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
1850 if (len2W)
1851 str2W = buf2W;
1852 else
1853 {
1854 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
1855 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
1856 if (!str2W)
1857 {
1858 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1859 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1860 return 0;
1861 }
1862 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
1863 }
1864 }
1865 else
1866 {
1867 len2W = 0;
1868 str2W = buf2W;
1869 }
1870
1871 ret = CompareStringW(lcid, flags, str1W, len1W, str2W, len2W);
1872
1873 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1874 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
1875 return ret;
1876 }
1877
1878 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
1879 {
1880 UNICODE_STRING keyName;
1881 OBJECT_ATTRIBUTES attr;
1882 HANDLE hkey;
1883
1884 RtlInitUnicodeString( &keyName, szKeyName );
1885 InitializeObjectAttributes(&attr, &keyName, OBJ_CASE_INSENSITIVE, hRootKey, NULL);
1886
1887 if (NtOpenKey( &hkey, KEY_READ, &attr ) != STATUS_SUCCESS)
1888 hkey = 0;
1889
1890 return hkey;
1891 }
1892
1893 static BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex,
1894 LPWSTR szValueName, ULONG valueNameSize,
1895 LPWSTR szValueData, ULONG valueDataSize)
1896 {
1897 BYTE buffer[80];
1898 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1899 DWORD dwLen;
1900
1901 if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
1902 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
1903 info->NameLength > valueNameSize ||
1904 info->DataLength > valueDataSize)
1905 {
1906 return FALSE;
1907 }
1908
1909 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info->Name), info->DataLength);
1910
1911 memcpy( szValueName, info->Name, info->NameLength);
1912 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
1913 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
1914 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
1915
1916 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
1917 return TRUE;
1918 }
1919
1920 static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
1921 {
1922 BYTE buffer[128];
1923 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
1924 DWORD dwSize = sizeof(buffer);
1925 UNICODE_STRING valueName;
1926
1927 RtlInitUnicodeString( &valueName, szValueName );
1928
1929 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
1930 if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
1931 buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
1932 info->DataLength == sizeof(DWORD))
1933 {
1934 memcpy(lpVal, info->Data, sizeof(DWORD));
1935 return TRUE;
1936 }
1937
1938 return FALSE;
1939 }
1940
1941 static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
1942 {
1943 LANGID langId;
1944 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
1945 HRSRC hResource;
1946 BOOL bRet = FALSE;
1947
1948 /* FIXME: Is it correct to use the system default langid? */
1949 langId = GetSystemDefaultLangID();
1950
1951 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
1952 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
1953
1954 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
1955
1956 if (hResource)
1957 {
1958 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
1959
1960 if (hResDir)
1961 {
1962 ULONG iResourceIndex = lgrpid & 0xf;
1963 LPCWSTR lpResEntry = LockResource( hResDir );
1964 ULONG i;
1965
1966 for (i = 0; i < iResourceIndex; i++)
1967 lpResEntry += *lpResEntry + 1;
1968
1969 if (*lpResEntry < nameSize)
1970 {
1971 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
1972 szName[*lpResEntry] = '\0';
1973 bRet = TRUE;
1974 }
1975
1976 }
1977 FreeResource( hResource );
1978 }
1979 return bRet;
1980 }
1981
1982 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
1983 typedef struct
1984 {
1985 LANGUAGEGROUP_ENUMPROCA procA;
1986 LANGUAGEGROUP_ENUMPROCW procW;
1987 DWORD dwFlags;
1988 LONG_PTR lParam;
1989 } ENUMLANGUAGEGROUP_CALLBACKS;
1990
1991 /* Internal implementation of EnumSystemLanguageGroupsA/W */
1992 static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
1993 {
1994 WCHAR szNumber[10], szValue[4];
1995 HANDLE hKey;
1996 BOOL bContinue = TRUE;
1997 ULONG ulIndex = 0;
1998
1999 if (!lpProcs)
2000 {
2001 SetLastError(ERROR_INVALID_PARAMETER);
2002 return FALSE;
2003 }
2004
2005 switch (lpProcs->dwFlags)
2006 {
2007 case 0:
2008 /* Default to LGRPID_INSTALLED */
2009 lpProcs->dwFlags = LGRPID_INSTALLED;
2010 /* Fall through... */
2011 case LGRPID_INSTALLED:
2012 case LGRPID_SUPPORTED:
2013 break;
2014 default:
2015 SetLastError(ERROR_INVALID_FLAGS);
2016 return FALSE;
2017 }
2018
2019 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2020
2021 if (!hKey)
2022 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2023
2024 while (bContinue)
2025 {
2026 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2027 szValue, sizeof(szValue) ))
2028 {
2029 BOOL bInstalled = szValue[0] == '1' ? TRUE : FALSE;
2030 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
2031
2032 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
2033 bInstalled ? "" : "not ");
2034
2035 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
2036 {
2037 WCHAR szGrpName[48];
2038
2039 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
2040 szGrpName[0] = '\0';
2041
2042 if (lpProcs->procW)
2043 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
2044 lpProcs->lParam );
2045 else
2046 {
2047 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2048 char szGrpNameA[48];
2049
2050 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2051 * or whether the language names are ever localised. Assume CP_ACP.
2052 */
2053
2054 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2055 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
2056
2057 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
2058 lpProcs->lParam );
2059 }
2060 }
2061
2062 ulIndex++;
2063 }
2064 else
2065 bContinue = FALSE;
2066
2067 if (!bContinue)
2068 break;
2069 }
2070
2071 if (hKey)
2072 NtClose( hKey );
2073
2074 return TRUE;
2075 }
2076
2077 /******************************************************************************
2078 * EnumSystemLanguageGroupsA (KERNEL32.@)
2079 *
2080 * Call a users function for each language group available on the system.
2081 *
2082 * PARAMS
2083 * pLangGrpEnumProc [I] Callback function to call for each language group
2084 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2085 * lParam [I] User parameter to pass to pLangGrpEnumProc
2086 *
2087 * RETURNS
2088 * Success: TRUE.
2089 * Failure: FALSE. Use GetLastError() to determine the cause.
2090 */
2091 BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
2092 DWORD dwFlags, LONG_PTR lParam)
2093 {
2094 ENUMLANGUAGEGROUP_CALLBACKS procs;
2095
2096 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2097
2098 procs.procA = pLangGrpEnumProc;
2099 procs.procW = NULL;
2100 procs.dwFlags = dwFlags;
2101 procs.lParam = lParam;
2102
2103 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2104 }
2105
2106 /******************************************************************************
2107 * EnumSystemLanguageGroupsW (KERNEL32.@)
2108 *
2109 * See EnumSystemLanguageGroupsA.
2110 */
2111 BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
2112 DWORD dwFlags, LONG_PTR lParam)
2113 {
2114 ENUMLANGUAGEGROUP_CALLBACKS procs;
2115
2116 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2117
2118 procs.procA = NULL;
2119 procs.procW = pLangGrpEnumProc;
2120 procs.dwFlags = dwFlags;
2121 procs.lParam = lParam;
2122
2123 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2124 }
2125
2126 /******************************************************************************
2127 * IsValidLanguageGroup (KERNEL32.@)
2128 *
2129 * Determine if a language group is supported and/or installed.
2130 *
2131 * PARAMS
2132 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2133 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2134 *
2135 * RETURNS
2136 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2137 * FALSE otherwise.
2138 */
2139 BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
2140 {
2141 static const WCHAR szFormat[] = { '%','x','\0' };
2142 WCHAR szValueName[16], szValue[2];
2143 BOOL bSupported = FALSE, bInstalled = FALSE;
2144 HANDLE hKey;
2145
2146
2147 switch (dwFlags)
2148 {
2149 case LGRPID_INSTALLED:
2150 case LGRPID_SUPPORTED:
2151
2152 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2153
2154 sprintfW( szValueName, szFormat, lgrpid );
2155
2156 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)szValue ))
2157 {
2158 bSupported = TRUE;
2159
2160 if (szValue[0] == '1')
2161 bInstalled = TRUE;
2162 }
2163
2164 if (hKey)
2165 NtClose( hKey );
2166
2167 break;
2168 }
2169
2170 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
2171 (dwFlags == LGRPID_INSTALLED && bInstalled))
2172 return TRUE;
2173
2174 return FALSE;
2175 }
2176
2177 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2178 typedef struct
2179 {
2180 LANGGROUPLOCALE_ENUMPROCA procA;
2181 LANGGROUPLOCALE_ENUMPROCW procW;
2182 DWORD dwFlags;
2183 LGRPID lgrpid;
2184 LONG_PTR lParam;
2185 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
2186
2187 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2188 static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
2189 {
2190 static const WCHAR szAlternateSortsKeyName[] = {
2191 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2192 };
2193 WCHAR szNumber[10], szValue[4];
2194 HANDLE hKey;
2195 BOOL bContinue = TRUE, bAlternate = FALSE;
2196 LGRPID lgrpid;
2197 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
2198
2199 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
2200 {
2201 SetLastError(ERROR_INVALID_PARAMETER);
2202 return FALSE;
2203 }
2204
2205 if (lpProcs->dwFlags)
2206 {
2207 SetLastError(ERROR_INVALID_FLAGS);
2208 return FALSE;
2209 }
2210
2211 hKey = NLS_RegOpenKey( 0, szLocaleKeyName );
2212
2213 if (!hKey)
2214 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2215
2216 while (bContinue)
2217 {
2218 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2219 szValue, sizeof(szValue) ))
2220 {
2221 lgrpid = strtoulW( szValue, NULL, 16 );
2222
2223 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber),
2224 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
2225
2226 if (lgrpid == lpProcs->lgrpid)
2227 {
2228 LCID lcid;
2229
2230 lcid = strtoulW( szNumber, NULL, 16 );
2231
2232 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2233 * '00000437 ;Georgian'
2234 * At present we only pass the LCID string.
2235 */
2236
2237 if (lpProcs->procW)
2238 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
2239 else
2240 {
2241 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2242
2243 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2244
2245 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
2246 }
2247 }
2248
2249 ulIndex++;
2250 }
2251 else
2252 {
2253 /* Finished enumerating this key */
2254 if (!bAlternate)
2255 {
2256 /* Enumerate alternate sorts also */
2257 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
2258 bAlternate = TRUE;
2259 ulIndex = 0;
2260 }
2261 else
2262 bContinue = FALSE; /* Finished both keys */
2263 }
2264
2265 if (!bContinue)
2266 break;
2267 }
2268
2269 if (hKey)
2270 NtClose( hKey );
2271
2272 return TRUE;
2273 }
2274
2275 enum locationkind {
2276 LOCATION_NATION = 0,
2277 LOCATION_REGION,
2278 LOCATION_BOTH
2279 };
2280
2281 struct geoinfo_t {
2282 GEOID id;
2283 WCHAR iso2W[3];
2284 WCHAR iso3W[4];
2285 GEOID parent;
2286 INT uncode;
2287 enum locationkind kind;
2288 };
2289
2290 static const struct geoinfo_t geoinfodata[] = {
2291 { 2, {'A','G',0}, {'A','T','G',0}, 10039880, 28 }, /* Antigua and Barbuda */
2292 { 3, {'A','F',0}, {'A','F','G',0}, 47614, 4 }, /* Afghanistan */
2293 { 4, {'D','Z',0}, {'D','Z','A',0}, 42487, 12 }, /* Algeria */
2294 { 5, {'A','Z',0}, {'A','Z','E',0}, 47611, 31 }, /* Azerbaijan */
2295 { 6, {'A','L',0}, {'A','L','B',0}, 47610, 8 }, /* Albania */
2296 { 7, {'A','M',0}, {'A','R','M',0}, 47611, 51 }, /* Armenia */
2297 { 8, {'A','D',0}, {'A','N','D',0}, 47610, 20 }, /* Andorra */
2298 { 9, {'A','O',0}, {'A','G','O',0}, 42484, 24 }, /* Angola */
2299 { 10, {'A','S',0}, {'A','S','M',0}, 26286, 16 }, /* American Samoa */
2300 { 11, {'A','R',0}, {'A','R','G',0}, 31396, 32 }, /* Argentina */
2301 { 12, {'A','U',0}, {'A','U','S',0}, 10210825, 36 }, /* Australia */
2302 { 14, {'A','T',0}, {'A','U','T',0}, 10210824, 40 }, /* Austria */
2303 { 17, {'B','H',0}, {'B','H','R',0}, 47611, 48 }, /* Bahrain */
2304 { 18, {'B','B',0}, {'B','R','B',0}, 10039880, 52 }, /* Barbados */
2305 { 19, {'B','W',0}, {'B','W','A',0}, 10039883, 72 }, /* Botswana */
2306 { 20, {'B','M',0}, {'B','M','U',0}, 23581, 60 }, /* Bermuda */
2307 { 21, {'B','E',0}, {'B','E','L',0}, 10210824, 56 }, /* Belgium */
2308 { 22, {'B','S',0}, {'B','H','S',0}, 10039880, 44 }, /* Bahamas, The */
2309 { 23, {'B','D',0}, {'B','G','D',0}, 47614, 50 }, /* Bangladesh */
2310 { 24, {'B','Z',0}, {'B','L','Z',0}, 27082, 84 }, /* Belize */
2311 { 25, {'B','A',0}, {'B','I','H',0}, 47610, 70 }, /* Bosnia and Herzegovina */
2312 { 26, {'B','O',0}, {'B','O','L',0}, 31396, 68 }, /* Bolivia */
2313 { 27, {'M','M',0}, {'M','M','R',0}, 47599, 104 }, /* Myanmar */
2314 { 28, {'B','J',0}, {'B','E','N',0}, 42483, 204 }, /* Benin */
2315 { 29, {'B','Y',0}, {'B','L','R',0}, 47609, 112 }, /* Belarus */
2316 { 30, {'S','B',0}, {'S','L','B',0}, 20900, 90 }, /* Solomon Islands */
2317 { 32, {'B','R',0}, {'B','R','A',0}, 31396, 76 }, /* Brazil */
2318 { 34, {'B','T',0}, {'B','T','N',0}, 47614, 64 }, /* Bhutan */
2319 { 35, {'B','G',0}, {'B','G','R',0}, 47609, 100 }, /* Bulgaria */
2320 { 37, {'B','N',0}, {'B','R','N',0}, 47599, 96 }, /* Brunei */
2321 { 38, {'B','I',0}, {'B','D','I',0}, 47603, 108 }, /* Burundi */
2322 { 39, {'C','A',0}, {'C','A','N',0}, 23581, 124 }, /* Canada */
2323 { 40, {'K','H',0}, {'K','H','M',0}, 47599, 116 }, /* Cambodia */
2324 { 41, {'T','D',0}, {'T','C','D',0}, 42484, 148 }, /* Chad */
2325 { 42, {'L','K',0}, {'L','K','A',0}, 47614, 144 }, /* Sri Lanka */
2326 { 43, {'C','G',0}, {'C','O','G',0}, 42484, 178 }, /* Congo */
2327 { 44, {'C','D',0}, {'C','O','D',0}, 42484, 180 }, /* Congo (DRC) */
2328 { 45, {'C','N',0}, {'C','H','N',0}, 47600, 156 }, /* China */
2329 { 46, {'C','L',0}, {'C','H','L',0}, 31396, 152 }, /* Chile */
2330 { 49, {'C','M',0}, {'C','M','R',0}, 42484, 120 }, /* Cameroon */
2331 { 50, {'K','M',0}, {'C','O','M',0}, 47603, 174 }, /* Comoros */
2332 { 51, {'C','O',0}, {'C','O','L',0}, 31396, 170 }, /* Colombia */
2333 { 54, {'C','R',0}, {'C','R','I',0}, 27082, 188 }, /* Costa Rica */
2334 { 55, {'C','F',0}, {'C','A','F',0}, 42484, 140 }, /* Central African Republic */
2335 { 56, {'C','U',0}, {'C','U','B',0}, 10039880, 192 }, /* Cuba */
2336 { 57, {'C','V',0}, {'C','P','V',0}, 42483, 132 }, /* Cape Verde */
2337 { 59, {'C','Y',0}, {'C','Y','P',0}, 47611, 196 }, /* Cyprus */
2338 { 61, {'D','K',0}, {'D','N','K',0}, 10039882, 208 }, /* Denmark */
2339 { 62, {'D','J',0}, {'D','J','I',0}, 47603, 262 }, /* Djibouti */
2340 { 63, {'D','M',0}, {'D','M','A',0}, 10039880, 212 }, /* Dominica */
2341 { 65, {'D','O',0}, {'D','O','M',0}, 10039880, 214 }, /* Dominican Republic */
2342 { 66, {'E','C',0}, {'E','C','U',0}, 31396, 218 }, /* Ecuador */
2343 { 67, {'E','G',0}, {'E','G','Y',0}, 42487, 818 }, /* Egypt */
2344 { 68, {'I','E',0}, {'I','R','L',0}, 10039882, 372 }, /* Ireland */
2345 { 69, {'G','Q',0}, {'G','N','Q',0}, 42484, 226 }, /* Equatorial Guinea */
2346 { 70, {'E','E',0}, {'E','S','T',0}, 10039882, 233 }, /* Estonia */
2347 { 71, {'E','R',0}, {'E','R','I',0}, 47603, 232 }, /* Eritrea */
2348 { 72, {'S','V',0}, {'S','L','V',0}, 27082, 222 }, /* El Salvador */
2349 { 73, {'E','T',0}, {'E','T','H',0}, 47603, 231 }, /* Ethiopia */
2350 { 75, {'C','Z',0}, {'C','Z','E',0}, 47609, 203 }, /* Czech Republic */
2351 { 77, {'F','I',0}, {'F','I','N',0}, 10039882, 246 }, /* Finland */
2352 { 78, {'F','J',0}, {'F','J','I',0}, 20900, 242 }, /* Fiji Islands */
2353 { 80, {'F','M',0}, {'F','S','M',0}, 21206, 583 }, /* Micronesia */
2354 { 81, {'F','O',0}, {'F','R','O',0}, 10039882, 234 }, /* Faroe Islands */
2355 { 84, {'F','R',0}, {'F','R','A',0}, 10210824, 250 }, /* France */
2356 { 86, {'G','M',0}, {'G','M','B',0}, 42483, 270 }, /* Gambia, The */
2357 { 87, {'G','A',0}, {'G','A','B',0}, 42484, 266 }, /* Gabon */
2358 { 88, {'G','E',0}, {'G','E','O',0}, 47611, 268 }, /* Georgia */
2359 { 89, {'G','H',0}, {'G','H','A',0}, 42483, 288 }, /* Ghana */
2360 { 90, {'G','I',0}, {'G','I','B',0}, 47610, 292 }, /* Gibraltar */
2361 { 91, {'G','D',0}, {'G','R','D',0}, 10039880, 308 }, /* Grenada */
2362 { 93, {'G','L',0}, {'G','R','L',0}, 23581, 304 }, /* Greenland */
2363 { 94, {'D','E',0}, {'D','E','U',0}, 10210824, 276 }, /* Germany */
2364 { 98, {'G','R',0}, {'G','R','C',0}, 47610, 300 }, /* Greece */
2365 { 99, {'G','T',0}, {'G','T','M',0}, 27082, 320 }, /* Guatemala */
2366 { 100, {'G','N',0}, {'G','I','N',0}, 42483, 324 }, /* Guinea */
2367 { 101, {'G','Y',0}, {'G','U','Y',0}, 31396, 328 }, /* Guyana */
2368 { 103, {'H','T',0}, {'H','T','I',0}, 10039880, 332 }, /* Haiti */
2369 { 104, {'H','K',0}, {'H','K','G',0}, 47600, 344 }, /* Hong Kong S.A.R. */
2370 { 106, {'H','N',0}, {'H','N','D',0}, 27082, 340 }, /* Honduras */
2371 { 108, {'H','R',0}, {'H','R','V',0}, 47610, 191 }, /* Croatia */
2372 { 109, {'H','U',0}, {'H','U','N',0}, 47609, 348 }, /* Hungary */
2373 { 110, {'I','S',0}, {'I','S','L',0}, 10039882, 352 }, /* Iceland */
2374 { 111, {'I','D',0}, {'I','D','N',0}, 47599, 360 }, /* Indonesia */
2375 { 113, {'I','N',0}, {'I','N','D',0}, 47614, 356 }, /* India */
2376 { 114, {'I','O',0}, {'I','O','T',0}, 39070, 86 }, /* British Indian Ocean Territory */
2377 { 116, {'I','R',0}, {'I','R','N',0}, 47614, 364 }, /* Iran */
2378 { 117, {'I','L',0}, {'I','S','R',0}, 47611, 376 }, /* Israel */
2379 { 118, {'I','T',0}, {'I','T','A',0}, 47610, 380 }, /* Italy */
2380 { 119, {'C','I',0}, {'C','I','V',0}, 42483, 384 }, /* Côte d'Ivoire */
2381 { 121, {'I','Q',0}, {'I','R','Q',0}, 47611, 368 }, /* Iraq */
2382 { 122, {'J','P',0}, {'J','P','N',0}, 47600, 392 }, /* Japan */
2383 { 124, {'J','M',0}, {'J','A','M',0}, 10039880, 388 }, /* Jamaica */
2384 { 125, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Jan Mayen */
2385 { 126, {'J','O',0}, {'J','O','R',0}, 47611, 400 }, /* Jordan */
2386 { 127, {'X','X',0}, {'X','X',0}, 161832256 }, /* Johnston Atoll */
2387 { 129, {'K','E',0}, {'K','E','N',0}, 47603, 404 }, /* Kenya */
2388 { 130, {'K','G',0}, {'K','G','Z',0}, 47590, 417 }, /* Kyrgyzstan */
2389 { 131, {'K','P',0}, {'P','R','K',0}, 47600, 408 }, /* North Korea */
2390 { 133, {'K','I',0}, {'K','I','R',0}, 21206, 296 }, /* Kiribati */
2391 { 134, {'K','R',0}, {'K','O','R',0}, 47600, 410 }, /* Korea */
2392 { 136, {'K','W',0}, {'K','W','T',0}, 47611, 414 }, /* Kuwait */
2393 { 137, {'K','Z',0}, {'K','A','Z',0}, 47590, 398 }, /* Kazakhstan */
2394 { 138, {'L','A',0}, {'L','A','O',0}, 47599, 418 }, /* Laos */
2395 { 139, {'L','B',0}, {'L','B','N',0}, 47611, 422 }, /* Lebanon */
2396 { 140, {'L','V',0}, {'L','V','A',0}, 10039882, 428 }, /* Latvia */
2397 { 141, {'L','T',0}, {'L','T','U',0}, 10039882, 440 }, /* Lithuania */
2398 { 142, {'L','R',0}, {'L','B','R',0}, 42483, 430 }, /* Liberia */
2399 { 143, {'S','K',0}, {'S','V','K',0}, 47609, 703 }, /* Slovakia */
2400 { 145, {'L','I',0}, {'L','I','E',0}, 10210824, 438 }, /* Liechtenstein */
2401 { 146, {'L','S',0}, {'L','S','O',0}, 10039883, 426 }, /* Lesotho */
2402 { 147, {'L','U',0}, {'L','U','X',0}, 10210824, 442 }, /* Luxembourg */
2403 { 148, {'L','Y',0}, {'L','B','Y',0}, 42487, 434 }, /* Libya */
2404 { 149, {'M','G',0}, {'M','D','G',0}, 47603, 450 }, /* Madagascar */
2405 { 151, {'M','O',0}, {'M','A','C',0}, 47600, 446 }, /* Macao S.A.R. */
2406 { 152, {'M','D',0}, {'M','D','A',0}, 47609, 498 }, /* Moldova */
2407 { 154, {'M','N',0}, {'M','N','G',0}, 47600, 496 }, /* Mongolia */
2408 { 156, {'M','W',0}, {'M','W','I',0}, 47603, 454 }, /* Malawi */
2409 { 157, {'M','L',0}, {'M','L','I',0}, 42483, 466 }, /* Mali */
2410 { 158, {'M','C',0}, {'M','C','O',0}, 10210824, 492 }, /* Monaco */
2411 { 159, {'M','A',0}, {'M','A','R',0}, 42487, 504 }, /* Morocco */
2412 { 160, {'M','U',0}, {'M','U','S',0}, 47603, 480 }, /* Mauritius */
2413 { 162, {'M','R',0}, {'M','R','T',0}, 42483, 478 }, /* Mauritania */
2414 { 163, {'M','T',0}, {'M','L','T',0}, 47610, 470 }, /* Malta */
2415 { 164, {'O','M',0}, {'O','M','N',0}, 47611, 512 }, /* Oman */
2416 { 165, {'M','V',0}, {'M','D','V',0}, 47614, 462 }, /* Maldives */
2417 { 166, {'M','X',0}, {'M','E','X',0}, 27082, 484 }, /* Mexico */
2418 { 167, {'M','Y',0}, {'M','Y','S',0}, 47599, 458 }, /* Malaysia */
2419 { 168, {'M','Z',0}, {'M','O','Z',0}, 47603, 508 }, /* Mozambique */
2420 { 173, {'N','E',0}, {'N','E','R',0}, 42483, 562 }, /* Niger */
2421 { 174, {'V','U',0}, {'V','U','T',0}, 20900, 548 }, /* Vanuatu */
2422 { 175, {'N','G',0}, {'N','G','A',0}, 42483, 566 }, /* Nigeria */
2423 { 176, {'N','L',0}, {'N','L','D',0}, 10210824, 528 }, /* Netherlands */
2424 { 177, {'N','O',0}, {'N','O','R',0}, 10039882, 578 }, /* Norway */
2425 { 178, {'N','P',0}, {'N','P','L',0}, 47614, 524 }, /* Nepal */
2426 { 180, {'N','R',0}, {'N','R','U',0}, 21206, 520 }, /* Nauru */
2427 { 181, {'S','R',0}, {'S','U','R',0}, 31396, 740 }, /* Suriname */
2428 { 182, {'N','I',0}, {'N','I','C',0}, 27082, 558 }, /* Nicaragua */
2429 { 183, {'N','Z',0}, {'N','Z','L',0}, 10210825, 554 }, /* New Zealand */
2430 { 184, {'P','S',0}, {'P','S','E',0}, 47611, 275 }, /* Palestinian Authority */
2431 { 185, {'P','Y',0}, {'P','R','Y',0}, 31396, 600 }, /* Paraguay */
2432 { 187, {'P','E',0}, {'P','E','R',0}, 31396, 604 }, /* Peru */
2433 { 190, {'P','K',0}, {'P','A','K',0}, 47614, 586 }, /* Pakistan */
2434 { 191, {'P','L',0}, {'P','O','L',0}, 47609, 616 }, /* Poland */
2435 { 192, {'P','A',0}, {'P','A','N',0}, 27082, 591 }, /* Panama */
2436 { 193, {'P','T',0}, {'P','R','T',0}, 47610, 620 }, /* Portugal */
2437 { 194, {'P','G',0}, {'P','N','G',0}, 20900, 598 }, /* Papua New Guinea */
2438 { 195, {'P','W',0}, {'P','L','W',0}, 21206, 585 }, /* Palau */
2439 { 196, {'G','W',0}, {'G','N','B',0}, 42483, 624 }, /* Guinea-Bissau */
2440 { 197, {'Q','A',0}, {'Q','A','T',0}, 47611, 634 }, /* Qatar */
2441 { 198, {'R','E',0}, {'R','E','U',0}, 47603, 638 }, /* Reunion */
2442 { 199, {'M','H',0}, {'M','H','L',0}, 21206, 584 }, /* Marshall Islands */
2443 { 200, {'R','O',0}, {'R','O','U',0}, 47609, 642 }, /* Romania */
2444 { 201, {'P','H',0}, {'P','H','L',0}, 47599, 608 }, /* Philippines */
2445 { 202, {'P','R',0}, {'P','R','I',0}, 10039880, 630 }, /* Puerto Rico */
2446 { 203, {'R','U',0}, {'R','U','S',0}, 47609, 643 }, /* Russia */
2447 { 204, {'R','W',0}, {'R','W','A',0}, 47603, 646 }, /* Rwanda */
2448 { 205, {'S','A',0}, {'S','A','U',0}, 47611, 682 }, /* Saudi Arabia */
2449 { 206, {'P','M',0}, {'S','P','M',0}, 23581, 666 }, /* St. Pierre and Miquelon */
2450 { 207, {'K','N',0}, {'K','N','A',0}, 10039880, 659 }, /* St. Kitts and Nevis */
2451 { 208, {'S','C',0}, {'S','Y','C',0}, 47603, 690 }, /* Seychelles */
2452 { 209, {'Z','A',0}, {'Z','A','F',0}, 10039883, 710 }, /* South Africa */
2453 { 210, {'S','N',0}, {'S','E','N',0}, 42483, 686 }, /* Senegal */
2454 { 212, {'S','I',0}, {'S','V','N',0}, 47610, 705 }, /* Slovenia */
2455 { 213, {'S','L',0}, {'S','L','E',0}, 42483, 694 }, /* Sierra Leone */
2456 { 214, {'S','M',0}, {'S','M','R',0}, 47610, 674 }, /* San Marino */
2457 { 215, {'S','G',0}, {'S','G','P',0}, 47599, 702 }, /* Singapore */
2458 { 216, {'S','O',0}, {'S','O','M',0}, 47603, 706 }, /* Somalia */
2459 { 217, {'E','S',0}, {'E','S','P',0}, 47610, 724 }, /* Spain */
2460 { 218, {'L','C',0}, {'L','C','A',0}, 10039880, 662 }, /* St. Lucia */
2461 { 219, {'S','D',0}, {'S','D','N',0}, 42487, 736 }, /* Sudan */
2462 { 220, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Svalbard */
2463 { 221, {'S','E',0}, {'S','W','E',0}, 10039882, 752 }, /* Sweden */
2464 { 222, {'S','Y',0}, {'S','Y','R',0}, 47611, 760 }, /* Syria */
2465 { 223, {'C','H',0}, {'C','H','E',0}, 10210824, 756 }, /* Switzerland */
2466 { 224, {'A','E',0}, {'A','R','E',0}, 47611, 784 }, /* United Arab Emirates */
2467 { 225, {'T','T',0}, {'T','T','O',0}, 10039880, 780 }, /* Trinidad and Tobago */
2468 { 227, {'T','H',0}, {'T','H','A',0}, 47599, 764 }, /* Thailand */
2469 { 228, {'T','J',0}, {'T','J','K',0}, 47590, 762 }, /* Tajikistan */
2470 { 231, {'T','O',0}, {'T','O','N',0}, 26286, 776 }, /* Tonga */
2471 { 232, {'T','G',0}, {'T','G','O',0}, 42483, 768 }, /* Togo */
2472 { 233, {'S','T',0}, {'S','T','P',0}, 42484, 678 }, /* São Tomé and Príncipe */
2473 { 234, {'T','N',0}, {'T','U','N',0}, 42487, 788 }, /* Tunisia */
2474 { 235, {'T','R',0}, {'T','U','R',0}, 47611, 792 }, /* Turkey */
2475 { 236, {'T','V',0}, {'T','U','V',0}, 26286, 798 }, /* Tuvalu */
2476 { 237, {'T','W',0}, {'T','W','N',0}, 47600, 158 }, /* Taiwan */
2477 { 238, {'T','M',0}, {'T','K','M',0}, 47590, 795 }, /* Turkmenistan */
2478 { 239, {'T','Z',0}, {'T','Z','A',0}, 47603, 834 }, /* Tanzania */
2479 { 240, {'U','G',0}, {'U','G','A',0}, 47603, 800 }, /* Uganda */
2480 { 241, {'U','A',0}, {'U','K','R',0}, 47609, 804 }, /* Ukraine */
2481 { 242, {'G','B',0}, {'G','B','R',0}, 10039882, 826 }, /* United Kingdom */
2482 { 244, {'U','S',0}, {'U','S','A',0}, 23581, 840 }, /* United States */
2483 { 245, {'B','F',0}, {'B','F','A',0}, 42483, 854 }, /* Burkina Faso */
2484 { 246, {'U','Y',0}, {'U','R','Y',0}, 31396, 858 }, /* Uruguay */
2485 { 247, {'U','Z',0}, {'U','Z','B',0}, 47590, 860 }, /* Uzbekistan */
2486 { 248, {'V','C',0}, {'V','C','T',0}, 10039880, 670 }, /* St. Vincent and the Grenadines */
2487 { 249, {'V','E',0}, {'V','E','N',0}, 31396, 862 }, /* Bolivarian Republic of Venezuela */
2488 { 251, {'V','N',0}, {'V','N','M',0}, 47599, 704 }, /* Vietnam */
2489 { 252, {'V','I',0}, {'V','I','R',0}, 10039880, 850 }, /* Virgin Islands */
2490 { 253, {'V','A',0}, {'V','A','T',0}, 47610, 336 }, /* Vatican City */
2491 { 254, {'N','A',0}, {'N','A','M',0}, 10039883, 516 }, /* Namibia */
2492 { 257, {'E','H',0}, {'E','S','H',0}, 42487, 732 }, /* Western Sahara (disputed) */
2493 { 258, {'X','X',0}, {'X','X',0}, 161832256 }, /* Wake Island */
2494 { 259, {'W','S',0}, {'W','S','M',0}, 26286, 882 }, /* Samoa */
2495 { 260, {'S','Z',0}, {'S','W','Z',0}, 10039883, 748 }, /* Swaziland */
2496 { 261, {'Y','E',0}, {'Y','E','M',0}, 47611, 887 }, /* Yemen */
2497 { 263, {'Z','M',0}, {'Z','M','B',0}, 47603, 894 }, /* Zambia */
2498 { 264, {'Z','W',0}, {'Z','W','E',0}, 47603, 716 }, /* Zimbabwe */
2499 { 269, {'C','S',0}, {'S','C','G',0}, 47610, 891 }, /* Serbia and Montenegro (Former) */
2500 { 270, {'M','E',0}, {'M','N','E',0}, 47610, 499 }, /* Montenegro */
2501 { 271, {'R','S',0}, {'S','R','B',0}, 47610, 688 }, /* Serbia */
2502 { 273, {'C','W',0}, {'C','U','W',0}, 10039880, 531 }, /* Curaçao */
2503 { 276, {'S','S',0}, {'S','S','D',0}, 42487, 728 }, /* South Sudan */
2504 { 300, {'A','I',0}, {'A','I','A',0}, 10039880, 660 }, /* Anguilla */
2505 { 301, {'A','Q',0}, {'A','T','A',0}, 39070, 10 }, /* Antarctica */
2506 { 302, {'A','W',0}, {'A','B','W',0}, 10039880, 533 }, /* Aruba */
2507 { 303, {'X','X',0}, {'X','X',0}, 39070 }, /* Ascension Island */
2508 { 304, {'X','X',0}, {'X','X',0}, 10210825 }, /* Ashmore and Cartier Islands */
2509 { 305, {'X','X',0}, {'X','X',0}, 161832256 }, /* Baker Island */
2510 { 306, {'B','V',0}, {'B','V','T',0}, 39070, 74 }, /* Bouvet Island */
2511 { 307, {'K','Y',0}, {'C','Y','M',0}, 10039880, 136 }, /* Cayman Islands */
2512 { 308, {'X','X',0}, {'X','X',0}, 10210824, 0, LOCATION_BOTH }, /* Channel Islands */
2513 { 309, {'C','X',0}, {'C','X','R',0}, 12, 162 }, /* Christmas Island */
2514 { 310, {'X','X',0}, {'X','X',0}, 27114 }, /* Clipperton Island */
2515 { 311, {'C','C',0}, {'C','C','K',0}, 10210825, 166 }, /* Cocos (Keeling) Islands */
2516 { 312, {'C','K',0}, {'C','O','K',0}, 26286, 184 }, /* Cook Islands */
2517 { 313, {'X','X',0}, {'X','X',0}, 10210825 }, /* Coral Sea Islands */
2518 { 314, {'X','X',0}, {'X','X',0}, 114 }, /* Diego Garcia */
2519 { 315, {'F','K',0}, {'F','L','K',0}, 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
2520 { 317, {'G','F',0}, {'G','U','F',0}, 31396, 254 }, /* French Guiana */
2521 { 318, {'P','F',0}, {'P','Y','F',0}, 26286, 258 }, /* French Polynesia */
2522 { 319, {'T','F',0}, {'A','T','F',0}, 39070, 260 }, /* French Southern and Antarctic Lands */
2523 { 321, {'G','P',0}, {'G','L','P',0}, 10039880, 312 }, /* Guadeloupe */
2524 { 322, {'G','U',0}, {'G','U','M',0}, 21206, 316 }, /* Guam */
2525 { 323, {'X','X',0}, {'X','X',0}, 39070 }, /* Guantanamo Bay */
2526 { 324, {'G','G',0}, {'G','G','Y',0}, 308, 831 }, /* Guernsey */
2527 { 325, {'H','M',0}, {'H','M','D',0}, 39070, 334 }, /* Heard Island and McDonald Islands */
2528 { 326, {'X','X',0}, {'X','X',0}, 161832256 }, /* Howland Island */
2529 { 327, {'X','X',0}, {'X','X',0}, 161832256 }, /* Jarvis Island */
2530 { 328, {'J','E',0}, {'J','E','Y',0}, 308, 832 }, /* Jersey */
2531 { 329, {'X','X',0}, {'X','X',0}, 161832256 }, /* Kingman Reef */
2532 { 330, {'M','Q',0}, {'M','T','Q',0}, 10039880, 474 }, /* Martinique */
2533 { 331, {'Y','T',0}, {'M','Y','T',0}, 47603, 175 }, /* Mayotte */
2534 { 332, {'M','S',0}, {'M','S','R',0}, 10039880, 500 }, /* Montserrat */
2535 { 333, {'A','N',0}, {'A','N','T',0}, 10039880, 530, LOCATION_BOTH }, /* Netherlands Antilles (Former) */
2536 { 334, {'N','C',0}, {'N','C','L',0}, 20900, 540 }, /* New Caledonia */
2537 { 335, {'N','U',0}, {'N','I','U',0}, 26286, 570 }, /* Niue */
2538 { 336, {'N','F',0}, {'N','F','K',0}, 10210825, 574 }, /* Norfolk Island */
2539 { 337, {'M','P',0}, {'M','N','P',0}, 21206, 580 }, /* Northern Mariana Islands */
2540 { 338, {'X','X',0}, {'X','X',0}, 161832256 }, /* Palmyra Atoll */
2541 { 339, {'P','N',0}, {'P','C','N',0}, 26286, 612 }, /* Pitcairn Islands */
2542 { 340, {'X','X',0}, {'X','X',0}, 337 }, /* Rota Island */
2543 { 341, {'X','X',0}, {'X','X',0}, 337 }, /* Saipan */
2544 { 342, {'G','S',0}, {'S','G','S',0}, 39070, 239 }, /* South Georgia and the South Sandwich Islands */
2545 { 343, {'S','H',0}, {'S','H','N',0}, 42483, 654 }, /* St. Helena */
2546 { 346, {'X','X',0}, {'X','X',0}, 337 }, /* Tinian Island */
2547 { 347, {'T','K',0}, {'T','K','L',0}, 26286, 772 }, /* Tokelau */
2548 { 348, {'X','X',0}, {'X','X',0}, 39070 }, /* Tristan da Cunha */
2549 { 349, {'T','C',0}, {'T','C','A',0}, 10039880, 796 }, /* Turks and Caicos Islands */
2550 { 351, {'V','G',0}, {'V','G','B',0}, 10039880, 92 }, /* Virgin Islands, British */
2551 { 352, {'W','F',0}, {'W','L','F',0}, 26286, 876 }, /* Wallis and Futuna */
2552 { 742, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Africa */
2553 { 2129, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Asia */
2554 { 10541, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Europe */
2555 { 15126, {'I','M',0}, {'I','M','N',0}, 10039882, 833 }, /* Man, Isle of */
2556 { 19618, {'M'<