ReactOS 0.4.16-dev-853-g88d9285
lcidtoname_downlevel.cpp
Go to the documentation of this file.
1//
2// lcidtoname_downlevel.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Definitions of wrappers for the Windows XP API functions that are not available on
7// all supported operating system versions.
8//
9
10#include <corecrt_internal.h>
11
12namespace {
13
14// Map of LCID to locale name.
16{
18 wchar_t* localeName;
19};
20
21// Map of locale name to an index.
23{
24 wchar_t* name;
25 int index;
26};
27
28// Map of LCID to locale name for Windows XP.
29// Data in this table has been obtained from National Language Support (NLS) API Reference at
30// http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx
31// The table is sorted to improve search performance.
33{
34 { 0x0001, L"ar" },
35 { 0x0002, L"bg" },
36 { 0x0003, L"ca" },
37 { 0x0004, L"zh-CHS" },
38 { 0x0005, L"cs" },
39 { 0x0006, L"da" },
40 { 0x0007, L"de" },
41 { 0x0008, L"el" },
42 { 0x0009, L"en" },
43 { 0x000A, L"es" },
44 { 0x000B, L"fi" },
45 { 0x000C, L"fr" },
46 { 0x000D, L"he" },
47 { 0x000E, L"hu" },
48 { 0x000F, L"is" },
49 { 0x0010, L"it" },
50 { 0x0011, L"ja" },
51 { 0x0012, L"ko" },
52 { 0x0013, L"nl" },
53 { 0x0014, L"no" },
54 { 0x0015, L"pl" },
55 { 0x0016, L"pt" },
56 { 0x0018, L"ro" },
57 { 0x0019, L"ru" },
58 { 0x001A, L"hr" },
59 { 0x001B, L"sk" },
60 { 0x001C, L"sq" },
61 { 0x001D, L"sv" },
62 { 0x001E, L"th" },
63 { 0x001F, L"tr" },
64 { 0x0020, L"ur" },
65 { 0x0021, L"id" },
66 { 0x0022, L"uk" },
67 { 0x0023, L"be" },
68 { 0x0024, L"sl" },
69 { 0x0025, L"et" },
70 { 0x0026, L"lv" },
71 { 0x0027, L"lt" },
72 { 0x0029, L"fa" },
73 { 0x002A, L"vi" },
74 { 0x002B, L"hy" },
75 { 0x002C, L"az" },
76 { 0x002D, L"eu" },
77 { 0x002F, L"mk" },
78 { 0x0036, L"af" },
79 { 0x0037, L"ka" },
80 { 0x0038, L"fo" },
81 { 0x0039, L"hi" },
82 { 0x003E, L"ms" },
83 { 0x003F, L"kk" },
84 { 0x0040, L"ky" },
85 { 0x0041, L"sw" },
86 { 0x0043, L"uz" },
87 { 0x0044, L"tt" },
88 { 0x0046, L"pa" },
89 { 0x0047, L"gu" },
90 { 0x0049, L"ta" },
91 { 0x004A, L"te" },
92 { 0x004B, L"kn" },
93 { 0x004E, L"mr" },
94 { 0x004F, L"sa" },
95 { 0x0050, L"mn" },
96 { 0x0056, L"gl" },
97 { 0x0057, L"kok" },
98 { 0x005A, L"syr" },
99 { 0x0065, L"div" },
100 { 0x007f, L"" },
101 { 0x0401, L"ar-SA" },
102 { 0x0402, L"bg-BG" },
103 { 0x0403, L"ca-ES" },
104 { 0x0404, L"zh-TW" },
105 { 0x0405, L"cs-CZ" },
106 { 0x0406, L"da-DK" },
107 { 0x0407, L"de-DE" },
108 { 0x0408, L"el-GR" },
109 { 0x0409, L"en-US" },
110 { 0x040B, L"fi-FI" },
111 { 0x040C, L"fr-FR" },
112 { 0x040D, L"he-IL" },
113 { 0x040E, L"hu-HU" },
114 { 0x040F, L"is-IS" },
115 { 0x0410, L"it-IT" },
116 { 0x0411, L"ja-JP" },
117 { 0x0412, L"ko-KR" },
118 { 0x0413, L"nl-NL" },
119 { 0x0414, L"nb-NO" },
120 { 0x0415, L"pl-PL" },
121 { 0x0416, L"pt-BR" },
122 { 0x0418, L"ro-RO" },
123 { 0x0419, L"ru-RU" },
124 { 0x041A, L"hr-HR" },
125 { 0x041B, L"sk-SK" },
126 { 0x041C, L"sq-AL" },
127 { 0x041D, L"sv-SE" },
128 { 0x041E, L"th-TH" },
129 { 0x041F, L"tr-TR" },
130 { 0x0420, L"ur-PK" },
131 { 0x0421, L"id-ID" },
132 { 0x0422, L"uk-UA" },
133 { 0x0423, L"be-BY" },
134 { 0x0424, L"sl-SI" },
135 { 0x0425, L"et-EE" },
136 { 0x0426, L"lv-LV" },
137 { 0x0427, L"lt-LT" },
138 { 0x0429, L"fa-IR" },
139 { 0x042A, L"vi-VN" },
140 { 0x042B, L"hy-AM" },
141 { 0x042C, L"az-AZ-Latn" },
142 { 0x042D, L"eu-ES" },
143 { 0x042F, L"mk-MK" },
144 { 0x0432, L"tn-ZA" },
145 { 0x0434, L"xh-ZA" },
146 { 0x0435, L"zu-ZA" },
147 { 0x0436, L"af-ZA" },
148 { 0x0437, L"ka-GE" },
149 { 0x0438, L"fo-FO" },
150 { 0x0439, L"hi-IN" },
151 { 0x043A, L"mt-MT" },
152 { 0x043B, L"se-NO" },
153 { 0x043E, L"ms-MY" },
154 { 0x043F, L"kk-KZ" },
155 { 0x0440, L"ky-KG" },
156 { 0x0441, L"sw-KE" },
157 { 0x0443, L"uz-UZ-Latn" },
158 { 0x0444, L"tt-RU" },
159 { 0x0445, L"bn-IN" },
160 { 0x0446, L"pa-IN" },
161 { 0x0447, L"gu-IN" },
162 { 0x0449, L"ta-IN" },
163 { 0x044A, L"te-IN" },
164 { 0x044B, L"kn-IN" },
165 { 0x044C, L"ml-IN" },
166 { 0x044E, L"mr-IN" },
167 { 0x044F, L"sa-IN" },
168 { 0x0450, L"mn-MN" },
169 { 0x0452, L"cy-GB" },
170 { 0x0456, L"gl-ES" },
171 { 0x0457, L"kok-IN" },
172 { 0x045A, L"syr-SY" },
173 { 0x0465, L"div-MV" },
174 { 0x046B, L"quz-BO" },
175 { 0x046C, L"ns-ZA" },
176 { 0x0481, L"mi-NZ" },
177 { 0x0801, L"ar-IQ" },
178 { 0x0804, L"zh-CN" },
179 { 0x0807, L"de-CH" },
180 { 0x0809, L"en-GB" },
181 { 0x080A, L"es-MX" },
182 { 0x080C, L"fr-BE" },
183 { 0x0810, L"it-CH" },
184 { 0x0813, L"nl-BE" },
185 { 0x0814, L"nn-NO" },
186 { 0x0816, L"pt-PT" },
187 { 0x081A, L"sr-SP-Latn" },
188 { 0x081D, L"sv-FI" },
189 { 0x082C, L"az-AZ-Cyrl" },
190 { 0x083B, L"se-SE" },
191 { 0x083E, L"ms-BN" },
192 { 0x0843, L"uz-UZ-Cyrl" },
193 { 0x086B, L"quz-EC" },
194 { 0x0C01, L"ar-EG" },
195 { 0x0C04, L"zh-HK" },
196 { 0x0C07, L"de-AT" },
197 { 0x0C09, L"en-AU" },
198 { 0x0C0A, L"es-ES" },
199 { 0x0C0C, L"fr-CA" },
200 { 0x0C1A, L"sr-SP-Cyrl" },
201 { 0x0C3B, L"se-FI" },
202 { 0x0C6B, L"quz-PE" },
203 { 0x1001, L"ar-LY" },
204 { 0x1004, L"zh-SG" },
205 { 0x1007, L"de-LU" },
206 { 0x1009, L"en-CA" },
207 { 0x100A, L"es-GT" },
208 { 0x100C, L"fr-CH" },
209 { 0x101A, L"hr-BA" },
210 { 0x103B, L"smj-NO" },
211 { 0x1401, L"ar-DZ" },
212 { 0x1404, L"zh-MO" },
213 { 0x1407, L"de-LI" },
214 { 0x1409, L"en-NZ" },
215 { 0x140A, L"es-CR" },
216 { 0x140C, L"fr-LU" },
217 { 0x141A, L"bs-BA-Latn" },
218 { 0x143B, L"smj-SE" },
219 { 0x1801, L"ar-MA" },
220 { 0x1809, L"en-IE" },
221 { 0x180A, L"es-PA" },
222 { 0x180C, L"fr-MC" },
223 { 0x181A, L"sr-BA-Latn" },
224 { 0x183B, L"sma-NO" },
225 { 0x1C01, L"ar-TN" },
226 { 0x1C09, L"en-ZA" },
227 { 0x1C0A, L"es-DO" },
228 { 0x1C1A, L"sr-BA-Cyrl" },
229 { 0x1C3B, L"sma-SE" },
230 { 0x2001, L"ar-OM" },
231 { 0x2009, L"en-JM" },
232 { 0x200A, L"es-VE" },
233 { 0x203B, L"sms-FI" },
234 { 0x2401, L"ar-YE" },
235 { 0x2409, L"en-CB" },
236 { 0x240A, L"es-CO" },
237 { 0x243B, L"smn-FI" },
238 { 0x2801, L"ar-SY" },
239 { 0x2809, L"en-BZ" },
240 { 0x280A, L"es-PE" },
241 { 0x2C01, L"ar-JO" },
242 { 0x2C09, L"en-TT" },
243 { 0x2C0A, L"es-AR" },
244 { 0x3001, L"ar-LB" },
245 { 0x3009, L"en-ZW" },
246 { 0x300A, L"es-EC" },
247 { 0x3401, L"ar-KW" },
248 { 0x3409, L"en-PH" },
249 { 0x340A, L"es-CL" },
250 { 0x3801, L"ar-AE" },
251 { 0x380A, L"es-UY" },
252 { 0x3C01, L"ar-BH" },
253 { 0x3C0A, L"es-PY" },
254 { 0x4001, L"ar-QA" },
255 { 0x400A, L"es-BO" },
256 { 0x440A, L"es-SV" },
257 { 0x480A, L"es-HN" },
258 { 0x4C0A, L"es-NI" },
259 { 0x500A, L"es-PR" },
260 { 0x7C04, L"zh-CHT" },
261 { 0x7C1A, L"sr" }
262};
263
264// Map of locale name to an index in LcidToLocaleNameTable, for Windows XP.
265// Data in this table has been obtained from National Language Support (NLS) API Reference at
266// http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx
267// The table is sorted to improve search performance.
269{
270 { L"" , 66 },
271 { L"af" , 44 },
272 { L"af-za" , 113 },
273 { L"ar" , 0 },
274 { L"ar-ae" , 216 },
275 { L"ar-bh" , 218 },
276 { L"ar-dz" , 177 },
277 { L"ar-eg" , 160 },
278 { L"ar-iq" , 143 },
279 { L"ar-jo" , 207 },
280 { L"ar-kw" , 213 },
281 { L"ar-lb" , 210 },
282 { L"ar-ly" , 169 },
283 { L"ar-ma" , 185 },
284 { L"ar-om" , 196 },
285 { L"ar-qa" , 220 },
286 { L"ar-sa" , 67 },
287 { L"ar-sy" , 204 },
288 { L"ar-tn" , 191 },
289 { L"ar-ye" , 200 },
290 { L"az" , 41 },
291 { L"az-az-cyrl" , 155 },
292 { L"az-az-latn" , 107 },
293 { L"be" , 33 },
294 { L"be-by" , 99 },
295 { L"bg" , 1 },
296 { L"bg-bg" , 68 },
297 { L"bn-in" , 125 },
298 { L"bs-ba-latn" , 183 },
299 { L"ca" , 2 },
300 { L"ca-es" , 69 },
301 { L"cs" , 4 },
302 { L"cs-cz" , 71 },
303 { L"cy-gb" , 135 },
304 { L"da" , 5 },
305 { L"da-dk" , 72 },
306 { L"de" , 6 },
307 { L"de-at" , 162 },
308 { L"de-ch" , 145 },
309 { L"de-de" , 73 },
310 { L"de-li" , 179 },
311 { L"de-lu" , 171 },
312 { L"div" , 65 },
313 { L"div-mv" , 139 },
314 { L"el" , 7 },
315 { L"el-gr" , 74 },
316 { L"en" , 8 },
317 { L"en-au" , 163 },
318 { L"en-bz" , 205 },
319 { L"en-ca" , 172 },
320 { L"en-cb" , 201 },
321 { L"en-gb" , 146 },
322 { L"en-ie" , 186 },
323 { L"en-jm" , 197 },
324 { L"en-nz" , 180 },
325 { L"en-ph" , 214 },
326 { L"en-tt" , 208 },
327 { L"en-us" , 75 },
328 { L"en-za" , 192 },
329 { L"en-zw" , 211 },
330 { L"es" , 9 },
331 { L"es-ar" , 209 },
332 { L"es-bo" , 221 },
333 { L"es-cl" , 215 },
334 { L"es-co" , 202 },
335 { L"es-cr" , 181 },
336 { L"es-do" , 193 },
337 { L"es-ec" , 212 },
338 { L"es-es" , 164 },
339 { L"es-gt" , 173 },
340 { L"es-hn" , 223 },
341 { L"es-mx" , 147 },
342 { L"es-ni" , 224 },
343 { L"es-pa" , 187 },
344 { L"es-pe" , 206 },
345 { L"es-pr" , 225 },
346 { L"es-py" , 219 },
347 { L"es-sv" , 222 },
348 { L"es-uy" , 217 },
349 { L"es-ve" , 198 },
350 { L"et" , 35 },
351 { L"et-ee" , 101 },
352 { L"eu" , 42 },
353 { L"eu-es" , 108 },
354 { L"fa" , 38 },
355 { L"fa-ir" , 104 },
356 { L"fi" , 10 },
357 { L"fi-fi" , 76 },
358 { L"fo" , 46 },
359 { L"fo-fo" , 115 },
360 { L"fr" , 11 },
361 { L"fr-be" , 148 },
362 { L"fr-ca" , 165 },
363 { L"fr-ch" , 174 },
364 { L"fr-fr" , 77 },
365 { L"fr-lu" , 182 },
366 { L"fr-mc" , 188 },
367 { L"gl" , 62 },
368 { L"gl-es" , 136 },
369 { L"gu" , 55 },
370 { L"gu-in" , 127 },
371 { L"he" , 12 },
372 { L"he-il" , 78 },
373 { L"hi" , 47 },
374 { L"hi-in" , 116 },
375 { L"hr" , 24 },
376 { L"hr-ba" , 175 },
377 { L"hr-hr" , 90 },
378 { L"hu" , 13 },
379 { L"hu-hu" , 79 },
380 { L"hy" , 40 },
381 { L"hy-am" , 106 },
382 { L"id" , 31 },
383 { L"id-id" , 97 },
384 { L"is" , 14 },
385 { L"is-is" , 80 },
386 { L"it" , 15 },
387 { L"it-ch" , 149 },
388 { L"it-it" , 81 },
389 { L"ja" , 16 },
390 { L"ja-jp" , 82 },
391 { L"ka" , 45 },
392 { L"ka-ge" , 114 },
393 { L"kk" , 49 },
394 { L"kk-kz" , 120 },
395 { L"kn" , 58 },
396 { L"kn-in" , 130 },
397 { L"ko" , 17 },
398 { L"kok" , 63 },
399 { L"kok-in" , 137 },
400 { L"ko-kr" , 83 },
401 { L"ky" , 50 },
402 { L"ky-kg" , 121 },
403 { L"lt" , 37 },
404 { L"lt-lt" , 103 },
405 { L"lv" , 36 },
406 { L"lv-lv" , 102 },
407 { L"mi-nz" , 142 },
408 { L"mk" , 43 },
409 { L"mk-mk" , 109 },
410 { L"ml-in" , 131 },
411 { L"mn" , 61 },
412 { L"mn-mn" , 134 },
413 { L"mr" , 59 },
414 { L"mr-in" , 132 },
415 { L"ms" , 48 },
416 { L"ms-bn" , 157 },
417 { L"ms-my" , 119 },
418 { L"mt-mt" , 117 },
419 { L"nb-no" , 85 },
420 { L"nl" , 18 },
421 { L"nl-be" , 150 },
422 { L"nl-nl" , 84 },
423 { L"nn-no" , 151 },
424 { L"no" , 19 },
425 { L"ns-za" , 141 },
426 { L"pa" , 54 },
427 { L"pa-in" , 126 },
428 { L"pl" , 20 },
429 { L"pl-pl" , 86 },
430 { L"pt" , 21 },
431 { L"pt-br" , 87 },
432 { L"pt-pt" , 152 },
433 { L"quz-bo" , 140 },
434 { L"quz-ec" , 159 },
435 { L"quz-pe" , 168 },
436 { L"ro" , 22 },
437 { L"ro-ro" , 88 },
438 { L"ru" , 23 },
439 { L"ru-ru" , 89 },
440 { L"sa" , 60 },
441 { L"sa-in" , 133 },
442 { L"se-fi" , 167 },
443 { L"se-no" , 118 },
444 { L"se-se" , 156 },
445 { L"sk" , 25 },
446 { L"sk-sk" , 91 },
447 { L"sl" , 34 },
448 { L"sl-si" , 100 },
449 { L"sma-no" , 190 },
450 { L"sma-se" , 195 },
451 { L"smj-no" , 176 },
452 { L"smj-se" , 184 },
453 { L"smn-fi" , 203 },
454 { L"sms-fi" , 199 },
455 { L"sq" , 26 },
456 { L"sq-al" , 92 },
457 { L"sr" , 227 },
458 { L"sr-ba-cyrl" , 194 },
459 { L"sr-ba-latn" , 189 },
460 { L"sr-sp-cyrl" , 166 },
461 { L"sr-sp-latn" , 153 },
462 { L"sv" , 27 },
463 { L"sv-fi" , 154 },
464 { L"sv-se" , 93 },
465 { L"sw" , 51 },
466 { L"sw-ke" , 122 },
467 { L"syr" , 64 },
468 { L"syr-sy" , 138 },
469 { L"ta" , 56 },
470 { L"ta-in" , 128 },
471 { L"te" , 57 },
472 { L"te-in" , 129 },
473 { L"th" , 28 },
474 { L"th-th" , 94 },
475 { L"tn-za" , 110 },
476 { L"tr" , 29 },
477 { L"tr-tr" , 95 },
478 { L"tt" , 53 },
479 { L"tt-ru" , 124 },
480 { L"uk" , 32 },
481 { L"uk-ua" , 98 },
482 { L"ur" , 30 },
483 { L"ur-pk" , 96 },
484 { L"uz" , 52 },
485 { L"uz-uz-cyrl" , 158 },
486 { L"uz-uz-latn" , 123 },
487 { L"vi" , 39 },
488 { L"vi-vn" , 105 },
489 { L"xh-za" , 111 },
490 { L"zh-chs" , 3 },
491 { L"zh-cht" , 226 },
492 { L"zh-cn" , 144 },
493 { L"zh-hk" , 161 },
494 { L"zh-mo" , 178 },
495 { L"zh-sg" , 170 },
496 { L"zh-tw" , 70 },
497 { L"zu-za" , 112 }
498};
499
500} // unnamed namespace
501
502// Maps input locale name to the index on LcidToLocaleNameTable
503static int GetTableIndexFromLocaleName(const wchar_t* localeName) throw()
504{
505 LocaleNameIndex *localeNamesIndex = (LocaleNameIndex *) LocaleNameToIndexTable;
506 int bottom = 0;
508
509 while (bottom <= top)
510 {
511 int middle = (bottom + top) / 2;
512 int testIndex = __ascii_wcsnicmp(localeName, localeNamesIndex[middle].name, LOCALE_NAME_MAX_LENGTH);
513
514 if (testIndex == 0)
515 return localeNamesIndex[middle].index;
516
517 if (testIndex < 0)
518 top = middle - 1;
519 else
520 bottom = middle + 1;
521 }
522
523 return -1;
524}
525
526// Maps input LCID to an index in LcidToLocaleNameTable
527static int GetTableIndexFromLcid(LCID lcid) throw()
528{
529
530 int bottom = 0;
532
533 while (bottom <= top)
534 {
535 int middle = (bottom + top) / 2;
536 int testIndex = lcid - LcidToLocaleNameTable[middle].lcid;
537
538 if (testIndex == 0)
539 return middle;
540
541 if (testIndex < 0)
542 top = middle - 1;
543 else
544 bottom = middle + 1;
545 }
546
547 return -1;
548}
549
550
552{
553 int index;
554
555 if (localeName == nullptr)
556 return 0;
557
559
560 if (index < 0 || (index >= _countof(LcidToLocaleNameTable)))
561 return 0;
562
564}
565
567 LCID lcid,
568 LPWSTR outLocaleName,
569 int cchLocaleName
570 )
571{
572 size_t count;
573 wchar_t* buffer;
574 int index;
575
576 if (lcid == 0 ||
577 lcid == LOCALE_USER_DEFAULT ||
578 lcid == LOCALE_SYSTEM_DEFAULT)
579 {
580 return 0;
581 }
582
583 if ((outLocaleName == nullptr && cchLocaleName>0) || cchLocaleName < 0)
584 {
585 return 0;
586 }
587
589 if (index < 0)
590 return 0;
591
594
595 if (cchLocaleName > 0)
596 {
597 if ((int)count >= cchLocaleName)
598 return 0;
599
600 _ERRCHECK(wcscpy_s(outLocaleName, cchLocaleName, buffer));
601 }
602
603 return (int) count + 1;
604}
#define __cdecl
Definition: accygwin.h:79
#define index(s, c)
Definition: various.h:29
_Check_return_ int __cdecl __ascii_wcsnicmp(_In_reads_or_z_(count) const wchar_t *lhs, _In_reads_or_z_(count) const wchar_t *rhs, _In_ size_t count)
_In_ int cchLocaleName
#define _ERRCHECK(e)
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLuint index
Definition: glext.h:6031
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLint GLint bottom
Definition: glext.h:7726
static int GetTableIndexFromLocaleName(const wchar_t *localeName)
LCID __cdecl __acrt_DownlevelLocaleNameToLCID(LPCWSTR localeName)
int __cdecl __acrt_DownlevelLCIDToLocaleName(LCID lcid, LPWSTR outLocaleName, int cchLocaleName)
static int GetTableIndexFromLcid(LCID lcid)
#define wcscpy_s(d, l, s)
Definition: utility.h:201
static const LocaleNameIndex LocaleNameToIndexTable[]
static const LcidToLocaleName LcidToLocaleNameTable[]
#define LOCALE_NAME_MAX_LENGTH
#define LOCALE_USER_DEFAULT
#define LOCALE_SYSTEM_DEFAULT
#define L(x)
Definition: ntvdm.h:50
DWORD LCID
Definition: nls.h:13
#define _countof(array)
Definition: sndvol32.h:70
size_t __cdecl wcsnlen(wchar_t const *const string, size_t const maximum_count)
Definition: strnlen.cpp:210
Definition: name.c:39
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185