4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2003 Jon Griffiths
8 * Copyright 2005 Dmitry Timoshkov
9 * Copyright 2002, 2019 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #define WIN32_NO_STATUS
31 #define WINNORMALIZEAPI
38 #include "kernelbase.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(nls
);
43 #define CALINFO_MAX_YEAR 2029
45 extern const unsigned int collation_table
[] DECLSPEC_HIDDEN
;
47 static HANDLE kernel32_handle
;
49 static const struct registry_value
55 { LOCALE_ICALENDARTYPE
, L
"iCalendarType" },
56 { LOCALE_ICURRDIGITS
, L
"iCurrDigits" },
57 { LOCALE_ICURRENCY
, L
"iCurrency" },
58 { LOCALE_IDIGITS
, L
"iDigits" },
59 { LOCALE_IFIRSTDAYOFWEEK
, L
"iFirstDayOfWeek" },
60 { LOCALE_IFIRSTWEEKOFYEAR
, L
"iFirstWeekOfYear" },
61 { LOCALE_ILZERO
, L
"iLZero" },
62 { LOCALE_IMEASURE
, L
"iMeasure" },
63 { LOCALE_INEGCURR
, L
"iNegCurr" },
64 { LOCALE_INEGNUMBER
, L
"iNegNumber" },
65 { LOCALE_IPAPERSIZE
, L
"iPaperSize" },
66 { LOCALE_ITIME
, L
"iTime" },
67 { LOCALE_S1159
, L
"s1159" },
68 { LOCALE_S2359
, L
"s2359" },
69 { LOCALE_SCURRENCY
, L
"sCurrency" },
70 { LOCALE_SDATE
, L
"sDate" },
71 { LOCALE_SDECIMAL
, L
"sDecimal" },
72 { LOCALE_SGROUPING
, L
"sGrouping" },
73 { LOCALE_SLIST
, L
"sList" },
74 { LOCALE_SLONGDATE
, L
"sLongDate" },
75 { LOCALE_SMONDECIMALSEP
, L
"sMonDecimalSep" },
76 { LOCALE_SMONGROUPING
, L
"sMonGrouping" },
77 { LOCALE_SMONTHOUSANDSEP
, L
"sMonThousandSep" },
78 { LOCALE_SNEGATIVESIGN
, L
"sNegativeSign" },
79 { LOCALE_SPOSITIVESIGN
, L
"sPositiveSign" },
80 { LOCALE_SSHORTDATE
, L
"sShortDate" },
81 { LOCALE_STHOUSAND
, L
"sThousand" },
82 { LOCALE_STIME
, L
"sTime" },
83 { LOCALE_STIMEFORMAT
, L
"sTimeFormat" },
84 { LOCALE_SYEARMONTH
, L
"sYearMonth" },
85 /* The following are not listed under MSDN as supported,
86 * but seem to be used and also stored in the registry.
88 { LOCALE_SNAME
, L
"LocaleName" },
89 { LOCALE_ICOUNTRY
, L
"iCountry" },
90 { LOCALE_IDATE
, L
"iDate" },
91 { LOCALE_ILDATE
, L
"iLDate" },
92 { LOCALE_ITLZERO
, L
"iTLZero" },
93 { LOCALE_SCOUNTRY
, L
"sCountry" },
94 { LOCALE_SABBREVLANGNAME
, L
"sLanguage" },
95 { LOCALE_IDIGITSUBSTITUTION
, L
"Numshape" },
96 { LOCALE_SNATIVEDIGITS
, L
"sNativeDigits" },
97 { LOCALE_ITIMEMARKPOSN
, L
"iTimePrefix" },
100 static WCHAR
*registry_cache
[ARRAY_SIZE(registry_values
)];
102 static const struct { UINT cp
; const WCHAR
*name
; } codepage_names
[] =
104 { 37, L
"IBM EBCDIC US Canada" },
105 { 424, L
"IBM EBCDIC Hebrew" },
106 { 437, L
"OEM United States" },
107 { 500, L
"IBM EBCDIC International" },
108 { 708, L
"Arabic ASMO" },
109 { 720, L
"Arabic (Transparent ASMO)" },
110 { 737, L
"OEM Greek 437G" },
111 { 775, L
"OEM Baltic" },
112 { 850, L
"OEM Multilingual Latin 1" },
113 { 852, L
"OEM Slovak Latin 2" },
114 { 855, L
"OEM Cyrillic" },
115 { 856, L
"Hebrew PC" },
116 { 857, L
"OEM Turkish" },
117 { 860, L
"OEM Portuguese" },
118 { 861, L
"OEM Icelandic" },
119 { 862, L
"OEM Hebrew" },
120 { 863, L
"OEM Canadian French" },
121 { 864, L
"OEM Arabic" },
122 { 865, L
"OEM Nordic" },
123 { 866, L
"OEM Russian" },
124 { 869, L
"OEM Greek" },
125 { 874, L
"ANSI/OEM Thai" },
126 { 875, L
"IBM EBCDIC Greek" },
127 { 878, L
"Russian KOI8" },
128 { 932, L
"ANSI/OEM Japanese Shift-JIS" },
129 { 936, L
"ANSI/OEM Simplified Chinese GBK" },
130 { 949, L
"ANSI/OEM Korean Unified Hangul" },
131 { 950, L
"ANSI/OEM Traditional Chinese Big5" },
132 { 1006, L
"IBM Arabic" },
133 { 1026, L
"IBM EBCDIC Latin 5 Turkish" },
134 { 1250, L
"ANSI Eastern Europe" },
135 { 1251, L
"ANSI Cyrillic" },
136 { 1252, L
"ANSI Latin 1" },
137 { 1253, L
"ANSI Greek" },
138 { 1254, L
"ANSI Turkish" },
139 { 1255, L
"ANSI Hebrew" },
140 { 1256, L
"ANSI Arabic" },
141 { 1257, L
"ANSI Baltic" },
142 { 1258, L
"ANSI/OEM Viet Nam" },
143 { 1361, L
"Korean Johab" },
144 { 10000, L
"Mac Roman" },
145 { 10001, L
"Mac Japanese" },
146 { 10002, L
"Mac Traditional Chinese" },
147 { 10003, L
"Mac Korean" },
148 { 10004, L
"Mac Arabic" },
149 { 10005, L
"Mac Hebrew" },
150 { 10006, L
"Mac Greek" },
151 { 10007, L
"Mac Cyrillic" },
152 { 10008, L
"Mac Simplified Chinese" },
153 { 10010, L
"Mac Romanian" },
154 { 10017, L
"Mac Ukrainian" },
155 { 10021, L
"Mac Thai" },
156 { 10029, L
"Mac Latin 2" },
157 { 10079, L
"Mac Icelandic" },
158 { 10081, L
"Mac Turkish" },
159 { 10082, L
"Mac Croatian" },
160 { 20127, L
"US-ASCII (7bit)" },
161 { 20866, L
"Russian KOI8" },
162 { 20932, L
"EUC-JP" },
163 { 20949, L
"Korean Wansung" },
164 { 21866, L
"Ukrainian KOI8" },
165 { 28591, L
"ISO 8859-1 Latin 1" },
166 { 28592, L
"ISO 8859-2 Latin 2 (East European)" },
167 { 28593, L
"ISO 8859-3 Latin 3 (South European)" },
168 { 28594, L
"ISO 8859-4 Latin 4 (Baltic old)" },
169 { 28595, L
"ISO 8859-5 Cyrillic" },
170 { 28596, L
"ISO 8859-6 Arabic" },
171 { 28597, L
"ISO 8859-7 Greek" },
172 { 28598, L
"ISO 8859-8 Hebrew" },
173 { 28599, L
"ISO 8859-9 Latin 5 (Turkish)" },
174 { 28600, L
"ISO 8859-10 Latin 6 (Nordic)" },
175 { 28601, L
"ISO 8859-11 Latin (Thai)" },
176 { 28603, L
"ISO 8859-13 Latin 7 (Baltic)" },
177 { 28604, L
"ISO 8859-14 Latin 8 (Celtic)" },
178 { 28605, L
"ISO 8859-15 Latin 9 (Euro)" },
179 { 28606, L
"ISO 8859-16 Latin 10 (Balkan)" },
180 { 65000, L
"Unicode (UTF-7)" },
181 { 65001, L
"Unicode (UTF-8)" }
184 /* Unicode expanded ligatures */
185 static const WCHAR ligatures
[][5] =
187 { 0x00c6, 'A','E',0 },
188 { 0x00de, 'T','H',0 },
189 { 0x00df, 's','s',0 },
190 { 0x00e6, 'a','e',0 },
191 { 0x00fe, 't','h',0 },
192 { 0x0132, 'I','J',0 },
193 { 0x0133, 'i','j',0 },
194 { 0x0152, 'O','E',0 },
195 { 0x0153, 'o','e',0 },
196 { 0x01c4, 'D',0x017d,0 },
197 { 0x01c5, 'D',0x017e,0 },
198 { 0x01c6, 'd',0x017e,0 },
199 { 0x01c7, 'L','J',0 },
200 { 0x01c8, 'L','j',0 },
201 { 0x01c9, 'l','j',0 },
202 { 0x01ca, 'N','J',0 },
203 { 0x01cb, 'N','j',0 },
204 { 0x01cc, 'n','j',0 },
205 { 0x01e2, 0x0100,0x0112,0 },
206 { 0x01e3, 0x0101,0x0113,0 },
207 { 0x01f1, 'D','Z',0 },
208 { 0x01f2, 'D','z',0 },
209 { 0x01f3, 'd','z',0 },
210 { 0x01fc, 0x00c1,0x00c9,0 },
211 { 0x01fd, 0x00e1,0x00e9,0 },
212 { 0x05f0, 0x05d5,0x05d5,0 },
213 { 0x05f1, 0x05d5,0x05d9,0 },
214 { 0x05f2, 0x05d9,0x05d9,0 },
215 { 0xfb00, 'f','f',0 },
216 { 0xfb01, 'f','i',0 },
217 { 0xfb02, 'f','l',0 },
218 { 0xfb03, 'f','f','i',0 },
219 { 0xfb04, 'f','f','l',0 },
220 { 0xfb05, 0x017f,'t',0 },
221 { 0xfb06, 's','t',0 },
224 enum locationkind
{ LOCATION_NATION
= 0, LOCATION_REGION
, LOCATION_BOTH
};
233 enum locationkind kind
;
236 static const struct geoinfo geoinfodata
[] =
238 { 2, L
"AG", L
"ATG", 10039880, 28 }, /* Antigua and Barbuda */
239 { 3, L
"AF", L
"AFG", 47614, 4 }, /* Afghanistan */
240 { 4, L
"DZ", L
"DZA", 42487, 12 }, /* Algeria */
241 { 5, L
"AZ", L
"AZE", 47611, 31 }, /* Azerbaijan */
242 { 6, L
"AL", L
"ALB", 47610, 8 }, /* Albania */
243 { 7, L
"AM", L
"ARM", 47611, 51 }, /* Armenia */
244 { 8, L
"AD", L
"AND", 47610, 20 }, /* Andorra */
245 { 9, L
"AO", L
"AGO", 42484, 24 }, /* Angola */
246 { 10, L
"AS", L
"ASM", 26286, 16 }, /* American Samoa */
247 { 11, L
"AR", L
"ARG", 31396, 32 }, /* Argentina */
248 { 12, L
"AU", L
"AUS", 10210825, 36 }, /* Australia */
249 { 14, L
"AT", L
"AUT", 10210824, 40 }, /* Austria */
250 { 17, L
"BH", L
"BHR", 47611, 48 }, /* Bahrain */
251 { 18, L
"BB", L
"BRB", 10039880, 52 }, /* Barbados */
252 { 19, L
"BW", L
"BWA", 10039883, 72 }, /* Botswana */
253 { 20, L
"BM", L
"BMU", 23581, 60 }, /* Bermuda */
254 { 21, L
"BE", L
"BEL", 10210824, 56 }, /* Belgium */
255 { 22, L
"BS", L
"BHS", 10039880, 44 }, /* Bahamas, The */
256 { 23, L
"BD", L
"BGD", 47614, 50 }, /* Bangladesh */
257 { 24, L
"BZ", L
"BLZ", 27082, 84 }, /* Belize */
258 { 25, L
"BA", L
"BIH", 47610, 70 }, /* Bosnia and Herzegovina */
259 { 26, L
"BO", L
"BOL", 31396, 68 }, /* Bolivia */
260 { 27, L
"MM", L
"MMR", 47599, 104 }, /* Myanmar */
261 { 28, L
"BJ", L
"BEN", 42483, 204 }, /* Benin */
262 { 29, L
"BY", L
"BLR", 47609, 112 }, /* Belarus */
263 { 30, L
"SB", L
"SLB", 20900, 90 }, /* Solomon Islands */
264 { 32, L
"BR", L
"BRA", 31396, 76 }, /* Brazil */
265 { 34, L
"BT", L
"BTN", 47614, 64 }, /* Bhutan */
266 { 35, L
"BG", L
"BGR", 47609, 100 }, /* Bulgaria */
267 { 37, L
"BN", L
"BRN", 47599, 96 }, /* Brunei */
268 { 38, L
"BI", L
"BDI", 47603, 108 }, /* Burundi */
269 { 39, L
"CA", L
"CAN", 23581, 124 }, /* Canada */
270 { 40, L
"KH", L
"KHM", 47599, 116 }, /* Cambodia */
271 { 41, L
"TD", L
"TCD", 42484, 148 }, /* Chad */
272 { 42, L
"LK", L
"LKA", 47614, 144 }, /* Sri Lanka */
273 { 43, L
"CG", L
"COG", 42484, 178 }, /* Congo */
274 { 44, L
"CD", L
"COD", 42484, 180 }, /* Congo (DRC) */
275 { 45, L
"CN", L
"CHN", 47600, 156 }, /* China */
276 { 46, L
"CL", L
"CHL", 31396, 152 }, /* Chile */
277 { 49, L
"CM", L
"CMR", 42484, 120 }, /* Cameroon */
278 { 50, L
"KM", L
"COM", 47603, 174 }, /* Comoros */
279 { 51, L
"CO", L
"COL", 31396, 170 }, /* Colombia */
280 { 54, L
"CR", L
"CRI", 27082, 188 }, /* Costa Rica */
281 { 55, L
"CF", L
"CAF", 42484, 140 }, /* Central African Republic */
282 { 56, L
"CU", L
"CUB", 10039880, 192 }, /* Cuba */
283 { 57, L
"CV", L
"CPV", 42483, 132 }, /* Cape Verde */
284 { 59, L
"CY", L
"CYP", 47611, 196 }, /* Cyprus */
285 { 61, L
"DK", L
"DNK", 10039882, 208 }, /* Denmark */
286 { 62, L
"DJ", L
"DJI", 47603, 262 }, /* Djibouti */
287 { 63, L
"DM", L
"DMA", 10039880, 212 }, /* Dominica */
288 { 65, L
"DO", L
"DOM", 10039880, 214 }, /* Dominican Republic */
289 { 66, L
"EC", L
"ECU", 31396, 218 }, /* Ecuador */
290 { 67, L
"EG", L
"EGY", 42487, 818 }, /* Egypt */
291 { 68, L
"IE", L
"IRL", 10039882, 372 }, /* Ireland */
292 { 69, L
"GQ", L
"GNQ", 42484, 226 }, /* Equatorial Guinea */
293 { 70, L
"EE", L
"EST", 10039882, 233 }, /* Estonia */
294 { 71, L
"ER", L
"ERI", 47603, 232 }, /* Eritrea */
295 { 72, L
"SV", L
"SLV", 27082, 222 }, /* El Salvador */
296 { 73, L
"ET", L
"ETH", 47603, 231 }, /* Ethiopia */
297 { 75, L
"CZ", L
"CZE", 47609, 203 }, /* Czech Republic */
298 { 77, L
"FI", L
"FIN", 10039882, 246 }, /* Finland */
299 { 78, L
"FJ", L
"FJI", 20900, 242 }, /* Fiji Islands */
300 { 80, L
"FM", L
"FSM", 21206, 583 }, /* Micronesia */
301 { 81, L
"FO", L
"FRO", 10039882, 234 }, /* Faroe Islands */
302 { 84, L
"FR", L
"FRA", 10210824, 250 }, /* France */
303 { 86, L
"GM", L
"GMB", 42483, 270 }, /* Gambia, The */
304 { 87, L
"GA", L
"GAB", 42484, 266 }, /* Gabon */
305 { 88, L
"GE", L
"GEO", 47611, 268 }, /* Georgia */
306 { 89, L
"GH", L
"GHA", 42483, 288 }, /* Ghana */
307 { 90, L
"GI", L
"GIB", 47610, 292 }, /* Gibraltar */
308 { 91, L
"GD", L
"GRD", 10039880, 308 }, /* Grenada */
309 { 93, L
"GL", L
"GRL", 23581, 304 }, /* Greenland */
310 { 94, L
"DE", L
"DEU", 10210824, 276 }, /* Germany */
311 { 98, L
"GR", L
"GRC", 47610, 300 }, /* Greece */
312 { 99, L
"GT", L
"GTM", 27082, 320 }, /* Guatemala */
313 { 100, L
"GN", L
"GIN", 42483, 324 }, /* Guinea */
314 { 101, L
"GY", L
"GUY", 31396, 328 }, /* Guyana */
315 { 103, L
"HT", L
"HTI", 10039880, 332 }, /* Haiti */
316 { 104, L
"HK", L
"HKG", 47600, 344 }, /* Hong Kong S.A.R. */
317 { 106, L
"HN", L
"HND", 27082, 340 }, /* Honduras */
318 { 108, L
"HR", L
"HRV", 47610, 191 }, /* Croatia */
319 { 109, L
"HU", L
"HUN", 47609, 348 }, /* Hungary */
320 { 110, L
"IS", L
"ISL", 10039882, 352 }, /* Iceland */
321 { 111, L
"ID", L
"IDN", 47599, 360 }, /* Indonesia */
322 { 113, L
"IN", L
"IND", 47614, 356 }, /* India */
323 { 114, L
"IO", L
"IOT", 39070, 86 }, /* British Indian Ocean Territory */
324 { 116, L
"IR", L
"IRN", 47614, 364 }, /* Iran */
325 { 117, L
"IL", L
"ISR", 47611, 376 }, /* Israel */
326 { 118, L
"IT", L
"ITA", 47610, 380 }, /* Italy */
327 { 119, L
"CI", L
"CIV", 42483, 384 }, /* Côte d'Ivoire */
328 { 121, L
"IQ", L
"IRQ", 47611, 368 }, /* Iraq */
329 { 122, L
"JP", L
"JPN", 47600, 392 }, /* Japan */
330 { 124, L
"JM", L
"JAM", 10039880, 388 }, /* Jamaica */
331 { 125, L
"SJ", L
"SJM", 10039882, 744 }, /* Jan Mayen */
332 { 126, L
"JO", L
"JOR", 47611, 400 }, /* Jordan */
333 { 127, L
"XX", L
"XX", 161832256 }, /* Johnston Atoll */
334 { 129, L
"KE", L
"KEN", 47603, 404 }, /* Kenya */
335 { 130, L
"KG", L
"KGZ", 47590, 417 }, /* Kyrgyzstan */
336 { 131, L
"KP", L
"PRK", 47600, 408 }, /* North Korea */
337 { 133, L
"KI", L
"KIR", 21206, 296 }, /* Kiribati */
338 { 134, L
"KR", L
"KOR", 47600, 410 }, /* Korea */
339 { 136, L
"KW", L
"KWT", 47611, 414 }, /* Kuwait */
340 { 137, L
"KZ", L
"KAZ", 47590, 398 }, /* Kazakhstan */
341 { 138, L
"LA", L
"LAO", 47599, 418 }, /* Laos */
342 { 139, L
"LB", L
"LBN", 47611, 422 }, /* Lebanon */
343 { 140, L
"LV", L
"LVA", 10039882, 428 }, /* Latvia */
344 { 141, L
"LT", L
"LTU", 10039882, 440 }, /* Lithuania */
345 { 142, L
"LR", L
"LBR", 42483, 430 }, /* Liberia */
346 { 143, L
"SK", L
"SVK", 47609, 703 }, /* Slovakia */
347 { 145, L
"LI", L
"LIE", 10210824, 438 }, /* Liechtenstein */
348 { 146, L
"LS", L
"LSO", 10039883, 426 }, /* Lesotho */
349 { 147, L
"LU", L
"LUX", 10210824, 442 }, /* Luxembourg */
350 { 148, L
"LY", L
"LBY", 42487, 434 }, /* Libya */
351 { 149, L
"MG", L
"MDG", 47603, 450 }, /* Madagascar */
352 { 151, L
"MO", L
"MAC", 47600, 446 }, /* Macao S.A.R. */
353 { 152, L
"MD", L
"MDA", 47609, 498 }, /* Moldova */
354 { 154, L
"MN", L
"MNG", 47600, 496 }, /* Mongolia */
355 { 156, L
"MW", L
"MWI", 47603, 454 }, /* Malawi */
356 { 157, L
"ML", L
"MLI", 42483, 466 }, /* Mali */
357 { 158, L
"MC", L
"MCO", 10210824, 492 }, /* Monaco */
358 { 159, L
"MA", L
"MAR", 42487, 504 }, /* Morocco */
359 { 160, L
"MU", L
"MUS", 47603, 480 }, /* Mauritius */
360 { 162, L
"MR", L
"MRT", 42483, 478 }, /* Mauritania */
361 { 163, L
"MT", L
"MLT", 47610, 470 }, /* Malta */
362 { 164, L
"OM", L
"OMN", 47611, 512 }, /* Oman */
363 { 165, L
"MV", L
"MDV", 47614, 462 }, /* Maldives */
364 { 166, L
"MX", L
"MEX", 27082, 484 }, /* Mexico */
365 { 167, L
"MY", L
"MYS", 47599, 458 }, /* Malaysia */
366 { 168, L
"MZ", L
"MOZ", 47603, 508 }, /* Mozambique */
367 { 173, L
"NE", L
"NER", 42483, 562 }, /* Niger */
368 { 174, L
"VU", L
"VUT", 20900, 548 }, /* Vanuatu */
369 { 175, L
"NG", L
"NGA", 42483, 566 }, /* Nigeria */
370 { 176, L
"NL", L
"NLD", 10210824, 528 }, /* Netherlands */
371 { 177, L
"NO", L
"NOR", 10039882, 578 }, /* Norway */
372 { 178, L
"NP", L
"NPL", 47614, 524 }, /* Nepal */
373 { 180, L
"NR", L
"NRU", 21206, 520 }, /* Nauru */
374 { 181, L
"SR", L
"SUR", 31396, 740 }, /* Suriname */
375 { 182, L
"NI", L
"NIC", 27082, 558 }, /* Nicaragua */
376 { 183, L
"NZ", L
"NZL", 10210825, 554 }, /* New Zealand */
377 { 184, L
"PS", L
"PSE", 47611, 275 }, /* Palestinian Authority */
378 { 185, L
"PY", L
"PRY", 31396, 600 }, /* Paraguay */
379 { 187, L
"PE", L
"PER", 31396, 604 }, /* Peru */
380 { 190, L
"PK", L
"PAK", 47614, 586 }, /* Pakistan */
381 { 191, L
"PL", L
"POL", 47609, 616 }, /* Poland */
382 { 192, L
"PA", L
"PAN", 27082, 591 }, /* Panama */
383 { 193, L
"PT", L
"PRT", 47610, 620 }, /* Portugal */
384 { 194, L
"PG", L
"PNG", 20900, 598 }, /* Papua New Guinea */
385 { 195, L
"PW", L
"PLW", 21206, 585 }, /* Palau */
386 { 196, L
"GW", L
"GNB", 42483, 624 }, /* Guinea-Bissau */
387 { 197, L
"QA", L
"QAT", 47611, 634 }, /* Qatar */
388 { 198, L
"RE", L
"REU", 47603, 638 }, /* Reunion */
389 { 199, L
"MH", L
"MHL", 21206, 584 }, /* Marshall Islands */
390 { 200, L
"RO", L
"ROU", 47609, 642 }, /* Romania */
391 { 201, L
"PH", L
"PHL", 47599, 608 }, /* Philippines */
392 { 202, L
"PR", L
"PRI", 10039880, 630 }, /* Puerto Rico */
393 { 203, L
"RU", L
"RUS", 47609, 643 }, /* Russia */
394 { 204, L
"RW", L
"RWA", 47603, 646 }, /* Rwanda */
395 { 205, L
"SA", L
"SAU", 47611, 682 }, /* Saudi Arabia */
396 { 206, L
"PM", L
"SPM", 23581, 666 }, /* St. Pierre and Miquelon */
397 { 207, L
"KN", L
"KNA", 10039880, 659 }, /* St. Kitts and Nevis */
398 { 208, L
"SC", L
"SYC", 47603, 690 }, /* Seychelles */
399 { 209, L
"ZA", L
"ZAF", 10039883, 710 }, /* South Africa */
400 { 210, L
"SN", L
"SEN", 42483, 686 }, /* Senegal */
401 { 212, L
"SI", L
"SVN", 47610, 705 }, /* Slovenia */
402 { 213, L
"SL", L
"SLE", 42483, 694 }, /* Sierra Leone */
403 { 214, L
"SM", L
"SMR", 47610, 674 }, /* San Marino */
404 { 215, L
"SG", L
"SGP", 47599, 702 }, /* Singapore */
405 { 216, L
"SO", L
"SOM", 47603, 706 }, /* Somalia */
406 { 217, L
"ES", L
"ESP", 47610, 724 }, /* Spain */
407 { 218, L
"LC", L
"LCA", 10039880, 662 }, /* St. Lucia */
408 { 219, L
"SD", L
"SDN", 42487, 736 }, /* Sudan */
409 { 220, L
"SJ", L
"SJM", 10039882, 744 }, /* Svalbard */
410 { 221, L
"SE", L
"SWE", 10039882, 752 }, /* Sweden */
411 { 222, L
"SY", L
"SYR", 47611, 760 }, /* Syria */
412 { 223, L
"CH", L
"CHE", 10210824, 756 }, /* Switzerland */
413 { 224, L
"AE", L
"ARE", 47611, 784 }, /* United Arab Emirates */
414 { 225, L
"TT", L
"TTO", 10039880, 780 }, /* Trinidad and Tobago */
415 { 227, L
"TH", L
"THA", 47599, 764 }, /* Thailand */
416 { 228, L
"TJ", L
"TJK", 47590, 762 }, /* Tajikistan */
417 { 231, L
"TO", L
"TON", 26286, 776 }, /* Tonga */
418 { 232, L
"TG", L
"TGO", 42483, 768 }, /* Togo */
419 { 233, L
"ST", L
"STP", 42484, 678 }, /* São Tomé and Príncipe */
420 { 234, L
"TN", L
"TUN", 42487, 788 }, /* Tunisia */
421 { 235, L
"TR", L
"TUR", 47611, 792 }, /* Turkey */
422 { 236, L
"TV", L
"TUV", 26286, 798 }, /* Tuvalu */
423 { 237, L
"TW", L
"TWN", 47600, 158 }, /* Taiwan */
424 { 238, L
"TM", L
"TKM", 47590, 795 }, /* Turkmenistan */
425 { 239, L
"TZ", L
"TZA", 47603, 834 }, /* Tanzania */
426 { 240, L
"UG", L
"UGA", 47603, 800 }, /* Uganda */
427 { 241, L
"UA", L
"UKR", 47609, 804 }, /* Ukraine */
428 { 242, L
"GB", L
"GBR", 10039882, 826 }, /* United Kingdom */
429 { 244, L
"US", L
"USA", 23581, 840 }, /* United States */
430 { 245, L
"BF", L
"BFA", 42483, 854 }, /* Burkina Faso */
431 { 246, L
"UY", L
"URY", 31396, 858 }, /* Uruguay */
432 { 247, L
"UZ", L
"UZB", 47590, 860 }, /* Uzbekistan */
433 { 248, L
"VC", L
"VCT", 10039880, 670 }, /* St. Vincent and the Grenadines */
434 { 249, L
"VE", L
"VEN", 31396, 862 }, /* Bolivarian Republic of Venezuela */
435 { 251, L
"VN", L
"VNM", 47599, 704 }, /* Vietnam */
436 { 252, L
"VI", L
"VIR", 10039880, 850 }, /* Virgin Islands */
437 { 253, L
"VA", L
"VAT", 47610, 336 }, /* Vatican City */
438 { 254, L
"NA", L
"NAM", 10039883, 516 }, /* Namibia */
439 { 257, L
"EH", L
"ESH", 42487, 732 }, /* Western Sahara (disputed) */
440 { 258, L
"XX", L
"XX", 161832256 }, /* Wake Island */
441 { 259, L
"WS", L
"WSM", 26286, 882 }, /* Samoa */
442 { 260, L
"SZ", L
"SWZ", 10039883, 748 }, /* Swaziland */
443 { 261, L
"YE", L
"YEM", 47611, 887 }, /* Yemen */
444 { 263, L
"ZM", L
"ZMB", 47603, 894 }, /* Zambia */
445 { 264, L
"ZW", L
"ZWE", 47603, 716 }, /* Zimbabwe */
446 { 269, L
"CS", L
"SCG", 47610, 891 }, /* Serbia and Montenegro (Former) */
447 { 270, L
"ME", L
"MNE", 47610, 499 }, /* Montenegro */
448 { 271, L
"RS", L
"SRB", 47610, 688 }, /* Serbia */
449 { 273, L
"CW", L
"CUW", 10039880, 531 }, /* Curaçao */
450 { 276, L
"SS", L
"SSD", 42487, 728 }, /* South Sudan */
451 { 300, L
"AI", L
"AIA", 10039880, 660 }, /* Anguilla */
452 { 301, L
"AQ", L
"ATA", 39070, 10 }, /* Antarctica */
453 { 302, L
"AW", L
"ABW", 10039880, 533 }, /* Aruba */
454 { 303, L
"XX", L
"XX", 343 }, /* Ascension Island */
455 { 304, L
"XX", L
"XX", 10210825 }, /* Ashmore and Cartier Islands */
456 { 305, L
"XX", L
"XX", 161832256 }, /* Baker Island */
457 { 306, L
"BV", L
"BVT", 39070, 74 }, /* Bouvet Island */
458 { 307, L
"KY", L
"CYM", 10039880, 136 }, /* Cayman Islands */
459 { 308, L
"XX", L
"XX", 10210824, 830, LOCATION_BOTH
}, /* Channel Islands */
460 { 309, L
"CX", L
"CXR", 12, 162 }, /* Christmas Island */
461 { 310, L
"XX", L
"XX", 27114 }, /* Clipperton Island */
462 { 311, L
"CC", L
"CCK", 10210825, 166 }, /* Cocos (Keeling) Islands */
463 { 312, L
"CK", L
"COK", 26286, 184 }, /* Cook Islands */
464 { 313, L
"XX", L
"XX", 10210825 }, /* Coral Sea Islands */
465 { 314, L
"XX", L
"XX", 114 }, /* Diego Garcia */
466 { 315, L
"FK", L
"FLK", 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
467 { 317, L
"GF", L
"GUF", 31396, 254 }, /* French Guiana */
468 { 318, L
"PF", L
"PYF", 26286, 258 }, /* French Polynesia */
469 { 319, L
"TF", L
"ATF", 39070, 260 }, /* French Southern and Antarctic Lands */
470 { 321, L
"GP", L
"GLP", 10039880, 312 }, /* Guadeloupe */
471 { 322, L
"GU", L
"GUM", 21206, 316 }, /* Guam */
472 { 323, L
"XX", L
"XX", 39070 }, /* Guantanamo Bay */
473 { 324, L
"GG", L
"GGY", 308, 831 }, /* Guernsey */
474 { 325, L
"HM", L
"HMD", 39070, 334 }, /* Heard Island and McDonald Islands */
475 { 326, L
"XX", L
"XX", 161832256 }, /* Howland Island */
476 { 327, L
"XX", L
"XX", 161832256 }, /* Jarvis Island */
477 { 328, L
"JE", L
"JEY", 308, 832 }, /* Jersey */
478 { 329, L
"XX", L
"XX", 161832256 }, /* Kingman Reef */
479 { 330, L
"MQ", L
"MTQ", 10039880, 474 }, /* Martinique */
480 { 331, L
"YT", L
"MYT", 47603, 175 }, /* Mayotte */
481 { 332, L
"MS", L
"MSR", 10039880, 500 }, /* Montserrat */
482 { 333, L
"AN", L
"ANT", 10039880, 530, LOCATION_BOTH
}, /* Netherlands Antilles (Former) */
483 { 334, L
"NC", L
"NCL", 20900, 540 }, /* New Caledonia */
484 { 335, L
"NU", L
"NIU", 26286, 570 }, /* Niue */
485 { 336, L
"NF", L
"NFK", 10210825, 574 }, /* Norfolk Island */
486 { 337, L
"MP", L
"MNP", 21206, 580 }, /* Northern Mariana Islands */
487 { 338, L
"XX", L
"XX", 161832256 }, /* Palmyra Atoll */
488 { 339, L
"PN", L
"PCN", 26286, 612 }, /* Pitcairn Islands */
489 { 340, L
"XX", L
"XX", 337 }, /* Rota Island */
490 { 341, L
"XX", L
"XX", 337 }, /* Saipan */
491 { 342, L
"GS", L
"SGS", 39070, 239 }, /* South Georgia and the South Sandwich Islands */
492 { 343, L
"SH", L
"SHN", 42483, 654 }, /* St. Helena */
493 { 346, L
"XX", L
"XX", 337 }, /* Tinian Island */
494 { 347, L
"TK", L
"TKL", 26286, 772 }, /* Tokelau */
495 { 348, L
"XX", L
"XX", 343 }, /* Tristan da Cunha */
496 { 349, L
"TC", L
"TCA", 10039880, 796 }, /* Turks and Caicos Islands */
497 { 351, L
"VG", L
"VGB", 10039880, 92 }, /* Virgin Islands, British */
498 { 352, L
"WF", L
"WLF", 26286, 876 }, /* Wallis and Futuna */
499 { 742, L
"XX", L
"XX", 39070, 2, LOCATION_REGION
}, /* Africa */
500 { 2129, L
"XX", L
"XX", 39070, 142, LOCATION_REGION
}, /* Asia */
501 { 10541, L
"XX", L
"XX", 39070, 150, LOCATION_REGION
}, /* Europe */
502 { 15126, L
"IM", L
"IMN", 10039882, 833 }, /* Man, Isle of */
503 { 19618, L
"MK", L
"MKD", 47610, 807 }, /* Macedonia, Former Yugoslav Republic of */
504 { 20900, L
"XX", L
"XX", 27114, 54, LOCATION_REGION
}, /* Melanesia */
505 { 21206, L
"XX", L
"XX", 27114, 57, LOCATION_REGION
}, /* Micronesia */
506 { 21242, L
"XX", L
"XX", 161832256 }, /* Midway Islands */
507 { 23581, L
"XX", L
"XX", 10026358, 21, LOCATION_REGION
}, /* Northern America */
508 { 26286, L
"XX", L
"XX", 27114, 61, LOCATION_REGION
}, /* Polynesia */
509 { 27082, L
"XX", L
"XX", 161832257, 13, LOCATION_REGION
}, /* Central America */
510 { 27114, L
"XX", L
"XX", 39070, 9, LOCATION_REGION
}, /* Oceania */
511 { 30967, L
"SX", L
"SXM", 10039880, 534 }, /* Sint Maarten (Dutch part) */
512 { 31396, L
"XX", L
"XX", 161832257, 5, LOCATION_REGION
}, /* South America */
513 { 31706, L
"MF", L
"MAF", 10039880, 663 }, /* Saint Martin (French part) */
514 { 39070, L
"XX", L
"XX", 39070, 1, LOCATION_REGION
}, /* World */
515 { 42483, L
"XX", L
"XX", 742, 11, LOCATION_REGION
}, /* Western Africa */
516 { 42484, L
"XX", L
"XX", 742, 17, LOCATION_REGION
}, /* Middle Africa */
517 { 42487, L
"XX", L
"XX", 742, 15, LOCATION_REGION
}, /* Northern Africa */
518 { 47590, L
"XX", L
"XX", 2129, 143, LOCATION_REGION
}, /* Central Asia */
519 { 47599, L
"XX", L
"XX", 2129, 35, LOCATION_REGION
}, /* South-Eastern Asia */
520 { 47600, L
"XX", L
"XX", 2129, 30, LOCATION_REGION
}, /* Eastern Asia */
521 { 47603, L
"XX", L
"XX", 742, 14, LOCATION_REGION
}, /* Eastern Africa */
522 { 47609, L
"XX", L
"XX", 10541, 151, LOCATION_REGION
}, /* Eastern Europe */
523 { 47610, L
"XX", L
"XX", 10541, 39, LOCATION_REGION
}, /* Southern Europe */
524 { 47611, L
"XX", L
"XX", 2129, 145, LOCATION_REGION
}, /* Middle East */
525 { 47614, L
"XX", L
"XX", 2129, 34, LOCATION_REGION
}, /* Southern Asia */
526 { 7299303, L
"TL", L
"TLS", 47599, 626 }, /* Democratic Republic of Timor-Leste */
527 { 9914689, L
"XK", L
"XKS", 47610, 906 }, /* Kosovo */
528 { 10026358, L
"XX", L
"XX", 39070, 19, LOCATION_REGION
}, /* Americas */
529 { 10028789, L
"AX", L
"ALA", 10039882, 248 }, /* Åland Islands */
530 { 10039880, L
"XX", L
"XX", 161832257, 29, LOCATION_REGION
}, /* Caribbean */
531 { 10039882, L
"XX", L
"XX", 10541, 154, LOCATION_REGION
}, /* Northern Europe */
532 { 10039883, L
"XX", L
"XX", 742, 18, LOCATION_REGION
}, /* Southern Africa */
533 { 10210824, L
"XX", L
"XX", 10541, 155, LOCATION_REGION
}, /* Western Europe */
534 { 10210825, L
"XX", L
"XX", 27114, 53, LOCATION_REGION
}, /* Australia and New Zealand */
535 { 161832015, L
"BL", L
"BLM", 10039880, 652 }, /* Saint Barthélemy */
536 { 161832256, L
"UM", L
"UMI", 27114, 581 }, /* U.S. Minor Outlying Islands */
537 { 161832257, L
"XX", L
"XX", 10026358, 419, LOCATION_REGION
}, /* Latin America and the Caribbean */
538 { 161832258, L
"BG", L
"BES", 10039880, 535 }, /* Bonaire, Sint Eustatius and Saba */
541 /* NLS normalization file */
544 WCHAR name
[13]; /* 00 file name */
545 USHORT checksum
[3]; /* 1a checksum? */
546 USHORT version
[4]; /* 20 Unicode version */
547 USHORT form
; /* 28 normalization form */
548 USHORT len_factor
; /* 2a factor for length estimates */
549 USHORT unknown1
; /* 2c */
550 USHORT decomp_size
; /* 2e decomposition hash size */
551 USHORT comp_size
; /* 30 composition hash size */
552 USHORT unknown2
; /* 32 */
553 USHORT classes
; /* 34 combining classes table offset */
554 USHORT props_level1
; /* 36 char properties table level 1 offset */
555 USHORT props_level2
; /* 38 char properties table level 2 offset */
556 USHORT decomp_hash
; /* 3a decomposition hash table offset */
557 USHORT decomp_map
; /* 3c decomposition character map table offset */
558 USHORT decomp_seq
; /* 3e decomposition character sequences offset */
559 USHORT comp_hash
; /* 40 composition hash table offset */
560 USHORT comp_seq
; /* 42 composition character sequences offset */
561 /* BYTE[] combining class values */
562 /* BYTE[0x2200] char properties index level 1 */
563 /* BYTE[] char properties index level 2 */
564 /* WORD[] decomposition hash table */
565 /* WORD[] decomposition character map */
566 /* WORD[] decomposition character sequences */
567 /* WORD[] composition hash table */
568 /* WORD[] composition character sequences */
571 static NLSTABLEINFO nls_info
;
572 static UINT unix_cp
= CP_UTF8
;
573 static UINT mac_cp
= 10000;
574 static HKEY intl_key
;
578 static CPTABLEINFO codepages
[128];
579 static unsigned int nb_codepages
;
581 static struct norm_table
*norm_info
;
585 GUID id
; /* sort GUID */
586 DWORD flags
; /* flags */
587 DWORD compr
; /* offset to compression table */
588 DWORD except
; /* exception table offset in sortkey table */
589 DWORD ling_except
; /* exception table offset for linguistic casing */
590 DWORD casemap
; /* linguistic casemap table offset */
593 #define FLAG_HAS_3_BYTE_WEIGHTS 0x01
594 #define FLAG_REVERSEDIACRITICS 0x10
595 #define FLAG_DOUBLECOMPRESSION 0x20
596 #define FLAG_INVERSECASING 0x40
598 static const struct sortguid
*current_locale_sort
;
600 static const GUID default_sort_guid
= { 0x00000001, 0x57ee, 0x1e5c, { 0x00, 0xb4, 0xd0, 0x00, 0x0b, 0xb1, 0xe1, 0x1e }};
604 DWORD
*keys
; /* sortkey table, indexed by char */
605 USHORT
*casemap
; /* casemap table, in l_intl.nls format */
606 WORD
*ctypes
; /* CT_CTYPE1,2,3 values */
607 BYTE
*ctype_idx
; /* index to map char to ctypes array entry */
608 DWORD version
; /* NLS version */
609 DWORD guid_count
; /* number of sort GUIDs */
610 struct sortguid
*guids
; /* table of sort GUIDs */
613 static CRITICAL_SECTION locale_section
;
614 static CRITICAL_SECTION_DEBUG critsect_debug
=
616 0, 0, &locale_section
,
617 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
618 0, 0, { (DWORD_PTR
)(__FILE__
": locale_section") }
620 static CRITICAL_SECTION locale_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
623 static void init_sortkeys( DWORD
*ptr
)
628 sort
.keys
= (DWORD
*)((char *)ptr
+ ptr
[0]);
629 sort
.casemap
= (USHORT
*)((char *)ptr
+ ptr
[1]);
631 ctype
= (WORD
*)((char *)ptr
+ ptr
[2]);
632 sort
.ctypes
= ctype
+ 2;
633 sort
.ctype_idx
= (BYTE
*)ctype
+ ctype
[1] + 2;
635 table
= (DWORD
*)((char *)ptr
+ ptr
[3]);
636 sort
.version
= table
[0];
637 sort
.guid_count
= table
[1];
638 sort
.guids
= (struct sortguid
*)(table
+ 2);
642 static const struct sortguid
*find_sortguid( const GUID
*guid
)
644 int pos
, ret
, min
= 0, max
= sort
.guid_count
- 1;
648 pos
= (min
+ max
) / 2;
649 ret
= memcmp( guid
, &sort
.guids
[pos
].id
, sizeof(*guid
) );
650 if (!ret
) return &sort
.guids
[pos
];
651 if (ret
> 0) min
= pos
+ 1;
654 ERR( "no sort found for %s\n", debugstr_guid( guid
));
659 static const struct sortguid
*get_language_sort( const WCHAR
*locale
)
661 WCHAR
*p
, *end
, buffer
[LOCALE_NAME_MAX_LENGTH
], guidstr
[39];
662 const struct sortguid
*ret
;
668 if (locale
== LOCALE_NAME_USER_DEFAULT
)
670 if (current_locale_sort
) return current_locale_sort
;
671 GetUserDefaultLocaleName( buffer
, ARRAY_SIZE( buffer
));
673 else lstrcpynW( buffer
, locale
, LOCALE_NAME_MAX_LENGTH
);
675 if (buffer
[0] && !RegOpenKeyExW( nls_key
, L
"Sorting\\Ids", 0, KEY_READ
, &key
))
679 size
= sizeof(guidstr
);
680 if (!RegQueryValueExW( key
, buffer
, NULL
, &type
, (BYTE
*)guidstr
, &size
) && type
== REG_SZ
)
682 RtlInitUnicodeString( &str
, guidstr
);
683 if (!RtlGUIDFromString( &str
, &guid
))
685 ret
= find_sortguid( &guid
);
690 for (p
= end
= buffer
; *p
; p
++) if (*p
== '-' || *p
== '_') end
= p
;
691 if (end
== buffer
) break;
695 ret
= find_sortguid( &default_sort_guid
);
702 static LCID
locale_to_lcid( WCHAR
*win_name
)
707 if (!RtlLocaleNameToLcid( win_name
, &lcid
, 0 )) return lcid
;
709 /* try neutral name */
710 if ((p
= wcsrchr( win_name
, '-' )))
713 if (!RtlLocaleNameToLcid( win_name
, &lcid
, 2 ))
715 if (SUBLANGID(lcid
) == SUBLANG_NEUTRAL
)
716 lcid
= MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_DEFAULT
);
723 /***********************************************************************
726 void init_locale(void)
728 UINT ansi_cp
= 0, oem_cp
= 0;
729 USHORT
*ansi_ptr
, *oem_ptr
;
731 LCID user_lcid
= 0, system_lcid
= 0;
732 WCHAR bufferW
[LOCALE_NAME_MAX_LENGTH
];
733 DYNAMIC_TIME_ZONE_INFORMATION timezone
;
734 GEOID geoid
= GEOID_NOT_AVAILABLE
;
735 DWORD count
, dispos
, i
;
739 if (GetEnvironmentVariableW( L
"WINEUNIXCP", bufferW
, ARRAY_SIZE(bufferW
) ))
740 unix_cp
= wcstoul( bufferW
, NULL
, 10 );
741 if (GetEnvironmentVariableW( L
"WINELOCALE", bufferW
, ARRAY_SIZE(bufferW
) ))
742 system_lcid
= locale_to_lcid( bufferW
);
743 if (GetEnvironmentVariableW( L
"WINEUSERLOCALE", bufferW
, ARRAY_SIZE(bufferW
) ))
744 user_lcid
= locale_to_lcid( bufferW
);
745 if (!system_lcid
) system_lcid
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
746 if (!user_lcid
) user_lcid
= system_lcid
;
748 NtSetDefaultUILanguage( LANGIDFROMLCID(user_lcid
) );
749 NtSetDefaultLocale( TRUE
, user_lcid
);
750 NtSetDefaultLocale( FALSE
, system_lcid
);
752 kernel32_handle
= GetModuleHandleW( L
"kernel32.dll" );
754 GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT
, LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
,
755 (WCHAR
*)&ansi_cp
, sizeof(ansi_cp
)/sizeof(WCHAR
) );
756 GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT
, LOCALE_IDEFAULTMACCODEPAGE
| LOCALE_RETURN_NUMBER
,
757 (WCHAR
*)&mac_cp
, sizeof(mac_cp
)/sizeof(WCHAR
) );
758 GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT
, LOCALE_IDEFAULTCODEPAGE
| LOCALE_RETURN_NUMBER
,
759 (WCHAR
*)&oem_cp
, sizeof(oem_cp
)/sizeof(WCHAR
) );
761 NtGetNlsSectionPtr( 9, 0, NULL
, &sort_ptr
, &size
);
762 NtGetNlsSectionPtr( 12, NormalizationC
, NULL
, (void **)&norm_info
, &size
);
763 init_sortkeys( sort_ptr
);
765 if (!ansi_cp
|| NtGetNlsSectionPtr( 11, ansi_cp
, NULL
, (void **)&ansi_ptr
, &size
))
766 NtGetNlsSectionPtr( 11, 1252, NULL
, (void **)&ansi_ptr
, &size
);
767 if (!oem_cp
|| NtGetNlsSectionPtr( 11, oem_cp
, 0, (void **)&oem_ptr
, &size
))
768 NtGetNlsSectionPtr( 11, 437, NULL
, (void **)&oem_ptr
, &size
);
769 NtCurrentTeb()->Peb
->AnsiCodePageData
= ansi_ptr
;
770 NtCurrentTeb()->Peb
->OemCodePageData
= oem_ptr
;
771 NtCurrentTeb()->Peb
->UnicodeCaseTableData
= sort
.casemap
;
772 RtlInitNlsTables( ansi_ptr
, oem_ptr
, sort
.casemap
, &nls_info
);
773 RtlResetRtlTranslations( &nls_info
);
775 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\Nls",
776 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &nls_key
, NULL
);
777 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
778 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &tz_key
, NULL
);
779 RegCreateKeyExW( HKEY_CURRENT_USER
, L
"Control Panel\\International",
780 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &intl_key
, NULL
);
782 current_locale_sort
= get_language_sort( LOCALE_NAME_USER_DEFAULT
);
784 if (GetDynamicTimeZoneInformation( &timezone
) != TIME_ZONE_ID_INVALID
&&
785 !RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\TimeZoneInformation",
786 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
788 RegSetValueExW( hkey
, L
"StandardName", 0, REG_SZ
, (BYTE
*)timezone
.StandardName
,
789 (lstrlenW(timezone
.StandardName
) + 1) * sizeof(WCHAR
) );
790 RegSetValueExW( hkey
, L
"TimeZoneKeyName", 0, REG_SZ
, (BYTE
*)timezone
.TimeZoneKeyName
,
791 (lstrlenW(timezone
.TimeZoneKeyName
) + 1) * sizeof(WCHAR
) );
795 if (!RegCreateKeyExW( intl_key
, L
"Geo", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, &dispos
))
797 if (dispos
== REG_CREATED_NEW_KEY
)
799 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IGEOID
| LOCALE_RETURN_NUMBER
,
800 (WCHAR
*)&geoid
, sizeof(geoid
) / sizeof(WCHAR
) );
801 SetUserGeoID( geoid
);
806 /* Update registry contents if the user locale has changed.
807 * This simulates the action of the Windows control panel. */
809 count
= sizeof(bufferW
);
810 if (!RegQueryValueExW( intl_key
, L
"Locale", NULL
, NULL
, (BYTE
*)bufferW
, &count
))
812 if (wcstoul( bufferW
, NULL
, 16 ) == user_lcid
) return; /* already set correctly */
813 TRACE( "updating registry, locale changed %s -> %08x\n", debugstr_w(bufferW
), user_lcid
);
815 else TRACE( "updating registry, locale changed none -> %08x\n", user_lcid
);
816 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%08x", user_lcid
);
817 RegSetValueExW( intl_key
, L
"Locale", 0, REG_SZ
,
818 (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
820 for (i
= 0; i
< ARRAY_SIZE(registry_values
); i
++)
822 GetLocaleInfoW( LOCALE_USER_DEFAULT
, registry_values
[i
].lctype
| LOCALE_NOUSEROVERRIDE
,
823 bufferW
, ARRAY_SIZE( bufferW
));
824 RegSetValueExW( intl_key
, registry_values
[i
].name
, 0, REG_SZ
,
825 (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
828 if (geoid
== GEOID_NOT_AVAILABLE
)
830 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IGEOID
| LOCALE_RETURN_NUMBER
,
831 (WCHAR
*)&geoid
, sizeof(geoid
) / sizeof(WCHAR
) );
832 SetUserGeoID( geoid
);
835 if (!RegCreateKeyExW( nls_key
, L
"Codepage",
836 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
838 count
= swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03d", ansi_cp
);
839 RegSetValueExW( hkey
, L
"ACP", 0, REG_SZ
, (BYTE
*)bufferW
, (count
+ 1) * sizeof(WCHAR
) );
840 count
= swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03d", oem_cp
);
841 RegSetValueExW( hkey
, L
"OEMCP", 0, REG_SZ
, (BYTE
*)bufferW
, (count
+ 1) * sizeof(WCHAR
) );
842 count
= swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03d", mac_cp
);
843 RegSetValueExW( hkey
, L
"MACCP", 0, REG_SZ
, (BYTE
*)bufferW
, (count
+ 1) * sizeof(WCHAR
) );
849 static inline USHORT
get_table_entry( const USHORT
*table
, WCHAR ch
)
851 return table
[table
[table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0xf)];
855 static inline WCHAR
casemap( const USHORT
*table
, WCHAR ch
)
857 return ch
+ table
[table
[table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0x0f)];
861 static inline WORD
get_char_type( DWORD type
, WCHAR ch
)
863 const BYTE
*ptr
= sort
.ctype_idx
+ ((const WORD
*)sort
.ctype_idx
)[ch
>> 8];
864 ptr
= sort
.ctype_idx
+ ((const WORD
*)ptr
)[(ch
>> 4) & 0x0f] + (ch
& 0x0f);
865 return sort
.ctypes
[*ptr
* 3 + type
/ 2];
869 static BYTE
rol( BYTE val
, BYTE count
)
871 return (val
<< count
) | (val
>> (8 - count
));
875 static BYTE
get_char_props( const struct norm_table
*info
, unsigned int ch
)
877 const BYTE
*level1
= (const BYTE
*)((const USHORT
*)info
+ info
->props_level1
);
878 const BYTE
*level2
= (const BYTE
*)((const USHORT
*)info
+ info
->props_level2
);
879 BYTE off
= level1
[ch
/ 128];
881 if (!off
|| off
>= 0xfb) return rol( off
, 5 );
882 return level2
[(off
- 1) * 128 + ch
% 128];
886 static const WCHAR
*get_decomposition( WCHAR ch
, unsigned int *ret_len
)
888 const struct pair
{ WCHAR src
; USHORT dst
; } *pairs
;
889 const USHORT
*hash_table
= (const USHORT
*)norm_info
+ norm_info
->decomp_hash
;
891 unsigned int i
, pos
, end
, len
, hash
;
894 hash
= ch
% norm_info
->decomp_size
;
895 pos
= hash_table
[hash
];
898 if (get_char_props( norm_info
, ch
) != 0xbf) return NULL
;
899 ret
= (const USHORT
*)norm_info
+ norm_info
->decomp_seq
+ (pos
& 0x1fff);
904 pairs
= (const struct pair
*)((const USHORT
*)norm_info
+ norm_info
->decomp_map
);
906 /* find the end of the hash bucket */
907 for (i
= hash
+ 1; i
< norm_info
->decomp_size
; i
++) if (!(hash_table
[i
] >> 13)) break;
908 if (i
< norm_info
->decomp_size
) end
= hash_table
[i
];
909 else for (end
= pos
; pairs
[end
].src
; end
++) ;
911 for ( ; pos
< end
; pos
++)
913 if (pairs
[pos
].src
!= (WCHAR
)ch
) continue;
914 ret
= (const USHORT
*)norm_info
+ norm_info
->decomp_seq
+ (pairs
[pos
].dst
& 0x1fff);
915 len
= pairs
[pos
].dst
>> 13;
918 if (pos
>= end
) return NULL
;
921 if (len
== 7) while (ret
[len
]) len
++;
922 if (!ret
[0]) len
= 0; /* ignored char */
928 static WCHAR
compose_chars( WCHAR ch1
, WCHAR ch2
)
930 const USHORT
*table
= (const USHORT
*)norm_info
+ norm_info
->comp_hash
;
931 const WCHAR
*chars
= (const USHORT
*)norm_info
+ norm_info
->comp_seq
;
932 unsigned int hash
, start
, end
, i
;
935 hash
= (ch1
+ 95 * ch2
) % norm_info
->comp_size
;
937 end
= table
[hash
+ 1];
940 for (i
= 0; i
< 3; i
++, start
++)
942 ch
[i
] = chars
[start
];
943 if (IS_HIGH_SURROGATE( ch
[i
] )) start
++;
945 if (ch
[0] == ch1
&& ch
[1] == ch2
) return ch
[2];
951 static UINT
get_lcid_codepage( LCID lcid
, ULONG flags
)
955 if (!(flags
& LOCALE_USE_CP_ACP
) && lcid
!= GetSystemDefaultLCID())
956 GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
,
957 (WCHAR
*)&ret
, sizeof(ret
)/sizeof(WCHAR
) );
962 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
964 switch (LOWORD(lctype
))
966 case LOCALE_SMONTHNAME1
:
967 case LOCALE_SMONTHNAME2
:
968 case LOCALE_SMONTHNAME3
:
969 case LOCALE_SMONTHNAME4
:
970 case LOCALE_SMONTHNAME5
:
971 case LOCALE_SMONTHNAME6
:
972 case LOCALE_SMONTHNAME7
:
973 case LOCALE_SMONTHNAME8
:
974 case LOCALE_SMONTHNAME9
:
975 case LOCALE_SMONTHNAME10
:
976 case LOCALE_SMONTHNAME11
:
977 case LOCALE_SMONTHNAME12
:
978 case LOCALE_SMONTHNAME13
:
986 static int get_value_base_by_lctype( LCTYPE lctype
)
988 return lctype
== LOCALE_ILANGUAGE
|| lctype
== LOCALE_IDEFAULTLANGUAGE
? 16 : 10;
992 static const struct registry_value
*get_locale_registry_value( DWORD lctype
)
996 for (i
= 0; i
< ARRAY_SIZE( registry_values
); i
++)
997 if (registry_values
[i
].lctype
== lctype
) return ®istry_values
[i
];
1002 static INT
get_registry_locale_info( const struct registry_value
*registry_value
, LPWSTR buffer
, INT len
)
1004 DWORD size
, index
= registry_value
- registry_values
;
1007 RtlEnterCriticalSection( &locale_section
);
1009 if (!registry_cache
[index
])
1011 size
= len
* sizeof(WCHAR
);
1012 ret
= RegQueryValueExW( intl_key
, registry_value
->name
, NULL
, NULL
, (BYTE
*)buffer
, &size
);
1015 if (buffer
&& (registry_cache
[index
] = HeapAlloc( GetProcessHeap(), 0, size
+ sizeof(WCHAR
) )))
1017 memcpy( registry_cache
[index
], buffer
, size
);
1018 registry_cache
[index
][size
/ sizeof(WCHAR
)] = 0;
1020 RtlLeaveCriticalSection( &locale_section
);
1021 return size
/ sizeof(WCHAR
);
1025 RtlLeaveCriticalSection( &locale_section
);
1026 if (ret
== ERROR_FILE_NOT_FOUND
) return -1;
1027 if (ret
== ERROR_MORE_DATA
) SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1028 else SetLastError( ret
);
1033 ret
= lstrlenW( registry_cache
[index
] ) + 1;
1038 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1041 else lstrcpyW( buffer
, registry_cache
[index
] );
1043 RtlLeaveCriticalSection( &locale_section
);
1048 static const CPTABLEINFO
*get_codepage_table( UINT codepage
)
1057 return &nls_info
.AnsiTableInfo
;
1059 return &nls_info
.OemTableInfo
;
1064 if (NtCurrentTeb()->CurrentLocale
== GetUserDefaultLCID()) return &nls_info
.AnsiTableInfo
;
1065 codepage
= get_lcid_codepage( NtCurrentTeb()->CurrentLocale
, 0 );
1066 if (!codepage
) return &nls_info
.AnsiTableInfo
;
1069 if (codepage
== nls_info
.AnsiTableInfo
.CodePage
) return &nls_info
.AnsiTableInfo
;
1070 if (codepage
== nls_info
.OemTableInfo
.CodePage
) return &nls_info
.OemTableInfo
;
1074 RtlEnterCriticalSection( &locale_section
);
1076 for (i
= 0; i
< nb_codepages
; i
++) if (codepages
[i
].CodePage
== codepage
) goto done
;
1078 if (i
== ARRAY_SIZE( codepages
))
1080 RtlLeaveCriticalSection( &locale_section
);
1081 ERR( "too many codepages\n" );
1084 if (NtGetNlsSectionPtr( 11, codepage
, NULL
, (void **)&ptr
, &size
))
1086 RtlLeaveCriticalSection( &locale_section
);
1087 SetLastError( ERROR_INVALID_PARAMETER
);
1090 RtlInitCodePageTable( ptr
, &codepages
[i
] );
1093 RtlLeaveCriticalSection( &locale_section
);
1094 return &codepages
[i
];
1098 static const WCHAR
*get_ligature( WCHAR wc
)
1100 int low
= 0, high
= ARRAY_SIZE( ligatures
) -1;
1103 int pos
= (low
+ high
) / 2;
1104 if (ligatures
[pos
][0] < wc
) low
= pos
+ 1;
1105 else if (ligatures
[pos
][0] > wc
) high
= pos
- 1;
1106 else return ligatures
[pos
] + 1;
1112 static NTSTATUS
expand_ligatures( const WCHAR
*src
, int srclen
, WCHAR
*dst
, int *dstlen
)
1114 int i
, len
, pos
= 0;
1115 NTSTATUS ret
= STATUS_SUCCESS
;
1116 const WCHAR
*expand
;
1118 for (i
= 0; i
< srclen
; i
++)
1120 if (!(expand
= get_ligature( src
[i
] )))
1125 else len
= lstrlenW( expand
);
1127 if (*dstlen
&& ret
== STATUS_SUCCESS
)
1129 if (pos
+ len
<= *dstlen
) memcpy( dst
+ pos
, expand
, len
* sizeof(WCHAR
) );
1130 else ret
= STATUS_BUFFER_TOO_SMALL
;
1139 static NTSTATUS
fold_digits( const WCHAR
*src
, int srclen
, WCHAR
*dst
, int *dstlen
)
1141 extern const WCHAR wine_digitmap
[] DECLSPEC_HIDDEN
;
1142 int i
, len
= *dstlen
;
1145 if (!len
) return STATUS_SUCCESS
;
1146 if (srclen
> len
) return STATUS_BUFFER_TOO_SMALL
;
1147 for (i
= 0; i
< srclen
; i
++)
1149 WCHAR digit
= get_table_entry( wine_digitmap
, src
[i
] );
1150 dst
[i
] = digit
? digit
: src
[i
];
1152 return STATUS_SUCCESS
;
1156 static NTSTATUS
fold_string( DWORD flags
, const WCHAR
*src
, int srclen
, WCHAR
*dst
, int *dstlen
)
1163 case MAP_PRECOMPOSED
:
1164 return RtlNormalizeString( NormalizationC
, src
, srclen
, dst
, dstlen
);
1166 case MAP_PRECOMPOSED
| MAP_FOLDCZONE
:
1167 return RtlNormalizeString( NormalizationKC
, src
, srclen
, dst
, dstlen
);
1169 return RtlNormalizeString( NormalizationD
, src
, srclen
, dst
, dstlen
);
1170 case MAP_COMPOSITE
| MAP_FOLDCZONE
:
1171 return RtlNormalizeString( NormalizationKD
, src
, srclen
, dst
, dstlen
);
1172 case MAP_FOLDDIGITS
:
1173 return fold_digits( src
, srclen
, dst
, dstlen
);
1174 case MAP_EXPAND_LIGATURES
:
1175 case MAP_EXPAND_LIGATURES
| MAP_FOLDCZONE
:
1176 return expand_ligatures( src
, srclen
, dst
, dstlen
);
1177 case MAP_FOLDDIGITS
| MAP_PRECOMPOSED
:
1178 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1179 return STATUS_NO_MEMORY
;
1180 fold_digits( src
, srclen
, tmp
, &srclen
);
1181 ret
= RtlNormalizeString( NormalizationC
, tmp
, srclen
, dst
, dstlen
);
1183 case MAP_FOLDDIGITS
| MAP_FOLDCZONE
:
1184 case MAP_FOLDDIGITS
| MAP_PRECOMPOSED
| MAP_FOLDCZONE
:
1185 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1186 return STATUS_NO_MEMORY
;
1187 fold_digits( src
, srclen
, tmp
, &srclen
);
1188 ret
= RtlNormalizeString( NormalizationKC
, tmp
, srclen
, dst
, dstlen
);
1190 case MAP_FOLDDIGITS
| MAP_COMPOSITE
:
1191 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1192 return STATUS_NO_MEMORY
;
1193 fold_digits( src
, srclen
, tmp
, &srclen
);
1194 ret
= RtlNormalizeString( NormalizationD
, tmp
, srclen
, dst
, dstlen
);
1196 case MAP_FOLDDIGITS
| MAP_COMPOSITE
| MAP_FOLDCZONE
:
1197 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1198 return STATUS_NO_MEMORY
;
1199 fold_digits( src
, srclen
, tmp
, &srclen
);
1200 ret
= RtlNormalizeString( NormalizationKD
, tmp
, srclen
, dst
, dstlen
);
1202 case MAP_EXPAND_LIGATURES
| MAP_FOLDDIGITS
:
1203 case MAP_EXPAND_LIGATURES
| MAP_FOLDDIGITS
| MAP_FOLDCZONE
:
1204 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1205 return STATUS_NO_MEMORY
;
1206 fold_digits( src
, srclen
, tmp
, &srclen
);
1207 ret
= expand_ligatures( tmp
, srclen
, dst
, dstlen
);
1210 return STATUS_INVALID_PARAMETER_1
;
1212 RtlFreeHeap( GetProcessHeap(), 0, tmp
);
1217 static int mbstowcs_cpsymbol( DWORD flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
)
1223 SetLastError( ERROR_INVALID_FLAGS
);
1226 if (!dstlen
) return srclen
;
1227 len
= min( srclen
, dstlen
);
1228 for (i
= 0; i
< len
; i
++)
1230 unsigned char c
= src
[i
];
1231 dst
[i
] = (c
< 0x20) ? c
: c
+ 0xf000;
1235 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1242 static int mbstowcs_utf7( DWORD flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
)
1244 static const signed char base64_decoding_table
[] =
1246 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0F */
1247 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1F */
1248 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20-0x2F */
1249 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30-0x3F */
1250 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40-0x4F */
1251 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50-0x5F */
1252 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60-0x6F */
1253 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70-0x7F */
1256 const char *source_end
= src
+ srclen
;
1257 int offset
= 0, pos
= 0;
1258 DWORD byte_pair
= 0;
1262 SetLastError( ERROR_INVALID_FLAGS
);
1265 #define OUTPUT(ch) \
1269 if (pos >= dstlen) goto overflow; \
1275 while (src
< source_end
)
1280 if (src
>= source_end
) break;
1283 /* just a plus sign escaped as +- */
1291 signed char sextet
= *src
;
1294 /* skip over the dash and end base64 decoding
1295 * the current, unfinished byte pair is discarded */
1302 /* the next character of src is < 0 and therefore not part of a base64 sequence
1303 * the current, unfinished byte pair is NOT discarded in this case
1304 * this is probably a bug in Windows */
1307 sextet
= base64_decoding_table
[sextet
];
1310 /* -1 means that the next character of src is not part of a base64 sequence
1311 * in other words, all sextets in this base64 sequence have been processed
1312 * the current, unfinished byte pair is discarded */
1317 byte_pair
= (byte_pair
<< 6) | sextet
;
1321 /* this byte pair is done */
1322 OUTPUT( byte_pair
>> (offset
- 16) );
1327 while (src
< source_end
);
1331 OUTPUT( (unsigned char)*src
);
1338 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1344 static int mbstowcs_utf8( DWORD flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
)
1349 if (flags
& ~(MB_PRECOMPOSED
| MB_COMPOSITE
| MB_USEGLYPHCHARS
| MB_ERR_INVALID_CHARS
))
1351 SetLastError( ERROR_INVALID_FLAGS
);
1354 if (!dstlen
) dst
= NULL
;
1355 status
= RtlUTF8ToUnicodeN( dst
, dstlen
* sizeof(WCHAR
), &reslen
, src
, srclen
);
1356 if (status
== STATUS_SOME_NOT_MAPPED
)
1358 if (flags
& MB_ERR_INVALID_CHARS
)
1360 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1364 else if (!set_ntstatus( status
)) reslen
= 0;
1366 return reslen
/ sizeof(WCHAR
);
1370 static inline int is_private_use_area_char( WCHAR code
)
1372 return (code
>= 0xe000 && code
<= 0xf8ff);
1376 static int check_invalid_chars( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
)
1378 if (info
->DBCSOffsets
)
1380 for ( ; srclen
; src
++, srclen
-- )
1382 USHORT off
= info
->DBCSOffsets
[*src
];
1385 if (srclen
== 1) break; /* partial char, error */
1386 if (info
->DBCSOffsets
[off
+ src
[1]] == info
->UniDefaultChar
&&
1387 ((src
[0] << 8) | src
[1]) != info
->TransUniDefaultChar
) break;
1392 if (info
->MultiByteTable
[*src
] == info
->UniDefaultChar
&& *src
!= info
->TransUniDefaultChar
)
1394 if (is_private_use_area_char( info
->MultiByteTable
[*src
] )) break;
1399 for ( ; srclen
; src
++, srclen
-- )
1401 if (info
->MultiByteTable
[*src
] == info
->UniDefaultChar
&& *src
!= info
->TransUniDefaultChar
)
1403 if (is_private_use_area_char( info
->MultiByteTable
[*src
] )) break;
1411 static int mbstowcs_decompose( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
,
1412 WCHAR
*dst
, int dstlen
)
1417 const WCHAR
*decomp
;
1418 unsigned int decomp_len
;
1420 if (info
->DBCSOffsets
)
1422 if (!dstlen
) /* compute length */
1424 for (len
= 0; srclen
; srclen
--, src
++, len
+= decomp_len
)
1426 if ((off
= info
->DBCSOffsets
[*src
]))
1428 if (srclen
> 1 && src
[1])
1432 ch
= info
->DBCSOffsets
[off
+ *src
];
1434 else ch
= info
->UniDefaultChar
;
1436 else ch
= info
->MultiByteTable
[*src
];
1437 get_decomposition( ch
, &decomp_len
);
1442 for (len
= dstlen
; srclen
&& len
; srclen
--, src
++, dst
+= decomp_len
, len
-= decomp_len
)
1444 if ((off
= info
->DBCSOffsets
[*src
]))
1446 if (srclen
> 1 && src
[1])
1450 ch
= info
->DBCSOffsets
[off
+ *src
];
1452 else ch
= info
->UniDefaultChar
;
1454 else ch
= info
->MultiByteTable
[*src
];
1456 if ((decomp
= get_decomposition( ch
, &decomp_len
)))
1458 if (len
< decomp_len
) break;
1459 memcpy( dst
, decomp
, decomp_len
* sizeof(WCHAR
) );
1466 if (!dstlen
) /* compute length */
1468 for (len
= 0; srclen
; srclen
--, src
++, len
+= decomp_len
)
1469 get_decomposition( info
->MultiByteTable
[*src
], &decomp_len
);
1473 for (len
= dstlen
; srclen
&& len
; srclen
--, src
++, dst
+= decomp_len
, len
-= decomp_len
)
1475 ch
= info
->MultiByteTable
[*src
];
1476 if ((decomp
= get_decomposition( ch
, &decomp_len
)))
1478 if (len
< decomp_len
) break;
1479 memcpy( dst
, decomp
, decomp_len
* sizeof(WCHAR
) );
1487 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1490 return dstlen
- len
;
1494 static int mbstowcs_sbcs( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
,
1495 WCHAR
*dst
, int dstlen
)
1497 const USHORT
*table
= info
->MultiByteTable
;
1500 if (!dstlen
) return srclen
;
1502 if (dstlen
< srclen
) /* buffer too small: fill it up to dstlen and return error */
1505 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1509 while (srclen
>= 16)
1511 dst
[0] = table
[src
[0]];
1512 dst
[1] = table
[src
[1]];
1513 dst
[2] = table
[src
[2]];
1514 dst
[3] = table
[src
[3]];
1515 dst
[4] = table
[src
[4]];
1516 dst
[5] = table
[src
[5]];
1517 dst
[6] = table
[src
[6]];
1518 dst
[7] = table
[src
[7]];
1519 dst
[8] = table
[src
[8]];
1520 dst
[9] = table
[src
[9]];
1521 dst
[10] = table
[src
[10]];
1522 dst
[11] = table
[src
[11]];
1523 dst
[12] = table
[src
[12]];
1524 dst
[13] = table
[src
[13]];
1525 dst
[14] = table
[src
[14]];
1526 dst
[15] = table
[src
[15]];
1532 /* now handle the remaining characters */
1537 case 15: dst
[-15] = table
[src
[-15]];
1538 case 14: dst
[-14] = table
[src
[-14]];
1539 case 13: dst
[-13] = table
[src
[-13]];
1540 case 12: dst
[-12] = table
[src
[-12]];
1541 case 11: dst
[-11] = table
[src
[-11]];
1542 case 10: dst
[-10] = table
[src
[-10]];
1543 case 9: dst
[-9] = table
[src
[-9]];
1544 case 8: dst
[-8] = table
[src
[-8]];
1545 case 7: dst
[-7] = table
[src
[-7]];
1546 case 6: dst
[-6] = table
[src
[-6]];
1547 case 5: dst
[-5] = table
[src
[-5]];
1548 case 4: dst
[-4] = table
[src
[-4]];
1549 case 3: dst
[-3] = table
[src
[-3]];
1550 case 2: dst
[-2] = table
[src
[-2]];
1551 case 1: dst
[-1] = table
[src
[-1]];
1558 static int mbstowcs_dbcs( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
,
1559 WCHAR
*dst
, int dstlen
)
1566 for (i
= 0; srclen
; i
++, src
++, srclen
--)
1567 if (info
->DBCSOffsets
[*src
] && srclen
> 1 && src
[1]) { src
++; srclen
--; }
1571 for (i
= dstlen
; srclen
&& i
; i
--, srclen
--, src
++, dst
++)
1573 if ((off
= info
->DBCSOffsets
[*src
]))
1575 if (srclen
> 1 && src
[1])
1579 *dst
= info
->DBCSOffsets
[off
+ *src
];
1581 else *dst
= info
->UniDefaultChar
;
1583 else *dst
= info
->MultiByteTable
[*src
];
1587 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1594 static int mbstowcs_codepage( UINT codepage
, DWORD flags
, const char *src
, int srclen
,
1595 WCHAR
*dst
, int dstlen
)
1597 CPTABLEINFO local_info
;
1598 const CPTABLEINFO
*info
= get_codepage_table( codepage
);
1599 const unsigned char *str
= (const unsigned char *)src
;
1603 SetLastError( ERROR_INVALID_PARAMETER
);
1606 if (flags
& ~(MB_PRECOMPOSED
| MB_COMPOSITE
| MB_USEGLYPHCHARS
| MB_ERR_INVALID_CHARS
))
1608 SetLastError( ERROR_INVALID_FLAGS
);
1612 if ((flags
& MB_USEGLYPHCHARS
) && info
->MultiByteTable
[256] == 256)
1615 local_info
.MultiByteTable
+= 257;
1618 if ((flags
& MB_ERR_INVALID_CHARS
) && check_invalid_chars( info
, str
, srclen
))
1620 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1624 if (flags
& MB_COMPOSITE
) return mbstowcs_decompose( info
, str
, srclen
, dst
, dstlen
);
1626 if (info
->DBCSOffsets
)
1627 return mbstowcs_dbcs( info
, str
, srclen
, dst
, dstlen
);
1629 return mbstowcs_sbcs( info
, str
, srclen
, dst
, dstlen
);
1633 static int wcstombs_cpsymbol( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
,
1634 const char *defchar
, BOOL
*used
)
1640 SetLastError( ERROR_INVALID_FLAGS
);
1643 if (defchar
|| used
)
1645 SetLastError( ERROR_INVALID_PARAMETER
);
1648 if (!dstlen
) return srclen
;
1649 len
= min( srclen
, dstlen
);
1650 for (i
= 0; i
< len
; i
++)
1652 if (src
[i
] < 0x20) dst
[i
] = src
[i
];
1653 else if (src
[i
] >= 0xf020 && src
[i
] < 0xf100) dst
[i
] = src
[i
] - 0xf000;
1656 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1662 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1669 static int wcstombs_utf7( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
,
1670 const char *defchar
, BOOL
*used
)
1672 static const char directly_encodable
[] =
1674 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0x00 - 0x0f */
1675 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */
1676 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* 0x20 - 0x2f */
1677 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x30 - 0x3f */
1678 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */
1679 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */
1680 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */
1681 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* 0x70 - 0x7a */
1683 #define ENCODABLE(ch) ((ch) <= 0x7a && directly_encodable[(ch)])
1685 static const char base64_encoding_table
[] =
1686 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1688 const WCHAR
*source_end
= src
+ srclen
;
1691 if (defchar
|| used
)
1693 SetLastError( ERROR_INVALID_PARAMETER
);
1698 SetLastError( ERROR_INVALID_FLAGS
);
1702 #define OUTPUT(ch) \
1706 if (pos >= dstlen) goto overflow; \
1712 while (src
< source_end
)
1720 else if (ENCODABLE(*src
))
1727 unsigned int offset
= 0, byte_pair
= 0;
1730 while (src
< source_end
&& !ENCODABLE(*src
))
1732 byte_pair
= (byte_pair
<< 16) | *src
;
1737 OUTPUT( base64_encoding_table
[(byte_pair
>> offset
) & 0x3f] );
1743 /* Windows won't create a padded base64 character if there's no room for the - sign
1744 * as well ; this is probably a bug in Windows */
1745 if (dstlen
> 0 && pos
+ 1 >= dstlen
) goto overflow
;
1746 byte_pair
<<= (6 - offset
);
1747 OUTPUT( base64_encoding_table
[byte_pair
& 0x3f] );
1749 /* Windows always explicitly terminates the base64 sequence
1750 even though RFC 2152 (page 3, rule 2) does not require this */
1757 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1764 static int wcstombs_utf8( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
,
1765 const char *defchar
, BOOL
*used
)
1770 if (defchar
|| used
)
1772 SetLastError( ERROR_INVALID_PARAMETER
);
1775 if (flags
& ~(WC_DISCARDNS
| WC_SEPCHARS
| WC_DEFAULTCHAR
| WC_ERR_INVALID_CHARS
|
1776 WC_COMPOSITECHECK
| WC_NO_BEST_FIT_CHARS
))
1778 SetLastError( ERROR_INVALID_FLAGS
);
1781 if (!dstlen
) dst
= NULL
;
1782 status
= RtlUnicodeToUTF8N( dst
, dstlen
, &reslen
, src
, srclen
* sizeof(WCHAR
) );
1783 if (status
== STATUS_SOME_NOT_MAPPED
)
1785 if (flags
& WC_ERR_INVALID_CHARS
)
1787 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1791 else if (!set_ntstatus( status
)) reslen
= 0;
1796 static int wcstombs_sbcs( const CPTABLEINFO
*info
, const WCHAR
*src
, unsigned int srclen
,
1797 char *dst
, unsigned int dstlen
)
1799 const char *table
= info
->WideCharTable
;
1802 if (!dstlen
) return srclen
;
1804 if (dstlen
< srclen
)
1806 /* buffer too small: fill it up to dstlen and return error */
1808 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1812 while (srclen
>= 16)
1814 dst
[0] = table
[src
[0]];
1815 dst
[1] = table
[src
[1]];
1816 dst
[2] = table
[src
[2]];
1817 dst
[3] = table
[src
[3]];
1818 dst
[4] = table
[src
[4]];
1819 dst
[5] = table
[src
[5]];
1820 dst
[6] = table
[src
[6]];
1821 dst
[7] = table
[src
[7]];
1822 dst
[8] = table
[src
[8]];
1823 dst
[9] = table
[src
[9]];
1824 dst
[10] = table
[src
[10]];
1825 dst
[11] = table
[src
[11]];
1826 dst
[12] = table
[src
[12]];
1827 dst
[13] = table
[src
[13]];
1828 dst
[14] = table
[src
[14]];
1829 dst
[15] = table
[src
[15]];
1835 /* now handle remaining characters */
1840 case 15: dst
[-15] = table
[src
[-15]];
1841 case 14: dst
[-14] = table
[src
[-14]];
1842 case 13: dst
[-13] = table
[src
[-13]];
1843 case 12: dst
[-12] = table
[src
[-12]];
1844 case 11: dst
[-11] = table
[src
[-11]];
1845 case 10: dst
[-10] = table
[src
[-10]];
1846 case 9: dst
[-9] = table
[src
[-9]];
1847 case 8: dst
[-8] = table
[src
[-8]];
1848 case 7: dst
[-7] = table
[src
[-7]];
1849 case 6: dst
[-6] = table
[src
[-6]];
1850 case 5: dst
[-5] = table
[src
[-5]];
1851 case 4: dst
[-4] = table
[src
[-4]];
1852 case 3: dst
[-3] = table
[src
[-3]];
1853 case 2: dst
[-2] = table
[src
[-2]];
1854 case 1: dst
[-1] = table
[src
[-1]];
1861 static int wcstombs_dbcs( const CPTABLEINFO
*info
, const WCHAR
*src
, unsigned int srclen
,
1862 char *dst
, unsigned int dstlen
)
1864 const USHORT
*table
= info
->WideCharTable
;
1869 for (i
= 0; srclen
; src
++, srclen
--, i
++) if (table
[*src
] & 0xff00) i
++;
1873 for (i
= dstlen
; srclen
&& i
; i
--, srclen
--, src
++)
1875 if (table
[*src
] & 0xff00)
1877 if (i
== 1) break; /* do not output a partial char */
1879 *dst
++ = table
[*src
] >> 8;
1881 *dst
++ = (char)table
[*src
];
1885 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1892 static inline int is_valid_sbcs_mapping( const CPTABLEINFO
*info
, DWORD flags
, unsigned int wch
)
1894 const unsigned char *table
= info
->WideCharTable
;
1896 if (wch
>= 0x10000) return 0;
1897 if ((flags
& WC_NO_BEST_FIT_CHARS
) || table
[wch
] == info
->DefaultChar
)
1898 return (info
->MultiByteTable
[table
[wch
]] == wch
);
1903 static inline int is_valid_dbcs_mapping( const CPTABLEINFO
*info
, DWORD flags
, unsigned int wch
)
1905 const unsigned short *table
= info
->WideCharTable
;
1908 if (wch
>= 0x10000) return 0;
1910 if ((flags
& WC_NO_BEST_FIT_CHARS
) || ch
== info
->DefaultChar
)
1912 if (ch
>> 8) return info
->DBCSOffsets
[info
->DBCSOffsets
[ch
>> 8] + (ch
& 0xff)] == wch
;
1913 return info
->MultiByteTable
[ch
] == wch
;
1919 static int wcstombs_sbcs_slow( const CPTABLEINFO
*info
, DWORD flags
, const WCHAR
*src
, unsigned int srclen
,
1920 char *dst
, unsigned int dstlen
, const char *defchar
, BOOL
*used
)
1922 const char *table
= info
->WideCharTable
;
1923 const char def
= defchar
? *defchar
: (char)info
->DefaultChar
;
1927 unsigned int composed
;
1929 if (!used
) used
= &tmp
; /* avoid checking on every char */
1934 for (i
= 0; srclen
; i
++, src
++, srclen
--)
1937 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
1939 /* now check if we can use the composed char */
1940 if (is_valid_sbcs_mapping( info
, flags
, composed
))
1942 /* we have a good mapping, use it */
1947 /* no mapping for the composed char, check the other flags */
1948 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
1951 src
++; /* skip the non-spacing char */
1955 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
1960 /* WC_SEPCHARS is the default */
1962 if (!*used
) *used
= !is_valid_sbcs_mapping( info
, flags
, wch
);
1967 for (i
= dstlen
; srclen
&& i
; dst
++, i
--, src
++, srclen
--)
1970 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
1972 /* now check if we can use the composed char */
1973 if (is_valid_sbcs_mapping( info
, flags
, composed
))
1975 /* we have a good mapping, use it */
1976 *dst
= table
[composed
];
1981 /* no mapping for the composed char, check the other flags */
1982 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
1986 src
++; /* skip the non-spacing char */
1990 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
1995 /* WC_SEPCHARS is the default */
1999 if (!is_valid_sbcs_mapping( info
, flags
, wch
))
2007 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
2014 static int wcstombs_dbcs_slow( const CPTABLEINFO
*info
, DWORD flags
, const WCHAR
*src
, unsigned int srclen
,
2015 char *dst
, unsigned int dstlen
, const char *defchar
, BOOL
*used
)
2017 const USHORT
*table
= info
->WideCharTable
;
2018 WCHAR wch
, defchar_value
;
2019 unsigned int composed
;
2024 if (!defchar
[1]) defchar_value
= (unsigned char)defchar
[0];
2025 else defchar_value
= ((unsigned char)defchar
[0] << 8) | (unsigned char)defchar
[1];
2027 if (!used
) used
= &tmp
; /* avoid checking on every char */
2032 if (!defchar
&& !used
&& !(flags
& WC_COMPOSITECHECK
))
2034 for (i
= 0; srclen
; srclen
--, src
++, i
++) if (table
[*src
] & 0xff00) i
++;
2037 for (i
= 0; srclen
; srclen
--, src
++, i
++)
2040 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
2042 /* now check if we can use the composed char */
2043 if (is_valid_dbcs_mapping( info
, flags
, composed
))
2045 /* we have a good mapping for the composed char, use it */
2046 res
= table
[composed
];
2047 if (res
& 0xff00) i
++;
2052 /* no mapping for the composed char, check the other flags */
2053 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
2055 if (defchar_value
& 0xff00) i
++;
2057 src
++; /* skip the non-spacing char */
2061 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
2066 /* WC_SEPCHARS is the default */
2070 if (!is_valid_dbcs_mapping( info
, flags
, wch
))
2072 res
= defchar_value
;
2075 if (res
& 0xff00) i
++;
2081 for (i
= dstlen
; srclen
&& i
; i
--, srclen
--, src
++)
2084 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
2086 /* now check if we can use the composed char */
2087 if (is_valid_dbcs_mapping( info
, flags
, composed
))
2089 /* we have a good mapping for the composed char, use it */
2090 res
= table
[composed
];
2095 /* no mapping for the composed char, check the other flags */
2096 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
2098 res
= defchar_value
;
2100 src
++; /* skip the non-spacing char */
2104 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
2109 /* WC_SEPCHARS is the default */
2113 if (!is_valid_dbcs_mapping( info
, flags
, wch
))
2115 res
= defchar_value
;
2122 if (i
== 1) break; /* do not output a partial char */
2130 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
2137 static int wcstombs_codepage( UINT codepage
, DWORD flags
, const WCHAR
*src
, int srclen
,
2138 char *dst
, int dstlen
, const char *defchar
, BOOL
*used
)
2140 const CPTABLEINFO
*info
= get_codepage_table( codepage
);
2144 SetLastError( ERROR_INVALID_PARAMETER
);
2147 if (flags
& ~(WC_DISCARDNS
| WC_SEPCHARS
| WC_DEFAULTCHAR
| WC_ERR_INVALID_CHARS
|
2148 WC_COMPOSITECHECK
| WC_NO_BEST_FIT_CHARS
))
2150 SetLastError( ERROR_INVALID_FLAGS
);
2153 if (flags
|| defchar
|| used
)
2155 if (!defchar
) defchar
= (const char *)&info
->DefaultChar
;
2156 if (info
->DBCSOffsets
)
2157 return wcstombs_dbcs_slow( info
, flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
2159 return wcstombs_sbcs_slow( info
, flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
2161 if (info
->DBCSOffsets
)
2162 return wcstombs_dbcs( info
, src
, srclen
, dst
, dstlen
);
2164 return wcstombs_sbcs( info
, src
, srclen
, dst
, dstlen
);
2168 static int get_sortkey( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
)
2170 WCHAR dummy
[4]; /* no decomposition is larger than 4 chars */
2173 const WCHAR
*src_save
= src
;
2174 int srclen_save
= srclen
;
2176 key_len
[0] = key_len
[1] = key_len
[2] = key_len
[3] = 0;
2177 for (; srclen
; srclen
--, src
++)
2179 unsigned int i
, decomposed_len
= 1;/*wine_decompose(*src, dummy, 4);*/
2183 for (i
= 0; i
< decomposed_len
; i
++)
2185 WCHAR wch
= dummy
[i
];
2188 if ((flags
& NORM_IGNORESYMBOLS
) &&
2189 (get_char_type( CT_CTYPE1
, wch
) & (C1_PUNCT
| C1_SPACE
)))
2192 if (flags
& NORM_IGNORECASE
) wch
= casemap( nls_info
.LowerCaseTable
, wch
);
2194 ce
= collation_table
[collation_table
[collation_table
[wch
>> 8] + ((wch
>> 4) & 0x0f)] + (wch
& 0xf)];
2195 if (ce
!= (unsigned int)-1)
2197 if (ce
>> 16) key_len
[0] += 2;
2198 if ((ce
>> 8) & 0xff) key_len
[1]++;
2199 if ((ce
>> 4) & 0x0f) key_len
[2]++;
2202 if (wch
>> 8) key_len
[3]++;
2209 if (wch
>> 8) key_len
[0]++;
2210 if (wch
& 0xff) key_len
[0]++;
2216 if (!dstlen
) /* compute length */
2217 /* 4 * '\1' + key length */
2218 return key_len
[0] + key_len
[1] + key_len
[2] + key_len
[3] + 4;
2220 if (dstlen
< key_len
[0] + key_len
[1] + key_len
[2] + key_len
[3] + 4 + 1)
2221 return 0; /* overflow */
2224 srclen
= srclen_save
;
2227 key_ptr
[1] = key_ptr
[0] + key_len
[0] + 1;
2228 key_ptr
[2] = key_ptr
[1] + key_len
[1] + 1;
2229 key_ptr
[3] = key_ptr
[2] + key_len
[2] + 1;
2231 for (; srclen
; srclen
--, src
++)
2233 unsigned int i
, decomposed_len
= 1;/*wine_decompose(*src, dummy, 4);*/
2237 for (i
= 0; i
< decomposed_len
; i
++)
2239 WCHAR wch
= dummy
[i
];
2242 if ((flags
& NORM_IGNORESYMBOLS
) &&
2243 (get_char_type( CT_CTYPE1
, wch
) & (C1_PUNCT
| C1_SPACE
)))
2246 if (flags
& NORM_IGNORECASE
) wch
= casemap( nls_info
.LowerCaseTable
, wch
);
2248 ce
= collation_table
[collation_table
[collation_table
[wch
>> 8] + ((wch
>> 4) & 0x0f)] + (wch
& 0xf)];
2249 if (ce
!= (unsigned int)-1)
2252 if ((key
= ce
>> 16))
2254 *key_ptr
[0]++ = key
>> 8;
2255 *key_ptr
[0]++ = key
& 0xff;
2257 /* make key 1 start from 2 */
2258 if ((key
= (ce
>> 8) & 0xff)) *key_ptr
[1]++ = key
+ 1;
2259 /* make key 2 start from 2 */
2260 if ((key
= (ce
>> 4) & 0x0f)) *key_ptr
[2]++ = key
+ 1;
2261 /* key 3 is always a character code */
2264 if (wch
>> 8) *key_ptr
[3]++ = wch
>> 8;
2265 if (wch
& 0xff) *key_ptr
[3]++ = wch
& 0xff;
2270 *key_ptr
[0]++ = 0xff;
2271 *key_ptr
[0]++ = 0xfe;
2272 if (wch
>> 8) *key_ptr
[0]++ = wch
>> 8;
2273 if (wch
& 0xff) *key_ptr
[0]++ = wch
& 0xff;
2284 return key_ptr
[3] - dst
;
2288 /* compose a full-width katakana. return consumed source characters. */
2289 static int compose_katakana( const WCHAR
*src
, int srclen
, WCHAR
*dst
)
2291 static const BYTE katakana_map
[] =
2293 /* */ 0x02, 0x0c, 0x0d, 0x01, 0xfb, 0xf2, 0xa1, /* U+FF61- */
2294 0xa3, 0xa5, 0xa7, 0xa9, 0xe3, 0xe5, 0xe7, 0xc3, /* U+FF68- */
2295 0xfc, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xab, 0xad, /* U+FF70- */
2296 0xaf, 0xb1, 0xb3, 0xb5, 0xb7, 0xb9, 0xbb, 0xbd, /* U+FF78- */
2297 0xbf, 0xc1, 0xc4, 0xc6, 0xc8, 0xca, 0xcb, 0xcc, /* U+FF80- */
2298 0xcd, 0xce, 0xcf, 0xd2, 0xd5, 0xd8, 0xdb, 0xde, /* U+FF88- */
2299 0xdf, 0xe0, 0xe1, 0xe2, 0xe4, 0xe6, 0xe8, 0xe9, /* U+FF90- */
2300 0xea, 0xeb, 0xec, 0xed, 0xef, 0xf3, 0x99, 0x9a, /* U+FF98- */
2305 if (!dst
) dst
= &dummy
;
2319 shift
= *src
- 0xff61;
2320 if (shift
< 0 || shift
>= ARRAY_SIZE( katakana_map
)) return 0;
2321 *dst
= katakana_map
[shift
] | 0x3000;
2325 if (srclen
<= 1) return 1;
2329 case 0xff9e: /* datakuten (voiced sound) */
2330 if ((*src
>= 0xff76 && *src
<= 0xff84) || (*src
>= 0xff8a && *src
<= 0xff8e) || *src
== 0x30fd)
2332 else if (*src
== 0xff73)
2333 *dst
= 0x30f4; /* KATAKANA LETTER VU */
2334 else if (*src
== 0xff9c)
2335 *dst
= 0x30f7; /* KATAKANA LETTER VA */
2336 else if (*src
== 0x30f0)
2337 *dst
= 0x30f8; /* KATAKANA LETTER VI */
2338 else if (*src
== 0x30f1)
2339 *dst
= 0x30f9; /* KATAKANA LETTER VE */
2340 else if (*src
== 0xff66)
2341 *dst
= 0x30fa; /* KATAKANA LETTER VO */
2345 case 0xff9f: /* handakuten (semi-voiced sound) */
2346 if (*src
>= 0xff8a && *src
<= 0xff8e)
2357 /* map one or two half-width characters to one full-width character */
2358 static int map_to_fullwidth( const WCHAR
*src
, int srclen
, WCHAR
*dst
)
2362 if (*src
<= '~' && *src
> ' ' && *src
!= '\\')
2363 *dst
= *src
- 0x20 + 0xff00;
2364 else if (*src
== ' ')
2366 else if (*src
<= 0x00af && *src
>= 0x00a2)
2368 static const BYTE misc_symbols_table
[] =
2370 0xe0, 0xe1, 0x00, 0xe5, 0xe4, 0x00, 0x00, /* U+00A2- */
2371 0x00, 0x00, 0x00, 0xe2, 0x00, 0x00, 0xe3 /* U+00A9- */
2373 if (misc_symbols_table
[*src
- 0x00a2])
2374 *dst
= misc_symbols_table
[*src
- 0x00a2] | 0xff00;
2378 else if (*src
== 0x20a9) /* WON SIGN */
2380 else if ((n
= compose_katakana(src
, srclen
, dst
)) > 0)
2382 else if (*src
>= 0xffa0 && *src
<= 0xffdc)
2384 static const BYTE hangul_mapping_table
[] =
2386 0x64, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* U+FFA0- */
2387 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* U+FFA8- */
2388 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* U+FFB0- */
2389 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x00, /* U+FFB8- */
2390 0x00, 0x00, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, /* U+FFC0- */
2391 0x00, 0x00, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, /* U+FFC8- */
2392 0x00, 0x00, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, /* U+FFD0- */
2393 0x00, 0x00, 0x61, 0x62, 0x63 /* U+FFD8- */
2396 if (hangul_mapping_table
[*src
- 0xffa0])
2397 *dst
= hangul_mapping_table
[*src
- 0xffa0] | 0x3100;
2407 /* decompose a full-width katakana character into one or two half-width characters. */
2408 static int decompose_katakana( WCHAR c
, WCHAR
*dst
, int dstlen
)
2410 static const BYTE katakana_map
[] =
2412 /* */ 0x9e, 0x9f, 0x9e, 0x9f, 0x00, 0x00, 0x00, /* U+3099- */
2413 0x00, 0x67, 0x71, 0x68, 0x72, 0x69, 0x73, 0x6a, /* U+30a1- */
2414 0x74, 0x6b, 0x75, 0x76, 0x01, 0x77, 0x01, 0x78, /* U+30a8- */
2415 0x01, 0x79, 0x01, 0x7a, 0x01, 0x7b, 0x01, 0x7c, /* U+30b0- */
2416 0x01, 0x7d, 0x01, 0x7e, 0x01, 0x7f, 0x01, 0x80, /* U+30b8- */
2417 0x01, 0x81, 0x01, 0x6f, 0x82, 0x01, 0x83, 0x01, /* U+30c0- */
2418 0x84, 0x01, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, /* U+30c8- */
2419 0x01, 0x02, 0x8b, 0x01, 0x02, 0x8c, 0x01, 0x02, /* U+30d0- */
2420 0x8d, 0x01, 0x02, 0x8e, 0x01, 0x02, 0x8f, 0x90, /* U+30d8- */
2421 0x91, 0x92, 0x93, 0x6c, 0x94, 0x6d, 0x95, 0x6e, /* U+30e0- */
2422 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x00, 0x9c, /* U+30e8- */
2423 0x00, 0x00, 0x66, 0x9d, 0x4e, 0x00, 0x00, 0x08, /* U+30f0- */
2424 0x58, 0x58, 0x08, 0x65, 0x70, 0x00, 0x51 /* U+30f8- */
2426 int len
= 0, shift
= c
- 0x3099;
2429 if (shift
< 0 || shift
>= ARRAY_SIZE( katakana_map
)) return 0;
2431 k
= katakana_map
[shift
];
2434 if (dstlen
> 0) *dst
= c
;
2439 if (dstlen
> 0) *dst
= k
| 0xff00;
2446 dst
[0] = (k
> 0x50) ? (c
- (k
& 0xf)) : (katakana_map
[shift
- k
] | 0xff00);
2447 dst
[1] = (k
== 2) ? 0xff9f : 0xff9e;
2454 /* map single full-width character to single or double half-width characters. */
2455 static int map_to_halfwidth( WCHAR c
, WCHAR
*dst
, int dstlen
)
2457 int n
= decompose_katakana( c
, dst
, dstlen
);
2458 if (n
> 0) return n
;
2462 else if (c
== 0x3001)
2464 else if (c
== 0x3002)
2466 else if (c
== 0x300c || c
== 0x300d)
2467 *dst
= (c
- 0x300c) + 0xff62;
2468 else if (c
>= 0x3131 && c
<= 0x3163)
2470 *dst
= c
- 0x3131 + 0xffa1;
2471 if (*dst
>= 0xffbf) *dst
+= 3;
2472 if (*dst
>= 0xffc8) *dst
+= 2;
2473 if (*dst
>= 0xffd0) *dst
+= 2;
2474 if (*dst
>= 0xffd8) *dst
+= 2;
2476 else if (c
== 0x3164)
2478 else if (c
== 0x2019)
2480 else if (c
== 0x201d)
2482 else if (c
> 0xff00 && c
< 0xff5f && c
!= 0xff3c)
2483 *dst
= c
- 0xff00 + 0x20;
2484 else if (c
>= 0xffe0 && c
<= 0xffe6)
2486 static const WCHAR misc_symbol_map
[] = { 0x00a2, 0x00a3, 0x00ac, 0x00af, 0x00a6, 0x00a5, 0x20a9 };
2487 *dst
= misc_symbol_map
[c
- 0xffe0];
2496 /* 32-bit collation element table format:
2497 * unicode weight - high 16 bit, diacritic weight - high 8 bit of low 16 bit,
2498 * case weight - high 4 bit of low 8 bit.
2501 enum weight
{ UNICODE_WEIGHT
, DIACRITIC_WEIGHT
, CASE_WEIGHT
};
2503 static unsigned int get_weight( WCHAR ch
, enum weight type
)
2507 ret
= collation_table
[collation_table
[collation_table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0xf)];
2508 if (ret
== ~0u) return ch
;
2512 case UNICODE_WEIGHT
: return ret
>> 16;
2513 case DIACRITIC_WEIGHT
: return (ret
>> 8) & 0xff;
2514 case CASE_WEIGHT
: return (ret
>> 4) & 0x0f;
2520 static void inc_str_pos( const WCHAR
**str
, int *len
, unsigned int *dpos
, unsigned int *dlen
)
2532 static int compare_weights(int flags
, const WCHAR
*str1
, int len1
,
2533 const WCHAR
*str2
, int len2
, enum weight type
)
2535 unsigned int ce1
, ce2
, dpos1
= 0, dpos2
= 0, dlen1
= 0, dlen2
= 0;
2536 const WCHAR
*dstr1
= NULL
, *dstr2
= NULL
;
2538 while (len1
> 0 && len2
> 0)
2540 if (!dlen1
&& !(dstr1
= get_decomposition( *str1
, &dlen1
))) dstr1
= str1
;
2541 if (!dlen2
&& !(dstr2
= get_decomposition( *str2
, &dlen2
))) dstr2
= str2
;
2543 if (flags
& NORM_IGNORESYMBOLS
)
2546 /* FIXME: not tested */
2547 if (get_char_type( CT_CTYPE1
, dstr1
[dpos1
] ) & (C1_PUNCT
| C1_SPACE
))
2549 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2552 if (get_char_type( CT_CTYPE1
, dstr2
[dpos2
] ) & (C1_PUNCT
| C1_SPACE
))
2554 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2560 /* hyphen and apostrophe are treated differently depending on
2561 * whether SORT_STRINGSORT specified or not
2563 if (type
== UNICODE_WEIGHT
&& !(flags
& SORT_STRINGSORT
))
2565 if (dstr1
[dpos1
] == '-' || dstr1
[dpos1
] == '\'')
2567 if (dstr2
[dpos2
] != '-' && dstr2
[dpos2
] != '\'')
2569 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2573 else if (dstr2
[dpos2
] == '-' || dstr2
[dpos2
] == '\'')
2575 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2580 ce1
= get_weight( dstr1
[dpos1
], type
);
2583 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2586 ce2
= get_weight( dstr2
[dpos2
], type
);
2589 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2593 if (ce1
- ce2
) return ce1
- ce2
;
2595 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2596 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2600 if (!dlen1
&& !(dstr1
= get_decomposition( *str1
, &dlen1
))) dstr1
= str1
;
2601 ce1
= get_weight( dstr1
[dpos1
], type
);
2603 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2607 if (!dlen2
&& !(dstr2
= get_decomposition( *str2
, &dlen2
))) dstr2
= str2
;
2608 ce2
= get_weight( dstr2
[dpos2
], type
);
2610 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2616 static const struct geoinfo
*get_geoinfo_ptr( GEOID geoid
)
2618 int min
= 0, max
= ARRAY_SIZE( geoinfodata
)-1;
2622 int n
= (min
+ max
)/2;
2623 const struct geoinfo
*ptr
= &geoinfodata
[n
];
2624 if (geoid
== ptr
->id
) /* we don't need empty entries */
2625 return *ptr
->iso2W
? ptr
: NULL
;
2626 if (ptr
->id
> geoid
) max
= n
-1;
2633 static int compare_tzdate( const TIME_FIELDS
*tf
, const SYSTEMTIME
*compare
)
2635 static const int month_lengths
[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
2636 int first
, last
, limit
, dayinsecs
;
2638 if (tf
->Month
< compare
->wMonth
) return -1; /* We are in a month before the date limit. */
2639 if (tf
->Month
> compare
->wMonth
) return 1; /* We are in a month after the date limit. */
2641 /* if year is 0 then date is in day-of-week format, otherwise
2642 * it's absolute date.
2644 if (!compare
->wYear
)
2646 /* wDay is interpreted as number of the week in the month
2647 * 5 means: the last week in the month */
2648 /* calculate the day of the first DayOfWeek in the month */
2649 first
= (6 + compare
->wDayOfWeek
- tf
->Weekday
+ tf
->Day
) % 7 + 1;
2650 /* check needed for the 5th weekday of the month */
2651 last
= month_lengths
[tf
->Month
- 1] +
2652 (tf
->Month
== 2 && (!(tf
->Year
% 4) && (tf
->Year
% 100 || !(tf
->Year
% 400))));
2653 limit
= first
+ 7 * (compare
->wDay
- 1);
2654 if (limit
> last
) limit
-= 7;
2656 else limit
= compare
->wDay
;
2658 limit
= ((limit
* 24 + compare
->wHour
) * 60 + compare
->wMinute
) * 60;
2659 dayinsecs
= ((tf
->Day
* 24 + tf
->Hour
) * 60 + tf
->Minute
) * 60 + tf
->Second
;
2660 return dayinsecs
- limit
;
2664 static DWORD
get_timezone_id( const TIME_ZONE_INFORMATION
*info
, LARGE_INTEGER time
, BOOL is_local
)
2667 BOOL before_standard_date
, after_daylight_date
;
2671 if (!info
->DaylightDate
.wMonth
) return TIME_ZONE_ID_UNKNOWN
;
2673 /* if year is 0 then date is in day-of-week format, otherwise it's absolute date */
2674 if (info
->StandardDate
.wMonth
== 0 ||
2675 (info
->StandardDate
.wYear
== 0 &&
2676 (info
->StandardDate
.wDay
< 1 || info
->StandardDate
.wDay
> 5 ||
2677 info
->DaylightDate
.wDay
< 1 || info
->DaylightDate
.wDay
> 5)))
2679 SetLastError( ERROR_INVALID_PARAMETER
);
2680 return TIME_ZONE_ID_INVALID
;
2683 if (!is_local
) time
.QuadPart
-= info
->Bias
* (LONGLONG
)600000000;
2684 RtlTimeToTimeFields( &time
, &tf
);
2688 t2
.QuadPart
= time
.QuadPart
- info
->DaylightBias
* (LONGLONG
)600000000;
2689 RtlTimeToTimeFields( &t2
, &tf
);
2691 if (tf
.Year
== year
)
2692 before_standard_date
= compare_tzdate( &tf
, &info
->StandardDate
) < 0;
2694 before_standard_date
= tf
.Year
< year
;
2698 t2
.QuadPart
= time
.QuadPart
- info
->StandardBias
* (LONGLONG
)600000000;
2699 RtlTimeToTimeFields( &t2
, &tf
);
2701 if (tf
.Year
== year
)
2702 after_daylight_date
= compare_tzdate( &tf
, &info
->DaylightDate
) >= 0;
2704 after_daylight_date
= tf
.Year
> year
;
2706 if (info
->DaylightDate
.wMonth
< info
->StandardDate
.wMonth
) /* Northern hemisphere */
2708 if (before_standard_date
&& after_daylight_date
) return TIME_ZONE_ID_DAYLIGHT
;
2710 else /* Down south */
2712 if (before_standard_date
|| after_daylight_date
) return TIME_ZONE_ID_DAYLIGHT
;
2714 return TIME_ZONE_ID_STANDARD
;
2718 /* Note: the Internal_ functions are not documented. The number of parameters
2719 * should be correct, but their exact meaning may not.
2722 /******************************************************************************
2723 * Internal_EnumCalendarInfo (kernelbase.@)
2725 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumCalendarInfo( CALINFO_ENUMPROCW proc
, LCID lcid
, CALID id
,
2726 CALTYPE type
, BOOL unicode
, BOOL ex
,
2727 BOOL exex
, LPARAM lparam
)
2735 SetLastError( ERROR_INVALID_PARAMETER
);
2739 if (id
== ENUM_ALL_CALENDARS
)
2741 if (!GetLocaleInfoW( lcid
, LOCALE_ICALENDARTYPE
| LOCALE_RETURN_NUMBER
,
2742 (WCHAR
*)&id
, sizeof(id
) / sizeof(WCHAR
) )) return FALSE
;
2743 if (!GetLocaleInfoW( lcid
, LOCALE_IOPTIONALCALENDAR
| LOCALE_RETURN_NUMBER
,
2744 (WCHAR
*)&optional
, sizeof(optional
) / sizeof(WCHAR
) )) optional
= 0;
2749 if (type
& CAL_RETURN_NUMBER
)
2750 ret
= GetCalendarInfoW( lcid
, id
, type
, NULL
, 0, (LPDWORD
)buffer
);
2752 ret
= GetCalendarInfoW( lcid
, id
, type
, buffer
, ARRAY_SIZE(buffer
), NULL
);
2756 ret
= GetCalendarInfoW( lcid
, id
, type
, bufW
, ARRAY_SIZE(bufW
), NULL
);
2757 if (ret
) WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, (char *)buffer
, sizeof(buffer
), NULL
, NULL
);
2762 if (exex
) ret
= ((CALINFO_ENUMPROCEXEX
)proc
)( buffer
, id
, NULL
, lparam
);
2763 else if (ex
) ret
= ((CALINFO_ENUMPROCEXW
)proc
)( buffer
, id
);
2764 else ret
= proc( buffer
);
2767 if (!optional
) break;
2774 /**************************************************************************
2775 * Internal_EnumDateFormats (kernelbase.@)
2777 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumDateFormats( DATEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
,
2778 BOOL unicode
, BOOL ex
, BOOL exex
, LPARAM lparam
)
2787 SetLastError( ERROR_INVALID_PARAMETER
);
2790 if (!GetLocaleInfoW( lcid
, LOCALE_ICALENDARTYPE
|LOCALE_RETURN_NUMBER
,
2791 (LPWSTR
)&cal_id
, sizeof(cal_id
)/sizeof(WCHAR
) ))
2794 switch (flags
& ~LOCALE_USE_CP_ACP
)
2797 case DATE_SHORTDATE
:
2798 lctype
= LOCALE_SSHORTDATE
;
2801 lctype
= LOCALE_SLONGDATE
;
2803 case DATE_YEARMONTH
:
2804 lctype
= LOCALE_SYEARMONTH
;
2807 FIXME( "unknown date format 0x%08x\n", flags
);
2808 SetLastError( ERROR_INVALID_PARAMETER
);
2812 lctype
|= flags
& LOCALE_USE_CP_ACP
;
2814 ret
= GetLocaleInfoW( lcid
, lctype
, buffer
, ARRAY_SIZE(buffer
) );
2816 ret
= GetLocaleInfoA( lcid
, lctype
, (char *)buffer
, sizeof(buffer
) );
2820 if (exex
) ((DATEFMT_ENUMPROCEXEX
)proc
)( buffer
, cal_id
, lparam
);
2821 else if (ex
) ((DATEFMT_ENUMPROCEXW
)proc
)( buffer
, cal_id
);
2822 else proc( buffer
);
2828 /******************************************************************************
2829 * Internal_EnumLanguageGroupLocales (kernelbase.@)
2831 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumLanguageGroupLocales( LANGGROUPLOCALE_ENUMPROCW proc
, LGRPID id
,
2832 DWORD flags
, LONG_PTR param
, BOOL unicode
)
2834 WCHAR name
[10], value
[10];
2835 DWORD name_len
, value_len
, type
, index
= 0, alt
= 0;
2839 if (!proc
|| id
< LGRPID_WESTERN_EUROPE
|| id
> LGRPID_ARMENIAN
)
2841 SetLastError( ERROR_INVALID_PARAMETER
);
2845 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
2846 if (RegOpenKeyExW( key
, L
"Alternate Sorts", 0, KEY_READ
, &altkey
)) altkey
= 0;
2850 name_len
= ARRAY_SIZE(name
);
2851 value_len
= sizeof(value
);
2852 if (RegEnumValueW( alt
? altkey
: key
, index
++, name
, &name_len
, NULL
,
2853 &type
, (BYTE
*)value
, &value_len
))
2859 if (type
!= REG_SZ
) continue;
2860 if (id
!= wcstoul( value
, NULL
, 16 )) continue;
2861 lcid
= wcstoul( name
, NULL
, 16 );
2865 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
2866 if (!((LANGGROUPLOCALE_ENUMPROCA
)proc
)( id
, lcid
, nameA
, param
)) break;
2868 else if (!proc( id
, lcid
, name
, param
)) break;
2870 RegCloseKey( altkey
);
2876 /***********************************************************************
2877 * Internal_EnumSystemCodePages (kernelbase.@)
2879 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumSystemCodePages( CODEPAGE_ENUMPROCW proc
, DWORD flags
,
2883 DWORD name_len
, type
, index
= 0;
2886 if (RegOpenKeyExW( nls_key
, L
"Codepage", 0, KEY_READ
, &key
)) return FALSE
;
2890 name_len
= ARRAY_SIZE(name
);
2891 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
2892 if (type
!= REG_SZ
) continue;
2893 if (!wcstoul( name
, NULL
, 10 )) continue;
2897 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
2898 if (!((CODEPAGE_ENUMPROCA
)proc
)( nameA
)) break;
2900 else if (!proc( name
)) break;
2907 /******************************************************************************
2908 * Internal_EnumSystemLanguageGroups (kernelbase.@)
2910 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumSystemLanguageGroups( LANGUAGEGROUP_ENUMPROCW proc
,
2911 DWORD flags
, LONG_PTR param
, BOOL unicode
)
2913 WCHAR name
[10], value
[10], descr
[80];
2914 DWORD name_len
, value_len
, type
, index
= 0;
2920 SetLastError( ERROR_INVALID_PARAMETER
);
2927 flags
= LGRPID_INSTALLED
;
2929 case LGRPID_INSTALLED
:
2930 case LGRPID_SUPPORTED
:
2933 SetLastError( ERROR_INVALID_FLAGS
);
2937 if (RegOpenKeyExW( nls_key
, L
"Language Groups", 0, KEY_READ
, &key
)) return FALSE
;
2941 name_len
= ARRAY_SIZE(name
);
2942 value_len
= sizeof(value
);
2943 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, (BYTE
*)value
, &value_len
)) break;
2944 if (type
!= REG_SZ
) continue;
2946 id
= wcstoul( name
, NULL
, 16 );
2948 if (!(flags
& LGRPID_SUPPORTED
) && !wcstoul( value
, NULL
, 10 )) continue;
2949 if (!LoadStringW( kernel32_handle
, 0x2000 + id
, descr
, ARRAY_SIZE(descr
) )) descr
[0] = 0;
2950 TRACE( "%p: %u %s %s %x %lx\n", proc
, id
, debugstr_w(name
), debugstr_w(descr
), flags
, param
);
2953 char nameA
[10], descrA
[80];
2954 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
2955 WideCharToMultiByte( CP_ACP
, 0, descr
, -1, descrA
, sizeof(descrA
), NULL
, NULL
);
2956 if (!((LANGUAGEGROUP_ENUMPROCA
)proc
)( id
, nameA
, descrA
, flags
, param
)) break;
2958 else if (!proc( id
, name
, descr
, flags
, param
)) break;
2965 /**************************************************************************
2966 * Internal_EnumTimeFormats (kernelbase.@)
2968 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumTimeFormats( TIMEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
,
2969 BOOL unicode
, BOOL ex
, LPARAM lparam
)
2977 SetLastError( ERROR_INVALID_PARAMETER
);
2980 switch (flags
& ~LOCALE_USE_CP_ACP
)
2983 lctype
= LOCALE_STIMEFORMAT
;
2985 case TIME_NOSECONDS
:
2986 lctype
= LOCALE_SSHORTTIME
;
2989 FIXME( "Unknown time format %x\n", flags
);
2990 SetLastError( ERROR_INVALID_PARAMETER
);
2994 lctype
|= flags
& LOCALE_USE_CP_ACP
;
2996 ret
= GetLocaleInfoW( lcid
, lctype
, buffer
, ARRAY_SIZE(buffer
) );
2998 ret
= GetLocaleInfoA( lcid
, lctype
, (char *)buffer
, sizeof(buffer
) );
3002 if (ex
) ((TIMEFMT_ENUMPROCEX
)proc
)( buffer
, lparam
);
3003 else proc( buffer
);
3009 /******************************************************************************
3010 * Internal_EnumUILanguages (kernelbase.@)
3012 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumUILanguages( UILANGUAGE_ENUMPROCW proc
, DWORD flags
,
3013 LONG_PTR param
, BOOL unicode
)
3016 DWORD name_len
, type
, index
= 0;
3021 SetLastError( ERROR_INVALID_PARAMETER
);
3024 if (flags
& ~MUI_LANGUAGE_ID
)
3026 SetLastError( ERROR_INVALID_FLAGS
);
3030 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3034 name_len
= ARRAY_SIZE(name
);
3035 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
3036 if (type
!= REG_SZ
) continue;
3037 if (!wcstoul( name
, NULL
, 16 )) continue;
3041 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
3042 if (!((UILANGUAGE_ENUMPROCA
)proc
)( nameA
, param
)) break;
3044 else if (!proc( name
, param
)) break;
3051 /******************************************************************************
3052 * CompareStringEx (kernelbase.@)
3054 INT WINAPI
CompareStringEx( const WCHAR
*locale
, DWORD flags
, const WCHAR
*str1
, int len1
,
3055 const WCHAR
*str2
, int len2
, NLSVERSIONINFO
*version
,
3056 void *reserved
, LPARAM handle
)
3058 DWORD supported_flags
= NORM_IGNORECASE
| NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
| SORT_STRINGSORT
|
3059 NORM_IGNOREKANATYPE
| NORM_IGNOREWIDTH
| LOCALE_USE_CP_ACP
;
3060 DWORD semistub_flags
= NORM_LINGUISTIC_CASING
| LINGUISTIC_IGNORECASE
| LINGUISTIC_IGNOREDIACRITIC
|
3061 SORT_DIGITSASNUMBERS
| 0x10000000;
3062 /* 0x10000000 is related to diacritics in Arabic, Japanese, and Hebrew */
3066 if (version
) FIXME( "unexpected version parameter\n" );
3067 if (reserved
) FIXME( "unexpected reserved value\n" );
3068 if (handle
) FIXME( "unexpected handle\n" );
3072 SetLastError( ERROR_INVALID_PARAMETER
);
3076 if (flags
& ~(supported_flags
| semistub_flags
))
3078 SetLastError( ERROR_INVALID_FLAGS
);
3082 if (flags
& semistub_flags
)
3084 if (!once
++) FIXME( "semi-stub behavior for flag(s) 0x%x\n", flags
& semistub_flags
);
3087 if (len1
< 0) len1
= lstrlenW(str1
);
3088 if (len2
< 0) len2
= lstrlenW(str2
);
3090 ret
= compare_weights( flags
, str1
, len1
, str2
, len2
, UNICODE_WEIGHT
);
3093 if (!(flags
& NORM_IGNORENONSPACE
))
3094 ret
= compare_weights( flags
, str1
, len1
, str2
, len2
, DIACRITIC_WEIGHT
);
3095 if (!ret
&& !(flags
& NORM_IGNORECASE
))
3096 ret
= compare_weights( flags
, str1
, len1
, str2
, len2
, CASE_WEIGHT
);
3098 if (!ret
) return CSTR_EQUAL
;
3099 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
3103 /******************************************************************************
3104 * CompareStringA (kernelbase.@)
3106 INT WINAPI DECLSPEC_HOTPATCH
CompareStringA( LCID lcid
, DWORD flags
, const char *str1
, int len1
,
3107 const char *str2
, int len2
)
3109 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
3110 WCHAR
*buf2W
= buf1W
+ 130;
3111 LPWSTR str1W
, str2W
;
3112 INT len1W
= 0, len2W
= 0, ret
;
3113 UINT locale_cp
= CP_ACP
;
3117 SetLastError( ERROR_INVALID_PARAMETER
);
3121 if (flags
& SORT_DIGITSASNUMBERS
)
3123 SetLastError( ERROR_INVALID_FLAGS
);
3127 if (len1
< 0) len1
= strlen(str1
);
3128 if (len2
< 0) len2
= strlen(str2
);
3130 locale_cp
= get_lcid_codepage( lcid
, flags
);
3133 if (len1
<= 130) len1W
= MultiByteToWideChar( locale_cp
, 0, str1
, len1
, buf1W
, 130 );
3134 if (len1W
) str1W
= buf1W
;
3137 len1W
= MultiByteToWideChar( locale_cp
, 0, str1
, len1
, NULL
, 0 );
3138 str1W
= HeapAlloc( GetProcessHeap(), 0, len1W
* sizeof(WCHAR
) );
3141 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3144 MultiByteToWideChar( locale_cp
, 0, str1
, len1
, str1W
, len1W
);
3155 if (len2
<= 130) len2W
= MultiByteToWideChar( locale_cp
, 0, str2
, len2
, buf2W
, 130 );
3156 if (len2W
) str2W
= buf2W
;
3159 len2W
= MultiByteToWideChar( locale_cp
, 0, str2
, len2
, NULL
, 0 );
3160 str2W
= HeapAlloc( GetProcessHeap(), 0, len2W
* sizeof(WCHAR
) );
3163 if (str1W
!= buf1W
) HeapFree( GetProcessHeap(), 0, str1W
);
3164 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3167 MultiByteToWideChar( locale_cp
, 0, str2
, len2
, str2W
, len2W
);
3176 ret
= CompareStringW( lcid
, flags
, str1W
, len1W
, str2W
, len2W
);
3178 if (str1W
!= buf1W
) HeapFree( GetProcessHeap(), 0, str1W
);
3179 if (str2W
!= buf2W
) HeapFree( GetProcessHeap(), 0, str2W
);
3184 /******************************************************************************
3185 * CompareStringW (kernelbase.@)
3187 INT WINAPI DECLSPEC_HOTPATCH
CompareStringW( LCID lcid
, DWORD flags
, const WCHAR
*str1
, int len1
,
3188 const WCHAR
*str2
, int len2
)
3190 return CompareStringEx( NULL
, flags
, str1
, len1
, str2
, len2
, NULL
, NULL
, 0 );
3194 /******************************************************************************
3195 * CompareStringOrdinal (kernelbase.@)
3197 INT WINAPI DECLSPEC_HOTPATCH
CompareStringOrdinal( const WCHAR
*str1
, INT len1
,
3198 const WCHAR
*str2
, INT len2
, BOOL ignore_case
)
3204 SetLastError( ERROR_INVALID_PARAMETER
);
3207 if (len1
< 0) len1
= lstrlenW( str1
);
3208 if (len2
< 0) len2
= lstrlenW( str2
);
3210 ret
= RtlCompareUnicodeStrings( str1
, len1
, str2
, len2
, ignore_case
);
3211 if (ret
< 0) return CSTR_LESS_THAN
;
3212 if (ret
> 0) return CSTR_GREATER_THAN
;
3217 /******************************************************************************
3218 * ConvertDefaultLocale (kernelbase.@)
3220 LCID WINAPI DECLSPEC_HOTPATCH
ConvertDefaultLocale( LCID lcid
)
3224 case LOCALE_INVARIANT
:
3225 return lcid
; /* keep as-is */
3226 case LOCALE_SYSTEM_DEFAULT
:
3227 return GetSystemDefaultLCID();
3228 case LOCALE_USER_DEFAULT
:
3229 case LOCALE_NEUTRAL
:
3230 return GetUserDefaultLCID();
3231 case MAKELANGID( LANG_CHINESE
, SUBLANG_NEUTRAL
):
3232 case MAKELANGID( LANG_CHINESE
, 0x1e ):
3233 return MAKELANGID( LANG_CHINESE
, SUBLANG_CHINESE_SIMPLIFIED
);
3234 case MAKELANGID( LANG_CHINESE
, 0x1f ):
3235 return MAKELANGID( LANG_CHINESE
, SUBLANG_CHINESE_HONGKONG
);
3236 case LANG_SERBIAN_NEUTRAL
:
3237 return MAKELANGID( LANG_SERBIAN
, SUBLANG_SERBIAN_SERBIA_LATIN
);
3238 case MAKELANGID( LANG_SPANISH
, SUBLANG_NEUTRAL
):
3239 return MAKELANGID( LANG_SPANISH
, SUBLANG_SPANISH_MODERN
);
3240 case MAKELANGID( LANG_IRISH
, SUBLANG_NEUTRAL
):
3241 return MAKELANGID( LANG_IRISH
, SUBLANG_IRISH_IRELAND
);
3242 case MAKELANGID( LANG_BENGALI
, SUBLANG_NEUTRAL
):
3243 return MAKELANGID( LANG_BENGALI
, SUBLANG_BENGALI_BANGLADESH
);
3244 case MAKELANGID( LANG_SINDHI
, SUBLANG_NEUTRAL
):
3245 return MAKELANGID( LANG_SINDHI
, SUBLANG_SINDHI_AFGHANISTAN
);
3246 case MAKELANGID( LANG_INUKTITUT
, SUBLANG_NEUTRAL
):
3247 return MAKELANGID( LANG_INUKTITUT
, SUBLANG_INUKTITUT_CANADA_LATIN
);
3248 case MAKELANGID( LANG_TAMAZIGHT
, SUBLANG_NEUTRAL
):
3249 return MAKELANGID( LANG_TAMAZIGHT
, SUBLANG_TAMAZIGHT_ALGERIA_LATIN
);
3250 case MAKELANGID( LANG_FULAH
, SUBLANG_NEUTRAL
):
3251 return MAKELANGID( LANG_FULAH
, SUBLANG_FULAH_SENEGAL
);
3252 case MAKELANGID( LANG_TIGRINYA
, SUBLANG_NEUTRAL
):
3253 return MAKELANGID( LANG_TIGRINYA
, SUBLANG_TIGRINYA_ERITREA
);
3255 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
3256 if (SUBLANGID(lcid
) == SUBLANG_NEUTRAL
&& SORTIDFROMLCID(lcid
) == SORT_DEFAULT
)
3257 lcid
= MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_DEFAULT
);
3264 /******************************************************************************
3265 * EnumCalendarInfoW (kernelbase.@)
3267 BOOL WINAPI DECLSPEC_HOTPATCH
EnumCalendarInfoW( CALINFO_ENUMPROCW proc
, LCID lcid
,
3268 CALID id
, CALTYPE type
)
3270 return Internal_EnumCalendarInfo( proc
, lcid
, id
, type
, TRUE
, FALSE
, FALSE
, 0 );
3274 /******************************************************************************
3275 * EnumCalendarInfoExW (kernelbase.@)
3277 BOOL WINAPI DECLSPEC_HOTPATCH
EnumCalendarInfoExW( CALINFO_ENUMPROCEXW proc
, LCID lcid
,
3278 CALID id
, CALTYPE type
)
3280 return Internal_EnumCalendarInfo( (CALINFO_ENUMPROCW
)proc
, lcid
, id
, type
, TRUE
, TRUE
, FALSE
, 0 );
3283 /******************************************************************************
3284 * EnumCalendarInfoExEx (kernelbase.@)
3286 BOOL WINAPI DECLSPEC_HOTPATCH
EnumCalendarInfoExEx( CALINFO_ENUMPROCEXEX proc
, LPCWSTR locale
, CALID id
,
3287 LPCWSTR reserved
, CALTYPE type
, LPARAM lparam
)
3289 LCID lcid
= LocaleNameToLCID( locale
, 0 );
3290 return Internal_EnumCalendarInfo( (CALINFO_ENUMPROCW
)proc
, lcid
, id
, type
, TRUE
, TRUE
, TRUE
, lparam
);
3294 /**************************************************************************
3295 * EnumDateFormatsW (kernelbase.@)
3297 BOOL WINAPI DECLSPEC_HOTPATCH
EnumDateFormatsW( DATEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
)
3299 return Internal_EnumDateFormats( proc
, lcid
, flags
, TRUE
, FALSE
, FALSE
, 0 );
3303 /**************************************************************************
3304 * EnumDateFormatsExW (kernelbase.@)
3306 BOOL WINAPI DECLSPEC_HOTPATCH
EnumDateFormatsExW( DATEFMT_ENUMPROCEXW proc
, LCID lcid
, DWORD flags
)
3308 return Internal_EnumDateFormats( (DATEFMT_ENUMPROCW
)proc
, lcid
, flags
, TRUE
, TRUE
, FALSE
, 0 );
3312 /**************************************************************************
3313 * EnumDateFormatsExEx (kernelbase.@)
3315 BOOL WINAPI DECLSPEC_HOTPATCH
EnumDateFormatsExEx( DATEFMT_ENUMPROCEXEX proc
, const WCHAR
*locale
,
3316 DWORD flags
, LPARAM lparam
)
3318 LCID lcid
= LocaleNameToLCID( locale
, 0 );
3319 return Internal_EnumDateFormats( (DATEFMT_ENUMPROCW
)proc
, lcid
, flags
, TRUE
, TRUE
, TRUE
, lparam
);
3324 /******************************************************************************
3325 * EnumDynamicTimeZoneInformation (kernelbase.@)
3327 DWORD WINAPI DECLSPEC_HOTPATCH
EnumDynamicTimeZoneInformation( DWORD index
,
3328 DYNAMIC_TIME_ZONE_INFORMATION
*info
)
3330 DYNAMIC_TIME_ZONE_INFORMATION tz
;
3334 if (!info
) return ERROR_INVALID_PARAMETER
;
3336 size
= ARRAY_SIZE(tz
.TimeZoneKeyName
);
3337 ret
= RegEnumKeyExW( tz_key
, index
, tz
.TimeZoneKeyName
, &size
, NULL
, NULL
, NULL
, NULL
);
3338 if (ret
) return ret
;
3340 tz
.DynamicDaylightTimeDisabled
= TRUE
;
3341 if (!GetTimeZoneInformationForYear( 0, &tz
, (TIME_ZONE_INFORMATION
*)info
)) return GetLastError();
3343 lstrcpyW( info
->TimeZoneKeyName
, tz
.TimeZoneKeyName
);
3344 info
->DynamicDaylightTimeDisabled
= FALSE
;
3349 /******************************************************************************
3350 * EnumLanguageGroupLocalesW (kernelbase.@)
3352 BOOL WINAPI DECLSPEC_HOTPATCH
EnumLanguageGroupLocalesW( LANGGROUPLOCALE_ENUMPROCW proc
, LGRPID id
,
3353 DWORD flags
, LONG_PTR param
)
3355 return Internal_EnumLanguageGroupLocales( proc
, id
, flags
, param
, TRUE
);
3359 /******************************************************************************
3360 * EnumUILanguagesW (kernelbase.@)
3362 BOOL WINAPI DECLSPEC_HOTPATCH
EnumUILanguagesW( UILANGUAGE_ENUMPROCW proc
, DWORD flags
, LONG_PTR param
)
3364 return Internal_EnumUILanguages( proc
, flags
, param
, TRUE
);
3368 /***********************************************************************
3369 * EnumSystemCodePagesW (kernelbase.@)
3371 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW proc
, DWORD flags
)
3373 return Internal_EnumSystemCodePages( proc
, flags
, TRUE
);
3377 /******************************************************************************
3378 * EnumSystemGeoID (kernelbase.@)
3380 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemGeoID( GEOCLASS
class, GEOID parent
, GEO_ENUMPROC proc
)
3384 TRACE( "(%d, %d, %p)\n", class, parent
, proc
);
3388 SetLastError( ERROR_INVALID_PARAMETER
);
3391 if (class != GEOCLASS_NATION
&& class != GEOCLASS_REGION
&& class != GEOCLASS_ALL
)
3393 SetLastError( ERROR_INVALID_FLAGS
);
3397 for (i
= 0; i
< ARRAY_SIZE(geoinfodata
); i
++)
3399 const struct geoinfo
*ptr
= &geoinfodata
[i
];
3401 if (class == GEOCLASS_NATION
&& (ptr
->kind
!= LOCATION_NATION
)) continue;
3402 /* LOCATION_BOTH counts as region */
3403 if (class == GEOCLASS_REGION
&& (ptr
->kind
== LOCATION_NATION
)) continue;
3404 if (parent
&& ptr
->parent
!= parent
) continue;
3405 if (!proc( ptr
->id
)) break;
3411 /******************************************************************************
3412 * EnumSystemLanguageGroupsW (kernelbase.@)
3414 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLanguageGroupsW( LANGUAGEGROUP_ENUMPROCW proc
,
3415 DWORD flags
, LONG_PTR param
)
3417 return Internal_EnumSystemLanguageGroups( proc
, flags
, param
, TRUE
);
3421 /******************************************************************************
3422 * EnumSystemLocalesA (kernelbase.@)
3424 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLocalesA( LOCALE_ENUMPROCA proc
, DWORD flags
)
3427 DWORD name_len
, type
, index
= 0;
3430 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3434 name_len
= ARRAY_SIZE(name
);
3435 if (RegEnumValueA( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
3436 if (type
!= REG_SZ
) continue;
3437 if (!strtoul( name
, NULL
, 16 )) continue;
3438 if (!proc( name
)) break;
3445 /******************************************************************************
3446 * EnumSystemLocalesW (kernelbase.@)
3448 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLocalesW( LOCALE_ENUMPROCW proc
, DWORD flags
)
3451 DWORD name_len
, type
, index
= 0;
3454 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3458 name_len
= ARRAY_SIZE(name
);
3459 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
3460 if (type
!= REG_SZ
) continue;
3461 if (!wcstoul( name
, NULL
, 16 )) continue;
3462 if (!proc( name
)) break;
3469 /******************************************************************************
3470 * EnumSystemLocalesEx (kernelbase.@)
3472 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLocalesEx( LOCALE_ENUMPROCEX proc
, DWORD wanted_flags
,
3473 LPARAM param
, void *reserved
)
3475 WCHAR buffer
[256], name
[10];
3476 DWORD name_len
, type
, neutral
, flags
, index
= 0, alt
= 0;
3482 SetLastError( ERROR_INVALID_PARAMETER
);
3486 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3487 if (RegOpenKeyExW( key
, L
"Alternate Sorts", 0, KEY_READ
, &altkey
)) altkey
= 0;
3491 name_len
= ARRAY_SIZE(name
);
3492 if (RegEnumValueW( alt
? altkey
: key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
))
3498 if (type
!= REG_SZ
) continue;
3499 if (!(lcid
= wcstoul( name
, NULL
, 16 ))) continue;
3501 GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, buffer
, ARRAY_SIZE( buffer
));
3502 if (!GetLocaleInfoW( lcid
, LOCALE_INEUTRAL
| LOCALE_NOUSEROVERRIDE
| LOCALE_RETURN_NUMBER
,
3503 (LPWSTR
)&neutral
, sizeof(neutral
) / sizeof(WCHAR
) ))
3507 flags
= LOCALE_ALTERNATE_SORTS
;
3509 flags
= LOCALE_WINDOWS
| (neutral
? LOCALE_NEUTRALDATA
: LOCALE_SPECIFICDATA
);
3511 if (wanted_flags
&& !(flags
& wanted_flags
)) continue;
3512 if (!proc( buffer
, flags
, param
)) break;
3514 RegCloseKey( altkey
);
3520 /**************************************************************************
3521 * EnumTimeFormatsW (kernelbase.@)
3523 BOOL WINAPI DECLSPEC_HOTPATCH
EnumTimeFormatsW( TIMEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
)
3525 return Internal_EnumTimeFormats( proc
, lcid
, flags
, TRUE
, FALSE
, 0 );
3529 /**************************************************************************
3530 * EnumTimeFormatsEx (kernelbase.@)
3532 BOOL WINAPI DECLSPEC_HOTPATCH
EnumTimeFormatsEx( TIMEFMT_ENUMPROCEX proc
, const WCHAR
*locale
,
3533 DWORD flags
, LPARAM lparam
)
3535 LCID lcid
= LocaleNameToLCID( locale
, 0 );
3536 return Internal_EnumTimeFormats( (TIMEFMT_ENUMPROCW
)proc
, lcid
, flags
, TRUE
, TRUE
, lparam
);
3540 /**************************************************************************
3541 * FindNLSString (kernelbase.@)
3543 INT WINAPI DECLSPEC_HOTPATCH
FindNLSString( LCID lcid
, DWORD flags
, const WCHAR
*src
,
3544 int srclen
, const WCHAR
*value
, int valuelen
, int *found
)
3546 WCHAR locale
[LOCALE_NAME_MAX_LENGTH
];
3548 LCIDToLocaleName( lcid
, locale
, ARRAY_SIZE(locale
), 0 );
3549 return FindNLSStringEx( locale
, flags
, src
, srclen
, value
, valuelen
, found
, NULL
, NULL
, 0 );
3553 /**************************************************************************
3554 * FindNLSStringEx (kernelbase.@)
3556 INT WINAPI DECLSPEC_HOTPATCH
FindNLSStringEx( const WCHAR
*locale
, DWORD flags
, const WCHAR
*src
,
3557 int srclen
, const WCHAR
*value
, int valuelen
, int *found
,
3558 NLSVERSIONINFO
*version
, void *reserved
, LPARAM handle
)
3560 /* FIXME: this function should normalize strings before calling CompareStringEx() */
3562 int offset
, inc
, count
;
3564 TRACE( "%s %x %s %d %s %d %p %p %p %ld\n", wine_dbgstr_w(locale
), flags
,
3565 wine_dbgstr_w(src
), srclen
, wine_dbgstr_w(value
), valuelen
, found
,
3566 version
, reserved
, handle
);
3568 if (version
|| reserved
|| handle
|| !IsValidLocaleName(locale
) ||
3569 !src
|| !srclen
|| srclen
< -1 || !value
|| !valuelen
|| valuelen
< -1)
3571 SetLastError( ERROR_INVALID_PARAMETER
);
3574 if (srclen
== -1) srclen
= lstrlenW(src
);
3575 if (valuelen
== -1) valuelen
= lstrlenW(value
);
3578 if (srclen
< 0) return -1;
3580 mask
= flags
& ~(FIND_FROMSTART
| FIND_FROMEND
| FIND_STARTSWITH
| FIND_ENDSWITH
);
3581 count
= flags
& (FIND_FROMSTART
| FIND_FROMEND
) ? srclen
+ 1 : 1;
3582 offset
= flags
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 0 : srclen
;
3583 inc
= flags
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 1 : -1;
3586 if (CompareStringEx( locale
, mask
, src
+ offset
, valuelen
,
3587 value
, valuelen
, NULL
, NULL
, 0 ) == CSTR_EQUAL
)
3589 if (found
) *found
= valuelen
;
3598 /******************************************************************************
3599 * FindStringOrdinal (kernelbase.@)
3601 INT WINAPI DECLSPEC_HOTPATCH
FindStringOrdinal( DWORD flag
, const WCHAR
*src
, INT src_size
,
3602 const WCHAR
*val
, INT val_size
, BOOL ignore_case
)
3604 INT offset
, inc
, count
;
3606 TRACE( "%#x %s %d %s %d %d\n", flag
, wine_dbgstr_w(src
), src_size
,
3607 wine_dbgstr_w(val
), val_size
, ignore_case
);
3611 SetLastError( ERROR_INVALID_PARAMETER
);
3615 if (flag
!= FIND_FROMSTART
&& flag
!= FIND_FROMEND
&& flag
!= FIND_STARTSWITH
&& flag
!= FIND_ENDSWITH
)
3617 SetLastError( ERROR_INVALID_FLAGS
);
3621 if (src_size
== -1) src_size
= lstrlenW( src
);
3622 if (val_size
== -1) val_size
= lstrlenW( val
);
3624 SetLastError( ERROR_SUCCESS
);
3625 src_size
-= val_size
;
3626 if (src_size
< 0) return -1;
3628 count
= flag
& (FIND_FROMSTART
| FIND_FROMEND
) ? src_size
+ 1 : 1;
3629 offset
= flag
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 0 : src_size
;
3630 inc
= flag
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 1 : -1;
3633 if (CompareStringOrdinal( src
+ offset
, val_size
, val
, val_size
, ignore_case
) == CSTR_EQUAL
)
3641 /******************************************************************************
3642 * FoldStringW (kernelbase.@)
3644 INT WINAPI DECLSPEC_HOTPATCH
FoldStringW( DWORD flags
, LPCWSTR src
, INT srclen
, LPWSTR dst
, INT dstlen
)
3650 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
3652 SetLastError( ERROR_INVALID_PARAMETER
);
3655 if (srclen
== -1) srclen
= lstrlenW(src
) + 1;
3657 if (!dstlen
&& (flags
& (MAP_PRECOMPOSED
| MAP_FOLDCZONE
| MAP_COMPOSITE
)))
3660 if (!(buf
= RtlAllocateHeap( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
3662 SetLastError( ERROR_OUTOFMEMORY
);
3669 status
= fold_string( flags
, src
, srclen
, buf
, &len
);
3670 if (buf
!= dst
) RtlFreeHeap( GetProcessHeap(), 0, buf
);
3671 if (status
!= STATUS_BUFFER_TOO_SMALL
) break;
3672 if (!(buf
= RtlAllocateHeap( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
3674 SetLastError( ERROR_OUTOFMEMORY
);
3678 if (status
== STATUS_INVALID_PARAMETER_1
)
3680 SetLastError( ERROR_INVALID_FLAGS
);
3683 if (!set_ntstatus( status
)) return 0;
3685 if (dstlen
&& dstlen
< len
) SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3690 static const WCHAR
*get_message( DWORD flags
, const void *src
, UINT id
, UINT lang
,
3691 BOOL ansi
, WCHAR
**buffer
)
3695 if (!(flags
& FORMAT_MESSAGE_FROM_STRING
))
3697 const MESSAGE_RESOURCE_ENTRY
*entry
;
3698 NTSTATUS status
= STATUS_INVALID_PARAMETER
;
3700 if (flags
& FORMAT_MESSAGE_FROM_HMODULE
)
3702 HMODULE module
= (HMODULE
)src
;
3703 if (!module
) module
= GetModuleHandleW( 0 );
3704 status
= RtlFindMessage( module
, RT_MESSAGETABLE
, lang
, id
, &entry
);
3706 if (status
&& (flags
& FORMAT_MESSAGE_FROM_SYSTEM
))
3708 /* Fold win32 hresult to its embedded error code. */
3709 if (HRESULT_SEVERITY(id
) == SEVERITY_ERROR
&& HRESULT_FACILITY(id
) == FACILITY_WIN32
)
3710 id
= HRESULT_CODE( id
);
3711 status
= RtlFindMessage( kernel32_handle
, RT_MESSAGETABLE
, lang
, id
, &entry
);
3713 if (!set_ntstatus( status
)) return NULL
;
3716 ansi
= !(entry
->Flags
& MESSAGE_RESOURCE_UNICODE
);
3719 if (!ansi
) return src
;
3720 len
= MultiByteToWideChar( CP_ACP
, 0, src
, -1, NULL
, 0 );
3721 if (!(*buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return NULL
;
3722 MultiByteToWideChar( CP_ACP
, 0, src
, -1, *buffer
, len
);
3727 /***********************************************************************
3728 * FormatMessageA (kernelbase.@)
3730 DWORD WINAPI DECLSPEC_HOTPATCH
FormatMessageA( DWORD flags
, const void *source
, DWORD msgid
, DWORD langid
,
3731 char *buffer
, DWORD size
, __ms_va_list
*args
)
3734 ULONG len
, retsize
= 0;
3735 ULONG width
= (flags
& FORMAT_MESSAGE_MAX_WIDTH_MASK
);
3737 WCHAR
*result
, *message
= NULL
;
3740 TRACE( "(0x%x,%p,%#x,0x%x,%p,%u,%p)\n", flags
, source
, msgid
, langid
, buffer
, size
, args
);
3742 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
)
3746 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3749 *(char **)buffer
= NULL
;
3753 SetLastError( ERROR_INVALID_PARAMETER
);
3757 if (width
== 0xff) width
= ~0u;
3759 if (!(src
= get_message( flags
, source
, msgid
, langid
, TRUE
, &message
))) return 0;
3761 if (!(result
= HeapAlloc( GetProcessHeap(), 0, 65536 )))
3762 status
= STATUS_NO_MEMORY
;
3764 status
= RtlFormatMessage( src
, width
, !!(flags
& FORMAT_MESSAGE_IGNORE_INSERTS
),
3765 TRUE
, !!(flags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
), args
,
3766 result
, 65536, &retsize
);
3768 HeapFree( GetProcessHeap(), 0, message
);
3770 if (status
== STATUS_BUFFER_OVERFLOW
)
3772 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3775 if (!set_ntstatus( status
)) goto done
;
3777 len
= WideCharToMultiByte( CP_ACP
, 0, result
, retsize
/ sizeof(WCHAR
), NULL
, 0, NULL
, NULL
);
3780 SetLastError( ERROR_NO_WORK_DONE
);
3784 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
)
3786 char *buf
= LocalAlloc( LMEM_ZEROINIT
, max( size
, len
));
3789 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3792 *(char **)buffer
= buf
;
3793 WideCharToMultiByte( CP_ACP
, 0, result
, retsize
/ sizeof(WCHAR
), buf
, max( size
, len
), NULL
, NULL
);
3795 else if (len
> size
)
3797 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3800 else WideCharToMultiByte( CP_ACP
, 0, result
, retsize
/ sizeof(WCHAR
), buffer
, size
, NULL
, NULL
);
3805 HeapFree( GetProcessHeap(), 0, result
);
3810 /***********************************************************************
3811 * FormatMessageW (kernelbase.@)
3813 DWORD WINAPI DECLSPEC_HOTPATCH
FormatMessageW( DWORD flags
, const void *source
, DWORD msgid
, DWORD langid
,
3814 WCHAR
*buffer
, DWORD size
, __ms_va_list
*args
)
3817 ULONG width
= (flags
& FORMAT_MESSAGE_MAX_WIDTH_MASK
);
3819 WCHAR
*message
= NULL
;
3822 TRACE( "(0x%x,%p,%#x,0x%x,%p,%u,%p)\n", flags
, source
, msgid
, langid
, buffer
, size
, args
);
3826 SetLastError( ERROR_INVALID_PARAMETER
);
3830 if (width
== 0xff) width
= ~0u;
3832 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
) *(LPWSTR
*)buffer
= NULL
;
3834 if (!(src
= get_message( flags
, source
, msgid
, langid
, FALSE
, &message
))) return 0;
3836 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
)
3839 ULONG alloc
= max( size
* sizeof(WCHAR
), 65536 );
3843 if (!(result
= HeapAlloc( GetProcessHeap(), 0, alloc
)))
3845 status
= STATUS_NO_MEMORY
;
3848 status
= RtlFormatMessage( src
, width
, !!(flags
& FORMAT_MESSAGE_IGNORE_INSERTS
),
3849 FALSE
, !!(flags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
), args
,
3850 result
, alloc
, &retsize
);
3853 if (retsize
<= sizeof(WCHAR
)) HeapFree( GetProcessHeap(), 0, result
);
3854 else *(WCHAR
**)buffer
= HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY
,
3855 result
, max( retsize
, size
* sizeof(WCHAR
) ));
3858 HeapFree( GetProcessHeap(), 0, result
);
3859 if (status
!= STATUS_BUFFER_OVERFLOW
) break;
3863 else status
= RtlFormatMessage( src
, width
, !!(flags
& FORMAT_MESSAGE_IGNORE_INSERTS
),
3864 FALSE
, !!(flags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
), args
,
3865 buffer
, size
* sizeof(WCHAR
), &retsize
);
3867 HeapFree( GetProcessHeap(), 0, message
);
3869 if (status
== STATUS_BUFFER_OVERFLOW
)
3871 if (size
) buffer
[size
- 1] = 0;
3872 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3875 if (!set_ntstatus( status
)) return 0;
3876 if (retsize
<= sizeof(WCHAR
)) SetLastError( ERROR_NO_WORK_DONE
);
3877 return retsize
/ sizeof(WCHAR
) - 1;
3881 /******************************************************************************
3882 * GetACP (kernelbase.@)
3884 UINT WINAPI
GetACP(void)
3886 return nls_info
.AnsiTableInfo
.CodePage
;
3890 /***********************************************************************
3891 * GetCPInfo (kernelbase.@)
3893 BOOL WINAPI DECLSPEC_HOTPATCH
GetCPInfo( UINT codepage
, CPINFO
*cpinfo
)
3895 const CPTABLEINFO
*table
;
3899 SetLastError( ERROR_INVALID_PARAMETER
);
3906 cpinfo
->DefaultChar
[0] = 0x3f;
3907 cpinfo
->DefaultChar
[1] = 0;
3908 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
3909 cpinfo
->MaxCharSize
= (codepage
== CP_UTF7
) ? 5 : 4;
3912 if (!(table
= get_codepage_table( codepage
))) return FALSE
;
3913 cpinfo
->MaxCharSize
= table
->MaximumCharacterSize
;
3914 memcpy( cpinfo
->DefaultChar
, &table
->DefaultChar
, sizeof(cpinfo
->DefaultChar
) );
3915 memcpy( cpinfo
->LeadByte
, table
->LeadByte
, sizeof(cpinfo
->LeadByte
) );
3922 /***********************************************************************
3923 * GetCPInfoExW (kernelbase.@)
3925 BOOL WINAPI
GetCPInfoExW( UINT codepage
, DWORD flags
, CPINFOEXW
*cpinfo
)
3927 const CPTABLEINFO
*table
;
3932 SetLastError( ERROR_INVALID_PARAMETER
);
3938 cpinfo
->DefaultChar
[0] = 0x3f;
3939 cpinfo
->DefaultChar
[1] = 0;
3940 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
3941 cpinfo
->MaxCharSize
= 5;
3942 cpinfo
->CodePage
= CP_UTF7
;
3943 cpinfo
->UnicodeDefaultChar
= 0x3f;
3946 cpinfo
->DefaultChar
[0] = 0x3f;
3947 cpinfo
->DefaultChar
[1] = 0;
3948 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
3949 cpinfo
->MaxCharSize
= 4;
3950 cpinfo
->CodePage
= CP_UTF8
;
3951 cpinfo
->UnicodeDefaultChar
= 0x3f;
3954 if (!(table
= get_codepage_table( codepage
))) return FALSE
;
3955 cpinfo
->MaxCharSize
= table
->MaximumCharacterSize
;
3956 memcpy( cpinfo
->DefaultChar
, &table
->DefaultChar
, sizeof(cpinfo
->DefaultChar
) );
3957 memcpy( cpinfo
->LeadByte
, table
->LeadByte
, sizeof(cpinfo
->LeadByte
) );
3958 cpinfo
->CodePage
= table
->CodePage
;
3959 cpinfo
->UnicodeDefaultChar
= table
->UniDefaultChar
;
3964 max
= ARRAY_SIZE(codepage_names
) - 1;
3965 cpinfo
->CodePageName
[0] = 0;
3968 pos
= (min
+ max
) / 2;
3969 if (codepage_names
[pos
].cp
< cpinfo
->CodePage
) min
= pos
+ 1;
3970 else if (codepage_names
[pos
].cp
> cpinfo
->CodePage
) max
= pos
- 1;
3973 wcscpy( cpinfo
->CodePageName
, codepage_names
[pos
].name
);
3981 /***********************************************************************
3982 * GetCalendarInfoW (kernelbase.@)
3984 INT WINAPI DECLSPEC_HOTPATCH
GetCalendarInfoW( LCID lcid
, CALID calendar
, CALTYPE type
,
3985 WCHAR
*data
, INT count
, DWORD
*value
)
3987 static const LCTYPE lctype_map
[] =
3990 0, /* CAL_ICALINTVALUE */
3991 0, /* CAL_SCALNAME */
3992 0, /* CAL_IYEAROFFSETRANGE */
3993 0, /* CAL_SERASTRING */
4003 LOCALE_SABBREVDAYNAME1
,
4004 LOCALE_SABBREVDAYNAME2
,
4005 LOCALE_SABBREVDAYNAME3
,
4006 LOCALE_SABBREVDAYNAME4
,
4007 LOCALE_SABBREVDAYNAME5
,
4008 LOCALE_SABBREVDAYNAME6
,
4009 LOCALE_SABBREVDAYNAME7
,
4019 LOCALE_SMONTHNAME10
,
4020 LOCALE_SMONTHNAME11
,
4021 LOCALE_SMONTHNAME12
,
4022 LOCALE_SMONTHNAME13
,
4023 LOCALE_SABBREVMONTHNAME1
,
4024 LOCALE_SABBREVMONTHNAME2
,
4025 LOCALE_SABBREVMONTHNAME3
,
4026 LOCALE_SABBREVMONTHNAME4
,
4027 LOCALE_SABBREVMONTHNAME5
,
4028 LOCALE_SABBREVMONTHNAME6
,
4029 LOCALE_SABBREVMONTHNAME7
,
4030 LOCALE_SABBREVMONTHNAME8
,
4031 LOCALE_SABBREVMONTHNAME9
,
4032 LOCALE_SABBREVMONTHNAME10
,
4033 LOCALE_SABBREVMONTHNAME11
,
4034 LOCALE_SABBREVMONTHNAME12
,
4035 LOCALE_SABBREVMONTHNAME13
,
4037 0, /* CAL_ITWODIGITYEARMAX */
4038 LOCALE_SSHORTESTDAYNAME1
,
4039 LOCALE_SSHORTESTDAYNAME2
,
4040 LOCALE_SSHORTESTDAYNAME3
,
4041 LOCALE_SSHORTESTDAYNAME4
,
4042 LOCALE_SSHORTESTDAYNAME5
,
4043 LOCALE_SSHORTESTDAYNAME6
,
4044 LOCALE_SSHORTESTDAYNAME7
,
4046 0, /* CAL_SABBREVERASTRING */
4049 CALTYPE calinfo
= type
& 0xffff;
4051 if (type
& CAL_NOUSEROVERRIDE
) FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
4052 if (type
& CAL_USE_CP_ACP
) FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
4054 if ((type
& CAL_RETURN_NUMBER
) && !value
)
4056 SetLastError( ERROR_INVALID_PARAMETER
);
4060 if (type
& CAL_RETURN_GENITIVE_NAMES
) flags
|= LOCALE_RETURN_GENITIVE_NAMES
;
4064 case CAL_ICALINTVALUE
:
4065 if (type
& CAL_RETURN_NUMBER
)
4066 return GetLocaleInfoW( lcid
, LOCALE_RETURN_NUMBER
| LOCALE_ICALENDARTYPE
,
4067 (WCHAR
*)value
, sizeof(*value
) / sizeof(WCHAR
) );
4068 return GetLocaleInfoW( lcid
, LOCALE_ICALENDARTYPE
, data
, count
);
4071 FIXME( "Unimplemented caltype %d\n", calinfo
);
4072 if (data
) *data
= 0;
4075 case CAL_IYEAROFFSETRANGE
:
4076 case CAL_SERASTRING
:
4077 case CAL_SABBREVERASTRING
:
4078 FIXME( "Unimplemented caltype %d\n", calinfo
);
4081 case CAL_SSHORTDATE
:
4090 case CAL_SABBREVDAYNAME1
:
4091 case CAL_SABBREVDAYNAME2
:
4092 case CAL_SABBREVDAYNAME3
:
4093 case CAL_SABBREVDAYNAME4
:
4094 case CAL_SABBREVDAYNAME5
:
4095 case CAL_SABBREVDAYNAME6
:
4096 case CAL_SABBREVDAYNAME7
:
4097 case CAL_SMONTHNAME1
:
4098 case CAL_SMONTHNAME2
:
4099 case CAL_SMONTHNAME3
:
4100 case CAL_SMONTHNAME4
:
4101 case CAL_SMONTHNAME5
:
4102 case CAL_SMONTHNAME6
:
4103 case CAL_SMONTHNAME7
:
4104 case CAL_SMONTHNAME8
:
4105 case CAL_SMONTHNAME9
:
4106 case CAL_SMONTHNAME10
:
4107 case CAL_SMONTHNAME11
:
4108 case CAL_SMONTHNAME12
:
4109 case CAL_SMONTHNAME13
:
4110 case CAL_SABBREVMONTHNAME1
:
4111 case CAL_SABBREVMONTHNAME2
:
4112 case CAL_SABBREVMONTHNAME3
:
4113 case CAL_SABBREVMONTHNAME4
:
4114 case CAL_SABBREVMONTHNAME5
:
4115 case CAL_SABBREVMONTHNAME6
:
4116 case CAL_SABBREVMONTHNAME7
:
4117 case CAL_SABBREVMONTHNAME8
:
4118 case CAL_SABBREVMONTHNAME9
:
4119 case CAL_SABBREVMONTHNAME10
:
4120 case CAL_SABBREVMONTHNAME11
:
4121 case CAL_SABBREVMONTHNAME12
:
4122 case CAL_SABBREVMONTHNAME13
:
4124 case CAL_SYEARMONTH
:
4125 case CAL_SSHORTESTDAYNAME1
:
4126 case CAL_SSHORTESTDAYNAME2
:
4127 case CAL_SSHORTESTDAYNAME3
:
4128 case CAL_SSHORTESTDAYNAME4
:
4129 case CAL_SSHORTESTDAYNAME5
:
4130 case CAL_SSHORTESTDAYNAME6
:
4131 case CAL_SSHORTESTDAYNAME7
:
4132 return GetLocaleInfoW( lcid
, lctype_map
[calinfo
] | flags
, data
, count
);
4134 case CAL_ITWODIGITYEARMAX
:
4135 if (type
& CAL_RETURN_NUMBER
)
4137 *value
= CALINFO_MAX_YEAR
;
4138 return sizeof(DWORD
) / sizeof(WCHAR
);
4143 int ret
= swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%u", CALINFO_MAX_YEAR
) + 1;
4144 if (!data
) return ret
;
4147 lstrcpyW( data
, buffer
);
4150 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4155 FIXME( "Unknown caltype %d\n", calinfo
);
4156 SetLastError( ERROR_INVALID_FLAGS
);
4163 /***********************************************************************
4164 * GetCalendarInfoEx (kernelbase.@)
4166 INT WINAPI DECLSPEC_HOTPATCH
GetCalendarInfoEx( const WCHAR
*locale
, CALID calendar
, const WCHAR
*reserved
,
4167 CALTYPE type
, WCHAR
*data
, INT count
, DWORD
*value
)
4169 LCID lcid
= LocaleNameToLCID( locale
, 0 );
4170 return GetCalendarInfoW( lcid
, calendar
, type
, data
, count
, value
);
4173 static CRITICAL_SECTION tzname_section
;
4174 static CRITICAL_SECTION_DEBUG tzname_section_debug
=
4176 0, 0, &tzname_section
,
4177 { &tzname_section_debug
.ProcessLocksList
, &tzname_section_debug
.ProcessLocksList
},
4178 0, 0, { (DWORD_PTR
)(__FILE__
": tzname_section") }
4180 static CRITICAL_SECTION tzname_section
= { &tzname_section_debug
, -1, 0, 0, 0, 0 };
4183 WCHAR key_name
[128];
4184 WCHAR standard_name
[32];
4185 WCHAR daylight_name
[32];
4188 /***********************************************************************
4189 * GetDynamicTimeZoneInformation (kernelbase.@)
4191 DWORD WINAPI DECLSPEC_HOTPATCH
GetDynamicTimeZoneInformation( DYNAMIC_TIME_ZONE_INFORMATION
*info
)
4196 if (!set_ntstatus( RtlQueryDynamicTimeZoneInformation( (RTL_DYNAMIC_TIME_ZONE_INFORMATION
*)info
)))
4197 return TIME_ZONE_ID_INVALID
;
4199 RtlEnterCriticalSection( &tzname_section
);
4200 if (cached_tzname
.lcid
== GetThreadLocale() &&
4201 !wcscmp( info
->TimeZoneKeyName
, cached_tzname
.key_name
))
4203 wcscpy( info
->StandardName
, cached_tzname
.standard_name
);
4204 wcscpy( info
->DaylightName
, cached_tzname
.daylight_name
);
4205 RtlLeaveCriticalSection( &tzname_section
);
4209 RtlLeaveCriticalSection( &tzname_section
);
4210 if (!RegOpenKeyExW( tz_key
, info
->TimeZoneKeyName
, 0, KEY_ALL_ACCESS
, &key
))
4212 RegLoadMUIStringW( key
, L
"MUI_Std", info
->StandardName
,
4213 sizeof(info
->StandardName
), NULL
, 0, system_dir
);
4214 RegLoadMUIStringW( key
, L
"MUI_Dlt", info
->DaylightName
,
4215 sizeof(info
->DaylightName
), NULL
, 0, system_dir
);
4218 else return TIME_ZONE_ID_INVALID
;
4220 RtlEnterCriticalSection( &tzname_section
);
4221 cached_tzname
.lcid
= GetThreadLocale();
4222 wcscpy( cached_tzname
.key_name
, info
->TimeZoneKeyName
);
4223 wcscpy( cached_tzname
.standard_name
, info
->StandardName
);
4224 wcscpy( cached_tzname
.daylight_name
, info
->DaylightName
);
4225 RtlLeaveCriticalSection( &tzname_section
);
4228 NtQuerySystemTime( &now
);
4229 return get_timezone_id( (TIME_ZONE_INFORMATION
*)info
, now
, FALSE
);
4233 /******************************************************************************
4234 * GetDynamicTimeZoneInformationEffectiveYears (kernelbase.@)
4236 DWORD WINAPI DECLSPEC_HOTPATCH
GetDynamicTimeZoneInformationEffectiveYears( const DYNAMIC_TIME_ZONE_INFORMATION
*info
,
4237 DWORD
*first
, DWORD
*last
)
4239 HKEY key
, dst_key
= 0;
4240 DWORD type
, count
, ret
= ERROR_FILE_NOT_FOUND
;
4242 if (RegOpenKeyExW( tz_key
, info
->TimeZoneKeyName
, 0, KEY_ALL_ACCESS
, &key
)) return ret
;
4244 if (RegOpenKeyExW( key
, L
"Dynamic DST", 0, KEY_ALL_ACCESS
, &dst_key
)) goto done
;
4245 count
= sizeof(DWORD
);
4246 if (RegQueryValueExW( dst_key
, L
"FirstEntry", NULL
, &type
, (BYTE
*)first
, &count
)) goto done
;
4247 if (type
!= REG_DWORD
) goto done
;
4248 count
= sizeof(DWORD
);
4249 if (RegQueryValueExW( dst_key
, L
"LastEntry", NULL
, &type
, (BYTE
*)last
, &count
)) goto done
;
4250 if (type
!= REG_DWORD
) goto done
;
4254 RegCloseKey( dst_key
);
4260 /******************************************************************************
4261 * GetFileMUIInfo (kernelbase.@)
4263 BOOL WINAPI
/* DECLSPEC_HOTPATCH */ GetFileMUIInfo( DWORD flags
, const WCHAR
*path
,
4264 FILEMUIINFO
*info
, DWORD
*size
)
4266 FIXME( "stub: %u, %s, %p, %p\n", flags
, debugstr_w(path
), info
, size
);
4267 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
4272 /******************************************************************************
4273 * GetFileMUIPath (kernelbase.@)
4275 BOOL WINAPI
/* DECLSPEC_HOTPATCH */ GetFileMUIPath( DWORD flags
, const WCHAR
*filepath
,
4276 WCHAR
*language
, ULONG
*languagelen
,
4277 WCHAR
*muipath
, ULONG
*muipathlen
,
4278 ULONGLONG
*enumerator
)
4280 FIXME( "stub: 0x%x, %s, %s, %p, %p, %p, %p\n", flags
, debugstr_w(filepath
),
4281 debugstr_w(language
), languagelen
, muipath
, muipathlen
, enumerator
);
4282 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
4287 /******************************************************************************
4288 * GetGeoInfoW (kernelbase.@)
4290 INT WINAPI DECLSPEC_HOTPATCH
GetGeoInfoW( GEOID id
, GEOTYPE type
, WCHAR
*data
, int count
, LANGID lang
)
4292 const struct geoinfo
*ptr
= get_geoinfo_ptr( id
);
4294 const WCHAR
*str
= bufferW
;
4297 TRACE( "%d %d %p %d %d\n", id
, type
, data
, count
, lang
);
4301 SetLastError( ERROR_INVALID_PARAMETER
);
4307 if (ptr
->kind
!= LOCATION_NATION
) return 0;
4310 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%u", ptr
->id
);
4312 case GEO_ISO_UN_NUMBER
:
4313 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03u", ptr
->uncode
);
4316 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%u", ptr
->parent
);
4326 case GEO_FRIENDLYNAME
:
4327 case GEO_OFFICIALNAME
:
4329 case GEO_OFFICIALLANGUAGES
:
4332 case GEO_DIALINGCODE
:
4333 case GEO_CURRENCYCODE
:
4334 case GEO_CURRENCYSYMBOL
:
4336 FIXME( "type %d is not supported\n", type
);
4337 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
4340 WARN( "unrecognized type %d\n", type
);
4341 SetLastError( ERROR_INVALID_FLAGS
);
4345 len
= lstrlenW(str
) + 1;
4346 if (!data
|| !count
) return len
;
4348 memcpy( data
, str
, min(len
, count
) * sizeof(WCHAR
) );
4349 if (count
< len
) SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4350 return count
< len
? 0 : len
;
4354 /******************************************************************************
4355 * GetLocaleInfoA (kernelbase.@)
4357 INT WINAPI DECLSPEC_HOTPATCH
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, char *buffer
, INT len
)
4362 TRACE( "lcid=0x%x lctype=0x%x %p %d\n", lcid
, lctype
, buffer
, len
);
4364 if (len
< 0 || (len
&& !buffer
))
4366 SetLastError( ERROR_INVALID_PARAMETER
);
4369 if (LOWORD(lctype
) == LOCALE_SSHORTTIME
|| (lctype
& LOCALE_RETURN_GENITIVE_NAMES
))
4371 SetLastError( ERROR_INVALID_FLAGS
);
4375 if (LOWORD(lctype
) == LOCALE_FONTSIGNATURE
|| (lctype
& LOCALE_RETURN_NUMBER
))
4376 return GetLocaleInfoW( lcid
, lctype
, (WCHAR
*)buffer
, len
/ sizeof(WCHAR
) ) * sizeof(WCHAR
);
4378 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
4380 if (!(bufferW
= RtlAllocateHeap( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
4382 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
4385 ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
);
4386 if (ret
) ret
= WideCharToMultiByte( get_lcid_codepage( lcid
, lctype
), 0,
4387 bufferW
, ret
, buffer
, len
, NULL
, NULL
);
4388 RtlFreeHeap( GetProcessHeap(), 0, bufferW
);
4393 /******************************************************************************
4394 * GetLocaleInfoW (kernelbase.@)
4396 INT WINAPI DECLSPEC_HOTPATCH
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, WCHAR
*buffer
, INT len
)
4401 UINT lcflags
= lctype
;
4405 if (len
< 0 || (len
&& !buffer
))
4407 SetLastError( ERROR_INVALID_PARAMETER
);
4410 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&& !is_genitive_name_supported( lctype
))
4412 SetLastError( ERROR_INVALID_FLAGS
);
4416 if (!len
) buffer
= NULL
;
4418 lcid
= ConvertDefaultLocale( lcid
);
4419 lctype
= LOWORD(lctype
);
4421 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
4423 /* first check for overrides in the registry */
4425 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) && lcid
== ConvertDefaultLocale( LOCALE_USER_DEFAULT
))
4427 const struct registry_value
*value
= get_locale_registry_value( lctype
);
4431 if (lcflags
& LOCALE_RETURN_NUMBER
)
4434 ret
= get_registry_locale_info( value
, tmp
, ARRAY_SIZE( tmp
));
4438 UINT number
= wcstol( tmp
, &end
, get_value_base_by_lctype( lctype
) );
4439 if (*end
) /* invalid number */
4441 SetLastError( ERROR_INVALID_FLAGS
);
4444 ret
= sizeof(UINT
) / sizeof(WCHAR
);
4445 if (!len
) return ret
;
4448 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4451 memcpy( buffer
, &number
, sizeof(number
) );
4454 else ret
= get_registry_locale_info( value
, buffer
, len
);
4456 if (ret
!= -1) return ret
;
4460 /* now load it from kernel resources */
4462 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
4463 ULongToPtr((lctype
>> 4) + 1), lcid
)))
4465 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
4468 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
))) return 0;
4470 p
= LockResource( hmem
);
4471 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
4473 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
) / sizeof(WCHAR
);
4474 else if (is_genitive_name_supported( lctype
) && *p
)
4476 /* genitive form is stored after a null separator from a nominative */
4477 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
4479 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
4487 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
4489 if (!len
) return ret
;
4493 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4497 if (lcflags
& LOCALE_RETURN_NUMBER
)
4500 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
4502 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
4504 number
= wcstol( tmp
, &end
, get_value_base_by_lctype( lctype
) );
4506 memcpy( buffer
, &number
, sizeof(number
) );
4507 else /* invalid number */
4509 SetLastError( ERROR_INVALID_FLAGS
);
4512 HeapFree( GetProcessHeap(), 0, tmp
);
4514 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
4515 lcid
, lctype
, buffer
, len
, number
);
4519 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
4520 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
4522 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
4523 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
4529 /******************************************************************************
4530 * GetLocaleInfoEx (kernelbase.@)
4532 INT WINAPI DECLSPEC_HOTPATCH
GetLocaleInfoEx( const WCHAR
*locale
, LCTYPE info
, WCHAR
*buffer
, INT len
)
4534 LCID lcid
= LocaleNameToLCID( locale
, 0 );
4536 TRACE( "%s lcid=0x%x 0x%x\n", debugstr_w(locale
), lcid
, info
);
4538 if (!lcid
) return 0;
4540 /* special handling for neutral locale names */
4541 if (locale
&& lstrlenW( locale
) == 2)
4543 switch (LOWORD( info
))
4548 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4551 if (len
) lstrcpyW( buffer
, locale
);
4553 case LOCALE_SPARENT
:
4554 if (len
) buffer
[0] = 0;
4558 return GetLocaleInfoW( lcid
, info
, buffer
, len
);
4562 /******************************************************************************
4563 * GetNLSVersion (kernelbase.@)
4565 BOOL WINAPI DECLSPEC_HOTPATCH
GetNLSVersion( NLS_FUNCTION func
, LCID lcid
, NLSVERSIONINFO
*info
)
4567 WCHAR locale
[LOCALE_NAME_MAX_LENGTH
];
4569 if (info
->dwNLSVersionInfoSize
< offsetof( NLSVERSIONINFO
, dwEffectiveId
))
4571 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4574 if (!LCIDToLocaleName( lcid
, locale
, LOCALE_NAME_MAX_LENGTH
, LOCALE_ALLOW_NEUTRAL_NAMES
))
4576 SetLastError( ERROR_INVALID_PARAMETER
);
4579 return GetNLSVersionEx( func
, locale
, (NLSVERSIONINFOEX
*)info
);
4583 /******************************************************************************
4584 * GetNLSVersionEx (kernelbase.@)
4586 BOOL WINAPI DECLSPEC_HOTPATCH
GetNLSVersionEx( NLS_FUNCTION func
, const WCHAR
*locale
,
4587 NLSVERSIONINFOEX
*info
)
4591 if (func
!= COMPARE_STRING
)
4593 SetLastError( ERROR_INVALID_FLAGS
);
4596 if (info
->dwNLSVersionInfoSize
< sizeof(*info
) &&
4597 (info
->dwNLSVersionInfoSize
!= offsetof( NLSVERSIONINFO
, dwEffectiveId
)))
4599 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4603 if (!(lcid
= LocaleNameToLCID( locale
, 0 ))) return FALSE
;
4605 info
->dwNLSVersion
= info
->dwDefinedVersion
= sort
.version
;
4606 if (info
->dwNLSVersionInfoSize
>= sizeof(*info
))
4608 const struct sortguid
*sortid
= get_language_sort( locale
);
4609 info
->dwEffectiveId
= lcid
;
4610 info
->guidCustomVersion
= sortid
? sortid
->id
: default_sort_guid
;
4616 /******************************************************************************
4617 * GetOEMCP (kernelbase.@)
4619 UINT WINAPI
GetOEMCP(void)
4621 return nls_info
.OemTableInfo
.CodePage
;
4625 /***********************************************************************
4626 * GetProcessPreferredUILanguages (kernelbase.@)
4628 BOOL WINAPI DECLSPEC_HOTPATCH
GetProcessPreferredUILanguages( DWORD flags
, ULONG
*count
,
4629 WCHAR
*buffer
, ULONG
*size
)
4631 return set_ntstatus( RtlGetProcessPreferredUILanguages( flags
, count
, buffer
, size
));
4635 /***********************************************************************
4636 * GetStringTypeA (kernelbase.@)
4638 BOOL WINAPI DECLSPEC_HOTPATCH
GetStringTypeA( LCID locale
, DWORD type
, const char *src
, int count
,
4646 if (count
== -1) count
= strlen(src
) + 1;
4648 cp
= get_lcid_codepage( locale
, 0 );
4649 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
4650 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4652 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
4654 * NOTE: the target buffer has 1 word for each CHARACTER in the source
4655 * string, with multibyte characters there maybe be more bytes in count
4656 * than character space in the buffer!
4658 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
4659 HeapFree(GetProcessHeap(), 0, srcW
);
4665 /***********************************************************************
4666 * GetStringTypeW (kernelbase.@)
4668 BOOL WINAPI DECLSPEC_HOTPATCH
GetStringTypeW( DWORD type
, const WCHAR
*src
, INT count
, WORD
*chartype
)
4672 SetLastError( ERROR_INVALID_PARAMETER
);
4675 if (type
!= CT_CTYPE1
&& type
!= CT_CTYPE2
&& type
!= CT_CTYPE3
)
4677 SetLastError( ERROR_INVALID_PARAMETER
);
4681 if (count
== -1) count
= lstrlenW(src
) + 1;
4683 while (count
--) *chartype
++ = get_char_type( type
, *src
++ );
4689 /***********************************************************************
4690 * GetStringTypeExW (kernelbase.@)
4692 BOOL WINAPI DECLSPEC_HOTPATCH
GetStringTypeExW( LCID locale
, DWORD type
, const WCHAR
*src
, int count
,
4695 /* locale is ignored for Unicode */
4696 return GetStringTypeW( type
, src
, count
, chartype
);
4700 /***********************************************************************
4701 * GetSystemDefaultLCID (kernelbase.@)
4703 LCID WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultLCID(void)
4706 NtQueryDefaultLocale( FALSE
, &lcid
);
4711 /***********************************************************************
4712 * GetSystemDefaultLangID (kernelbase.@)
4714 LANGID WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultLangID(void)
4716 return LANGIDFROMLCID( GetSystemDefaultLCID() );
4720 /***********************************************************************
4721 * GetSystemDefaultLocaleName (kernelbase.@)
4723 INT WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultLocaleName( LPWSTR name
, INT len
)
4725 return LCIDToLocaleName( GetSystemDefaultLCID(), name
, len
, 0 );
4729 /***********************************************************************
4730 * GetSystemDefaultUILanguage (kernelbase.@)
4732 LANGID WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultUILanguage(void)
4735 NtQueryInstallUILanguage( &lang
);
4740 /***********************************************************************
4741 * GetSystemPreferredUILanguages (kernelbase.@)
4743 BOOL WINAPI DECLSPEC_HOTPATCH
GetSystemPreferredUILanguages( DWORD flags
, ULONG
*count
,
4744 WCHAR
*buffer
, ULONG
*size
)
4746 return set_ntstatus( RtlGetSystemPreferredUILanguages( flags
, 0, count
, buffer
, size
));
4750 /***********************************************************************
4751 * GetThreadPreferredUILanguages (kernelbase.@)
4753 BOOL WINAPI DECLSPEC_HOTPATCH
GetThreadPreferredUILanguages( DWORD flags
, ULONG
*count
,
4754 WCHAR
*buffer
, ULONG
*size
)
4756 return set_ntstatus( RtlGetThreadPreferredUILanguages( flags
, count
, buffer
, size
));
4760 /***********************************************************************
4761 * GetTimeZoneInformation (kernelbase.@)
4763 DWORD WINAPI DECLSPEC_HOTPATCH
GetTimeZoneInformation( TIME_ZONE_INFORMATION
*info
)
4765 DYNAMIC_TIME_ZONE_INFORMATION tzinfo
;
4766 DWORD ret
= GetDynamicTimeZoneInformation( &tzinfo
);
4768 memcpy( info
, &tzinfo
, sizeof(*info
) );
4773 /***********************************************************************
4774 * GetTimeZoneInformationForYear (kernelbase.@)
4776 BOOL WINAPI DECLSPEC_HOTPATCH
GetTimeZoneInformationForYear( USHORT year
,
4777 DYNAMIC_TIME_ZONE_INFORMATION
*dynamic
,
4778 TIME_ZONE_INFORMATION
*info
)
4780 DYNAMIC_TIME_ZONE_INFORMATION local_info
;
4781 HKEY key
= 0, dst_key
;
4789 SYSTEMTIME std_date
;
4790 SYSTEMTIME dlt_date
;
4793 TRACE( "(%u,%p)\n", year
, info
);
4797 if (GetDynamicTimeZoneInformation( &local_info
) == TIME_ZONE_ID_INVALID
) return FALSE
;
4798 dynamic
= &local_info
;
4801 if ((ret
= RegOpenKeyExW( tz_key
, dynamic
->TimeZoneKeyName
, 0, KEY_ALL_ACCESS
, &key
))) goto done
;
4802 if (RegLoadMUIStringW( key
, L
"MUI_Std", info
->StandardName
,
4803 sizeof(info
->StandardName
), NULL
, 0, system_dir
))
4805 count
= sizeof(info
->StandardName
);
4806 if ((ret
= RegQueryValueExW( key
, L
"Std", NULL
, NULL
, (BYTE
*)info
->StandardName
, &count
)))
4809 if (RegLoadMUIStringW( key
, L
"MUI_Dlt", info
->DaylightName
,
4810 sizeof(info
->DaylightName
), NULL
, 0, system_dir
))
4812 count
= sizeof(info
->DaylightName
);
4813 if ((ret
= RegQueryValueExW( key
, L
"Dlt", NULL
, NULL
, (BYTE
*)info
->DaylightName
, &count
)))
4817 ret
= ERROR_FILE_NOT_FOUND
;
4818 if (!dynamic
->DynamicDaylightTimeDisabled
&&
4819 !RegOpenKeyExW( key
, L
"Dynamic DST", 0, KEY_ALL_ACCESS
, &dst_key
))
4822 swprintf( yearW
, ARRAY_SIZE(yearW
), L
"%u", year
);
4823 count
= sizeof(data
);
4824 ret
= RegQueryValueExW( dst_key
, yearW
, NULL
, NULL
, (BYTE
*)&data
, &count
);
4825 RegCloseKey( dst_key
);
4829 count
= sizeof(data
);
4830 ret
= RegQueryValueExW( key
, L
"TZI", NULL
, NULL
, (BYTE
*)&data
, &count
);
4835 info
->Bias
= data
.bias
;
4836 info
->StandardBias
= data
.std_bias
;
4837 info
->DaylightBias
= data
.dlt_bias
;
4838 info
->StandardDate
= data
.std_date
;
4839 info
->DaylightDate
= data
.dlt_date
;
4844 if (ret
) SetLastError( ret
);
4849 /***********************************************************************
4850 * GetUserDefaultLCID (kernelbase.@)
4852 LCID WINAPI DECLSPEC_HOTPATCH
GetUserDefaultLCID(void)
4855 NtQueryDefaultLocale( TRUE
, &lcid
);
4860 /***********************************************************************
4861 * GetUserDefaultLangID (kernelbase.@)
4863 LANGID WINAPI DECLSPEC_HOTPATCH
GetUserDefaultLangID(void)
4865 return LANGIDFROMLCID( GetUserDefaultLCID() );
4869 /***********************************************************************
4870 * GetUserDefaultLocaleName (kernelbase.@)
4872 INT WINAPI DECLSPEC_HOTPATCH
GetUserDefaultLocaleName( LPWSTR name
, INT len
)
4874 return LCIDToLocaleName( GetUserDefaultLCID(), name
, len
, 0 );
4878 /***********************************************************************
4879 * GetUserDefaultUILanguage (kernelbase.@)
4881 LANGID WINAPI DECLSPEC_HOTPATCH
GetUserDefaultUILanguage(void)
4884 NtQueryDefaultUILanguage( &lang
);
4889 /******************************************************************************
4890 * GetUserGeoID (kernelbase.@)
4892 GEOID WINAPI DECLSPEC_HOTPATCH
GetUserGeoID( GEOCLASS geoclass
)
4901 case GEOCLASS_NATION
:
4904 case GEOCLASS_REGION
:
4908 WARN("Unknown geoclass %d\n", geoclass
);
4909 return GEOID_NOT_AVAILABLE
;
4911 if (!RegOpenKeyExW( intl_key
, L
"Geo", 0, KEY_ALL_ACCESS
, &hkey
))
4913 DWORD count
= sizeof(bufferW
);
4914 if (!RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)bufferW
, &count
))
4915 ret
= wcstol( bufferW
, NULL
, 10 );
4916 RegCloseKey( hkey
);
4922 /******************************************************************************
4923 * GetUserPreferredUILanguages (kernelbase.@)
4925 BOOL WINAPI DECLSPEC_HOTPATCH
GetUserPreferredUILanguages( DWORD flags
, ULONG
*count
,
4926 WCHAR
*buffer
, ULONG
*size
)
4928 return set_ntstatus( RtlGetUserPreferredUILanguages( flags
, 0, count
, buffer
, size
));
4932 /******************************************************************************
4933 * IdnToAscii (kernelbase.@)
4935 INT WINAPI DECLSPEC_HOTPATCH
IdnToAscii( DWORD flags
, const WCHAR
*src
, INT srclen
,
4936 WCHAR
*dst
, INT dstlen
)
4938 NTSTATUS status
= RtlIdnToAscii( flags
, src
, srclen
, dst
, &dstlen
);
4939 if (!set_ntstatus( status
)) return 0;
4944 /******************************************************************************
4945 * IdnToNameprepUnicode (kernelbase.@)
4947 INT WINAPI DECLSPEC_HOTPATCH
IdnToNameprepUnicode( DWORD flags
, const WCHAR
*src
, INT srclen
,
4948 WCHAR
*dst
, INT dstlen
)
4950 NTSTATUS status
= RtlIdnToNameprepUnicode( flags
, src
, srclen
, dst
, &dstlen
);
4951 if (!set_ntstatus( status
)) return 0;
4956 /******************************************************************************
4957 * IdnToUnicode (kernelbase.@)
4959 INT WINAPI DECLSPEC_HOTPATCH
IdnToUnicode( DWORD flags
, const WCHAR
*src
, INT srclen
,
4960 WCHAR
*dst
, INT dstlen
)
4962 NTSTATUS status
= RtlIdnToUnicode( flags
, src
, srclen
, dst
, &dstlen
);
4963 if (!set_ntstatus( status
)) return 0;
4968 /******************************************************************************
4969 * IsCharAlphaA (kernelbase.@)
4971 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaA( CHAR c
)
4973 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
4974 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_ALPHA
);
4978 /******************************************************************************
4979 * IsCharAlphaW (kernelbase.@)
4981 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaW( WCHAR wc
)
4983 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_ALPHA
);
4987 /******************************************************************************
4988 * IsCharAlphaNumericA (kernelbase.@)
4990 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaNumericA( CHAR c
)
4992 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
4993 return !!(get_char_type( CT_CTYPE1
, wc
) & (C1_ALPHA
| C1_DIGIT
));
4997 /******************************************************************************
4998 * IsCharAlphaNumericW (kernelbase.@)
5000 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaNumericW( WCHAR wc
)
5002 return !!(get_char_type( CT_CTYPE1
, wc
) & (C1_ALPHA
| C1_DIGIT
));
5006 /******************************************************************************
5007 * IsCharBlankW (kernelbase.@)
5009 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharBlankW( WCHAR wc
)
5011 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_BLANK
);
5015 /******************************************************************************
5016 * IsCharCntrlW (kernelbase.@)
5018 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharCntrlW( WCHAR wc
)
5020 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_CNTRL
);
5024 /******************************************************************************
5025 * IsCharDigitW (kernelbase.@)
5027 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharDigitW( WCHAR wc
)
5029 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_DIGIT
);
5033 /******************************************************************************
5034 * IsCharLowerA (kernelbase.@)
5036 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharLowerA( CHAR c
)
5038 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5039 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_LOWER
);
5043 /******************************************************************************
5044 * IsCharLowerW (kernelbase.@)
5046 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharLowerW( WCHAR wc
)
5048 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_LOWER
);
5052 /******************************************************************************
5053 * IsCharPunctW (kernelbase.@)
5055 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharPunctW( WCHAR wc
)
5057 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_PUNCT
);
5061 /******************************************************************************
5062 * IsCharSpaceA (kernelbase.@)
5064 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharSpaceA( CHAR c
)
5066 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5067 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_SPACE
);
5071 /******************************************************************************
5072 * IsCharSpaceW (kernelbase.@)
5074 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharSpaceW( WCHAR wc
)
5076 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_SPACE
);
5080 /******************************************************************************
5081 * IsCharUpperA (kernelbase.@)
5083 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharUpperA( CHAR c
)
5085 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5086 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_UPPER
);
5090 /******************************************************************************
5091 * IsCharUpperW (kernelbase.@)
5093 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharUpperW( WCHAR wc
)
5095 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_UPPER
);
5099 /******************************************************************************
5100 * IsCharXDigitW (kernelbase.@)
5102 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharXDigitW( WCHAR wc
)
5104 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_XDIGIT
);
5108 /******************************************************************************
5109 * IsDBCSLeadByte (kernelbase.@)
5111 BOOL WINAPI DECLSPEC_HOTPATCH
IsDBCSLeadByte( BYTE testchar
)
5113 return nls_info
.AnsiTableInfo
.DBCSCodePage
&& nls_info
.AnsiTableInfo
.DBCSOffsets
[testchar
];
5117 /******************************************************************************
5118 * IsDBCSLeadByteEx (kernelbase.@)
5120 BOOL WINAPI DECLSPEC_HOTPATCH
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
5122 const CPTABLEINFO
*table
= get_codepage_table( codepage
);
5123 return table
&& table
->DBCSCodePage
&& table
->DBCSOffsets
[testchar
];
5127 /******************************************************************************
5128 * IsNormalizedString (kernelbase.@)
5130 BOOL WINAPI DECLSPEC_HOTPATCH
IsNormalizedString( NORM_FORM form
, const WCHAR
*str
, INT len
)
5133 if (!set_ntstatus( RtlIsNormalizedString( form
, str
, len
, &res
))) res
= FALSE
;
5138 /******************************************************************************
5139 * IsValidCodePage (kernelbase.@)
5141 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidCodePage( UINT codepage
)
5154 return get_codepage_table( codepage
) != NULL
;
5159 /******************************************************************************
5160 * IsValidLanguageGroup (kernelbase.@)
5162 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidLanguageGroup( LGRPID id
, DWORD flags
)
5164 WCHAR name
[10], value
[10];
5165 DWORD type
, value_len
= sizeof(value
);
5169 if (RegOpenKeyExW( nls_key
, L
"Language Groups", 0, KEY_READ
, &key
)) return FALSE
;
5171 swprintf( name
, ARRAY_SIZE(name
), L
"%x", id
);
5172 if (!RegQueryValueExW( key
, name
, NULL
, &type
, (BYTE
*)value
, &value_len
) && type
== REG_SZ
)
5173 ret
= (flags
& LGRPID_SUPPORTED
) || wcstoul( value
, NULL
, 10 );
5180 /******************************************************************************
5181 * IsValidLocale (kernelbase.@)
5183 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidLocale( LCID lcid
, DWORD flags
)
5185 /* check if language is registered in the kernel32 resources */
5186 return FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
5187 ULongToPtr( (LOCALE_ILANGUAGE
>> 4) + 1 ), LANGIDFROMLCID(lcid
)) != 0;
5191 /******************************************************************************
5192 * IsValidLocaleName (kernelbase.@)
5194 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidLocaleName( const WCHAR
*locale
)
5198 return !RtlLocaleNameToLcid( locale
, &lcid
, 2 );
5202 /******************************************************************************
5203 * IsValidNLSVersion (kernelbase.@)
5205 DWORD WINAPI DECLSPEC_HOTPATCH
IsValidNLSVersion( NLS_FUNCTION func
, const WCHAR
*locale
,
5206 NLSVERSIONINFOEX
*info
)
5208 static const GUID GUID_NULL
;
5209 NLSVERSIONINFOEX infoex
;
5212 if (func
!= COMPARE_STRING
)
5214 SetLastError( ERROR_INVALID_PARAMETER
);
5217 if (info
->dwNLSVersionInfoSize
< sizeof(*info
) &&
5218 (info
->dwNLSVersionInfoSize
!= offsetof( NLSVERSIONINFO
, dwEffectiveId
)))
5220 SetLastError( ERROR_INVALID_PARAMETER
);
5223 infoex
.dwNLSVersionInfoSize
= sizeof(infoex
);
5224 if (!GetNLSVersionEx( func
, locale
, &infoex
)) return FALSE
;
5226 ret
= (infoex
.dwNLSVersion
& ~0xff) == (info
->dwNLSVersion
& ~0xff);
5227 if (ret
&& !IsEqualGUID( &info
->guidCustomVersion
, &GUID_NULL
))
5228 ret
= find_sortguid( &info
->guidCustomVersion
) != NULL
;
5230 if (!ret
) SetLastError( ERROR_SUCCESS
);
5235 /***********************************************************************
5236 * LCIDToLocaleName (kernelbase.@)
5238 INT WINAPI DECLSPEC_HOTPATCH
LCIDToLocaleName( LCID lcid
, WCHAR
*name
, INT count
, DWORD flags
)
5241 if (flags
&& !once
++) FIXME( "unsupported flags %x\n", flags
);
5243 return GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, name
, count
);
5247 /***********************************************************************
5248 * LCMapStringEx (kernelbase.@)
5250 INT WINAPI DECLSPEC_HOTPATCH
LCMapStringEx( const WCHAR
*locale
, DWORD flags
, const WCHAR
*src
, int srclen
,
5251 WCHAR
*dst
, int dstlen
, NLSVERSIONINFO
*version
,
5252 void *reserved
, LPARAM handle
)
5254 const struct sortguid
*sortid
= NULL
;
5258 if (version
) FIXME( "unsupported version structure %p\n", version
);
5259 if (reserved
) FIXME( "unsupported reserved pointer %p\n", reserved
);
5263 if (!once
++) FIXME( "unsupported lparam %lx\n", handle
);
5266 if (!src
|| !srclen
|| dstlen
< 0)
5268 SetLastError( ERROR_INVALID_PARAMETER
);
5272 /* mutually exclusive flags */
5273 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
5274 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
5275 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
5276 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
) ||
5279 SetLastError( ERROR_INVALID_FLAGS
);
5283 if (!dstlen
) dst
= NULL
;
5285 if (flags
& LCMAP_LINGUISTIC_CASING
&& !(sortid
= get_language_sort( locale
)))
5287 FIXME( "unknown locale %s\n", debugstr_w(locale
) );
5288 SetLastError( ERROR_INVALID_PARAMETER
);
5292 if (flags
& LCMAP_SORTKEY
)
5298 SetLastError( ERROR_INVALID_FLAGS
);
5301 if (srclen
< 0) srclen
= lstrlenW(src
);
5303 TRACE( "(%s,0x%08x,%s,%d,%p,%d)\n",
5304 debugstr_w(locale
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
5306 if ((ret
= get_sortkey( flags
, src
, srclen
, (char *)dst
, dstlen
))) ret
++;
5307 else SetLastError( ERROR_INSUFFICIENT_BUFFER
);
5311 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
5312 if (flags
& SORT_STRINGSORT
)
5314 SetLastError( ERROR_INVALID_FLAGS
);
5317 if (((flags
& (NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
)) &&
5318 (flags
& ~(NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
))) ||
5319 ((flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
| LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) &&
5320 (flags
& (LCMAP_SIMPLIFIED_CHINESE
| LCMAP_TRADITIONAL_CHINESE
))))
5322 SetLastError( ERROR_INVALID_FLAGS
);
5326 if (srclen
< 0) srclen
= lstrlenW(src
) + 1;
5328 TRACE( "(%s,0x%08x,%s,%d,%p,%d)\n",
5329 debugstr_w(locale
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
5331 if (!dst
) /* return required string length */
5333 if (flags
& NORM_IGNORESYMBOLS
)
5335 for (len
= 0; srclen
; src
++, srclen
--)
5336 if (!(get_char_type( CT_CTYPE1
, *src
) & (C1_PUNCT
| C1_SPACE
))) len
++;
5338 else if (flags
& LCMAP_FULLWIDTH
)
5340 for (len
= 0; srclen
; src
++, srclen
--, len
++)
5342 if (compose_katakana( src
, srclen
, NULL
) == 2)
5349 else if (flags
& LCMAP_HALFWIDTH
)
5351 for (len
= 0; srclen
; src
++, srclen
--, len
++)
5354 /* map Hiragana to Katakana before decomposition if needed */
5355 if ((flags
& LCMAP_KATAKANA
) &&
5356 ((wch
>= 0x3041 && wch
<= 0x3096) || wch
== 0x309D || wch
== 0x309E))
5359 if (decompose_katakana( wch
, NULL
, 0 ) == 2) len
++;
5366 if (src
== dst
&& (flags
& ~(LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)))
5368 SetLastError( ERROR_INVALID_FLAGS
);
5372 if (flags
& (NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
))
5374 for (len
= dstlen
, dst_ptr
= dst
; srclen
&& len
; src
++, srclen
--)
5376 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_type( CT_CTYPE1
, *src
) & (C1_PUNCT
| C1_SPACE
)))
5384 if (flags
& (LCMAP_FULLWIDTH
| LCMAP_HALFWIDTH
| LCMAP_HIRAGANA
| LCMAP_KATAKANA
))
5386 for (len
= dstlen
, dst_ptr
= dst
; len
&& srclen
; src
++, srclen
--, len
--, dst_ptr
++)
5389 if (flags
& LCMAP_FULLWIDTH
)
5391 /* map half-width character to full-width one,
5392 e.g. U+FF71 -> U+30A2, U+FF8C U+FF9F -> U+30D7. */
5393 if (map_to_fullwidth( src
, srclen
, &wch
) == 2)
5401 if (flags
& LCMAP_KATAKANA
)
5403 /* map hiragana to katakana, e.g. U+3041 -> U+30A1.
5404 we can't use C3_HIRAGANA as some characters can't map to katakana */
5405 if ((wch
>= 0x3041 && wch
<= 0x3096) || wch
== 0x309D || wch
== 0x309E) wch
+= 0x60;
5407 else if (flags
& LCMAP_HIRAGANA
)
5409 /* map katakana to hiragana, e.g. U+30A1 -> U+3041.
5410 we can't use C3_KATAKANA as some characters can't map to hiragana */
5411 if ((wch
>= 0x30A1 && wch
<= 0x30F6) || wch
== 0x30FD || wch
== 0x30FE) wch
-= 0x60;
5414 if (flags
& LCMAP_HALFWIDTH
)
5416 /* map full-width character to half-width one,
5417 e.g. U+30A2 -> U+FF71, U+30D7 -> U+FF8C U+FF9F. */
5418 if (map_to_halfwidth(wch
, dst_ptr
, len
) == 2)
5425 else *dst_ptr
= wch
;
5427 if (!(flags
& (LCMAP_UPPERCASE
| LCMAP_LOWERCASE
)) || srclen
) goto done
;
5429 srclen
= dst_ptr
- dst
;
5433 if (flags
& (LCMAP_UPPERCASE
| LCMAP_LOWERCASE
))
5435 const USHORT
*table
= sort
.casemap
+ (flags
& LCMAP_LINGUISTIC_CASING
? sortid
->casemap
: 0);
5436 table
= table
+ 2 + (flags
& LCMAP_LOWERCASE
? table
[1] : 0);
5437 for (len
= dstlen
, dst_ptr
= dst
; srclen
&& len
; src
++, srclen
--, len
--)
5438 *dst_ptr
++ = casemap( table
, *src
);
5442 len
= min( srclen
, dstlen
);
5443 memcpy( dst
, src
, len
* sizeof(WCHAR
) );
5444 dst_ptr
= dst
+ len
;
5451 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
5455 return dst_ptr
- dst
;
5459 /***********************************************************************
5460 * LCMapStringA (kernelbase.@)
5462 INT WINAPI DECLSPEC_HOTPATCH
LCMapStringA( LCID lcid
, DWORD flags
, const char *src
, int srclen
,
5463 char *dst
, int dstlen
)
5465 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
5467 INT ret
= 0, srclenW
, dstlenW
;
5468 UINT locale_cp
= CP_ACP
;
5470 if (!src
|| !srclen
|| dstlen
< 0)
5472 SetLastError( ERROR_INVALID_PARAMETER
);
5476 locale_cp
= get_lcid_codepage( lcid
, flags
);
5478 srclenW
= MultiByteToWideChar( locale_cp
, 0, src
, srclen
, bufW
, 260 );
5479 if (srclenW
) srcW
= bufW
;
5482 srclenW
= MultiByteToWideChar( locale_cp
, 0, src
, srclen
, NULL
, 0 );
5483 srcW
= HeapAlloc( GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
) );
5486 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
5489 MultiByteToWideChar( locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
5492 if (flags
& LCMAP_SORTKEY
)
5496 SetLastError( ERROR_INVALID_FLAGS
);
5499 ret
= LCMapStringEx( NULL
, flags
, srcW
, srclenW
, (WCHAR
*)dst
, dstlen
, NULL
, NULL
, 0 );
5503 if (flags
& SORT_STRINGSORT
)
5505 SetLastError( ERROR_INVALID_FLAGS
);
5509 dstlenW
= LCMapStringEx( NULL
, flags
, srcW
, srclenW
, NULL
, 0, NULL
, NULL
, 0 );
5510 if (!dstlenW
) goto done
;
5512 dstW
= HeapAlloc( GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
) );
5515 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
5518 LCMapStringEx( NULL
, flags
, srcW
, srclenW
, dstW
, dstlenW
, NULL
, NULL
, 0 );
5519 ret
= WideCharToMultiByte( locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
5520 HeapFree( GetProcessHeap(), 0, dstW
);
5523 if (srcW
!= bufW
) HeapFree( GetProcessHeap(), 0, srcW
);
5528 /***********************************************************************
5529 * LCMapStringW (kernelbase.@)
5531 INT WINAPI DECLSPEC_HOTPATCH
LCMapStringW( LCID lcid
, DWORD flags
, const WCHAR
*src
, int srclen
,
5532 WCHAR
*dst
, int dstlen
)
5534 return LCMapStringEx( NULL
, flags
, src
, srclen
, dst
, dstlen
, NULL
, NULL
, 0 );
5538 /***********************************************************************
5539 * LocaleNameToLCID (kernelbase.@)
5541 LCID WINAPI DECLSPEC_HOTPATCH
LocaleNameToLCID( const WCHAR
*name
, DWORD flags
)
5545 if (!name
) return GetUserDefaultLCID();
5546 if (!set_ntstatus( RtlLocaleNameToLcid( name
, &lcid
, 2 ))) return 0;
5547 if (!(flags
& LOCALE_ALLOW_NEUTRAL_NAMES
)) lcid
= ConvertDefaultLocale( lcid
);
5552 /******************************************************************************
5553 * MultiByteToWideChar (kernelbase.@)
5555 INT WINAPI DECLSPEC_HOTPATCH
MultiByteToWideChar( UINT codepage
, DWORD flags
, const char *src
, INT srclen
,
5556 WCHAR
*dst
, INT dstlen
)
5560 if (!src
|| !srclen
|| (!dst
&& dstlen
) || dstlen
< 0)
5562 SetLastError( ERROR_INVALID_PARAMETER
);
5565 if (srclen
< 0) srclen
= strlen(src
) + 1;
5570 ret
= mbstowcs_cpsymbol( flags
, src
, srclen
, dst
, dstlen
);
5573 ret
= mbstowcs_utf7( flags
, src
, srclen
, dst
, dstlen
);
5576 ret
= mbstowcs_utf8( flags
, src
, srclen
, dst
, dstlen
);
5579 if (unix_cp
== CP_UTF8
)
5581 ret
= mbstowcs_utf8( flags
, src
, srclen
, dst
, dstlen
);
5582 #ifdef __APPLE__ /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
5583 if (ret
&& dstlen
) RtlNormalizeString( NormalizationC
, dst
, ret
, dst
, &ret
);
5590 ret
= mbstowcs_codepage( codepage
, flags
, src
, srclen
, dst
, dstlen
);
5593 TRACE( "cp %d %s -> %s, ret = %d\n", codepage
, debugstr_an(src
, srclen
), debugstr_wn(dst
, ret
), ret
);
5598 /******************************************************************************
5599 * NormalizeString (kernelbase.@)
5601 INT WINAPI DECLSPEC_HOTPATCH
NormalizeString(NORM_FORM form
, const WCHAR
*src
, INT src_len
,
5602 WCHAR
*dst
, INT dst_len
)
5604 NTSTATUS status
= RtlNormalizeString( form
, src
, src_len
, dst
, &dst_len
);
5608 case STATUS_OBJECT_NAME_NOT_FOUND
:
5609 status
= STATUS_INVALID_PARAMETER
;
5611 case STATUS_BUFFER_TOO_SMALL
:
5612 case STATUS_NO_UNICODE_TRANSLATION
:
5616 SetLastError( RtlNtStatusToDosError( status
));
5621 /******************************************************************************
5622 * ResolveLocaleName (kernelbase.@)
5624 INT WINAPI DECLSPEC_HOTPATCH
ResolveLocaleName( LPCWSTR name
, LPWSTR buffer
, INT len
)
5626 FIXME( "stub: %s, %p, %d\n", wine_dbgstr_w(name
), buffer
, len
);
5628 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
5633 /******************************************************************************
5634 * SetLocaleInfoW (kernelbase.@)
5636 BOOL WINAPI DECLSPEC_HOTPATCH
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, const WCHAR
*data
)
5638 const struct registry_value
*value
;
5642 lctype
= LOWORD(lctype
);
5643 value
= get_locale_registry_value( lctype
);
5645 if (!data
|| !value
)
5647 SetLastError( ERROR_INVALID_PARAMETER
);
5651 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
5653 SetLastError( ERROR_INVALID_FLAGS
);
5657 TRACE( "setting %x (%s) to %s\n", lctype
, debugstr_w(value
->name
), debugstr_w(data
) );
5659 /* FIXME: should check that data to set is sane */
5661 status
= RegSetValueExW( intl_key
, value
->name
, 0, REG_SZ
, (BYTE
*)data
, (lstrlenW(data
)+1)*sizeof(WCHAR
) );
5662 index
= value
- registry_values
;
5664 RtlEnterCriticalSection( &locale_section
);
5665 HeapFree( GetProcessHeap(), 0, registry_cache
[index
] );
5666 registry_cache
[index
] = NULL
;
5667 RtlLeaveCriticalSection( &locale_section
);
5669 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
5671 /* Set I-value from S value */
5672 WCHAR
*pD
, *pM
, *pY
, buf
[2];
5674 pD
= wcschr( data
, 'd' );
5675 pM
= wcschr( data
, 'M' );
5676 pY
= wcschr( data
, 'y' );
5678 if (pD
<= pM
) buf
[0] = '1'; /* D-M-Y */
5679 else if (pY
<= pM
) buf
[0] = '2'; /* Y-M-D */
5680 else buf
[0] = '0'; /* M-D-Y */
5683 lctype
= (lctype
== LOCALE_SSHORTDATE
) ? LOCALE_IDATE
: LOCALE_ILDATE
;
5684 value
= get_locale_registry_value( lctype
);
5685 index
= value
- registry_values
;
5687 RegSetValueExW( intl_key
, value
->name
, 0, REG_SZ
, (BYTE
*)buf
, sizeof(buf
) );
5689 RtlEnterCriticalSection( &locale_section
);
5690 HeapFree( GetProcessHeap(), 0, registry_cache
[index
] );
5691 registry_cache
[index
] = NULL
;
5692 RtlLeaveCriticalSection( &locale_section
);
5694 return set_ntstatus( status
);
5698 /***********************************************************************
5699 * SetCalendarInfoW (kernelbase.@)
5701 INT WINAPI
/* DECLSPEC_HOTPATCH */ SetCalendarInfoW( LCID lcid
, CALID calendar
, CALTYPE type
, const WCHAR
*data
)
5703 FIXME( "(%08x,%08x,%08x,%s): stub\n", lcid
, calendar
, type
, debugstr_w(data
) );
5708 /***********************************************************************
5709 * SetProcessPreferredUILanguages (kernelbase.@)
5711 BOOL WINAPI DECLSPEC_HOTPATCH
SetProcessPreferredUILanguages( DWORD flags
, PCZZWSTR buffer
, ULONG
*count
)
5713 return set_ntstatus( RtlSetProcessPreferredUILanguages( flags
, buffer
, count
));
5717 /***********************************************************************
5718 * SetThreadPreferredUILanguages (kernelbase.@)
5720 BOOL WINAPI DECLSPEC_HOTPATCH
SetThreadPreferredUILanguages( DWORD flags
, PCZZWSTR buffer
, ULONG
*count
)
5722 return set_ntstatus( RtlSetThreadPreferredUILanguages( flags
, buffer
, count
));
5726 /***********************************************************************
5727 * SetTimeZoneInformation (kernelbase.@)
5729 BOOL WINAPI DECLSPEC_HOTPATCH
SetTimeZoneInformation( const TIME_ZONE_INFORMATION
*info
)
5731 return set_ntstatus( RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION
*)info
));
5735 /******************************************************************************
5736 * SetUserGeoID (kernelbase.@)
5738 BOOL WINAPI DECLSPEC_HOTPATCH
SetUserGeoID( GEOID id
)
5740 const struct geoinfo
*geoinfo
= get_geoinfo_ptr( id
);
5746 SetLastError( ERROR_INVALID_PARAMETER
);
5749 if (!RegCreateKeyExW( intl_key
, L
"Geo", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
5751 const WCHAR
*name
= geoinfo
->kind
== LOCATION_NATION
? L
"Nation" : L
"Region";
5752 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%u", geoinfo
->id
);
5753 RegSetValueExW( hkey
, name
, 0, REG_SZ
, (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
5755 if (geoinfo
->kind
== LOCATION_NATION
|| geoinfo
->kind
== LOCATION_BOTH
)
5756 lstrcpyW( bufferW
, geoinfo
->iso2W
);
5758 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03u", geoinfo
->uncode
);
5759 RegSetValueExW( hkey
, L
"Name", 0, REG_SZ
, (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
5760 RegCloseKey( hkey
);
5766 /***********************************************************************
5767 * SystemTimeToTzSpecificLocalTime (kernelbase.@)
5769 BOOL WINAPI DECLSPEC_HOTPATCH
SystemTimeToTzSpecificLocalTime( const TIME_ZONE_INFORMATION
*info
,
5770 const SYSTEMTIME
*system
,
5773 TIME_ZONE_INFORMATION tzinfo
;
5778 RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
5782 if (!SystemTimeToFileTime( system
, (FILETIME
*)&ft
)) return FALSE
;
5783 switch (get_timezone_id( info
, ft
, FALSE
))
5785 case TIME_ZONE_ID_UNKNOWN
:
5786 ft
.QuadPart
-= info
->Bias
* (LONGLONG
)600000000;
5788 case TIME_ZONE_ID_STANDARD
:
5789 ft
.QuadPart
-= (info
->Bias
+ info
->StandardBias
) * (LONGLONG
)600000000;
5791 case TIME_ZONE_ID_DAYLIGHT
:
5792 ft
.QuadPart
-= (info
->Bias
+ info
->DaylightBias
) * (LONGLONG
)600000000;
5797 return FileTimeToSystemTime( (FILETIME
*)&ft
, local
);
5801 /***********************************************************************
5802 * TzSpecificLocalTimeToSystemTime (kernelbase.@)
5804 BOOL WINAPI DECLSPEC_HOTPATCH
TzSpecificLocalTimeToSystemTime( const TIME_ZONE_INFORMATION
*info
,
5805 const SYSTEMTIME
*local
,
5806 SYSTEMTIME
*system
)
5808 TIME_ZONE_INFORMATION tzinfo
;
5813 RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
5817 if (!SystemTimeToFileTime( local
, (FILETIME
*)&ft
)) return FALSE
;
5818 switch (get_timezone_id( info
, ft
, TRUE
))
5820 case TIME_ZONE_ID_UNKNOWN
:
5821 ft
.QuadPart
+= info
->Bias
* (LONGLONG
)600000000;
5823 case TIME_ZONE_ID_STANDARD
:
5824 ft
.QuadPart
+= (info
->Bias
+ info
->StandardBias
) * (LONGLONG
)600000000;
5826 case TIME_ZONE_ID_DAYLIGHT
:
5827 ft
.QuadPart
+= (info
->Bias
+ info
->DaylightBias
) * (LONGLONG
)600000000;
5832 return FileTimeToSystemTime( (FILETIME
*)&ft
, system
);
5836 /***********************************************************************
5837 * VerLanguageNameA (kernelbase.@)
5839 DWORD WINAPI DECLSPEC_HOTPATCH
VerLanguageNameA( DWORD lang
, LPSTR buffer
, DWORD size
)
5841 return GetLocaleInfoA( MAKELCID( lang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, buffer
, size
);
5845 /***********************************************************************
5846 * VerLanguageNameW (kernelbase.@)
5848 DWORD WINAPI DECLSPEC_HOTPATCH
VerLanguageNameW( DWORD lang
, LPWSTR buffer
, DWORD size
)
5850 return GetLocaleInfoW( MAKELCID( lang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, buffer
, size
);
5854 /***********************************************************************
5855 * WideCharToMultiByte (kernelbase.@)
5857 INT WINAPI DECLSPEC_HOTPATCH
WideCharToMultiByte( UINT codepage
, DWORD flags
, LPCWSTR src
, INT srclen
,
5858 LPSTR dst
, INT dstlen
, LPCSTR defchar
, BOOL
*used
)
5862 if (!src
|| !srclen
|| (!dst
&& dstlen
) || dstlen
< 0)
5864 SetLastError( ERROR_INVALID_PARAMETER
);
5868 if (srclen
< 0) srclen
= lstrlenW(src
) + 1;
5873 ret
= wcstombs_cpsymbol( flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5876 ret
= wcstombs_utf7( flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5879 ret
= wcstombs_utf8( flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5882 if (unix_cp
== CP_UTF8
)
5884 if (used
) *used
= FALSE
;
5885 ret
= wcstombs_utf8( flags
, src
, srclen
, dst
, dstlen
, NULL
, NULL
);
5891 ret
= wcstombs_codepage( codepage
, flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5894 TRACE( "cp %d %s -> %s, ret = %d\n", codepage
, debugstr_wn(src
, srclen
), debugstr_an(dst
, ret
), ret
);
5899 /***********************************************************************
5900 * GetUserDefaultGeoName (kernelbase.@)
5902 INT WINAPI
GetUserDefaultGeoName(LPWSTR geo_name
, int count
)
5904 const struct geoinfo
*geoinfo
;
5910 TRACE( "geo_name %p, count %d.\n", geo_name
, count
);
5912 if (count
&& !geo_name
)
5914 SetLastError( ERROR_INVALID_PARAMETER
);
5917 if (!(status
= RegOpenKeyExW( intl_key
, L
"Geo", 0, KEY_ALL_ACCESS
, &key
)))
5919 size
= sizeof(buffer
);
5920 status
= RegQueryValueExW( key
, L
"Name", NULL
, NULL
, (BYTE
*)buffer
, &size
);
5925 if ((geoinfo
= get_geoinfo_ptr( GetUserGeoID( GEOCLASS_NATION
))) && geoinfo
->id
!= 39070)
5926 lstrcpyW( buffer
, geoinfo
->iso2W
);
5928 lstrcpyW( buffer
, L
"001" );
5930 size
= lstrlenW( buffer
) + 1;
5935 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
5938 lstrcpyW( geo_name
, buffer
);
5943 /***********************************************************************
5944 * SetUserDefaultGeoName (kernelbase.@)
5946 BOOL WINAPI
SetUserGeoName(PWSTR geo_name
)
5952 TRACE( "geo_name %s.\n", debugstr_w( geo_name
));
5956 SetLastError( ERROR_INVALID_PARAMETER
);
5960 if (lstrlenW( geo_name
) == 3)
5962 uncode
= wcstol( geo_name
, &endptr
, 10 );
5963 if (!uncode
|| endptr
!= geo_name
+ 3)
5965 SetLastError( ERROR_INVALID_PARAMETER
);
5968 for (i
= 0; i
< ARRAY_SIZE(geoinfodata
); ++i
)
5969 if (geoinfodata
[i
].uncode
== uncode
)
5974 if (!lstrcmpiW( geo_name
, L
"XX" ))
5975 return SetUserGeoID( 39070 );
5976 for (i
= 0; i
< ARRAY_SIZE(geoinfodata
); ++i
)
5977 if (!lstrcmpiW( geo_name
, geoinfodata
[i
].iso2W
))
5980 if (i
== ARRAY_SIZE(geoinfodata
))
5982 SetLastError( ERROR_INVALID_PARAMETER
);
5985 return SetUserGeoID( geoinfodata
[i
].id
);