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 LCID system_lcid
;
575 static LCID user_lcid
;
576 static HKEY intl_key
;
579 static const NLS_LOCALE_LCID_INDEX
*lcids_index
;
580 static const NLS_LOCALE_LCNAME_INDEX
*lcnames_index
;
581 static const NLS_LOCALE_HEADER
*locale_table
;
582 static const WCHAR
*locale_strings
;
583 static const NLS_LOCALE_DATA
*system_locale
;
584 static const NLS_LOCALE_DATA
*user_locale
;
586 static CPTABLEINFO codepages
[128];
587 static unsigned int nb_codepages
;
589 static struct norm_table
*norm_info
;
593 GUID id
; /* sort GUID */
594 DWORD flags
; /* flags */
595 DWORD compr
; /* offset to compression table */
596 DWORD except
; /* exception table offset in sortkey table */
597 DWORD ling_except
; /* exception table offset for linguistic casing */
598 DWORD casemap
; /* linguistic casemap table offset */
601 #define FLAG_HAS_3_BYTE_WEIGHTS 0x01
602 #define FLAG_REVERSEDIACRITICS 0x10
603 #define FLAG_DOUBLECOMPRESSION 0x20
604 #define FLAG_INVERSECASING 0x40
606 static const struct sortguid
*current_locale_sort
;
608 static const GUID default_sort_guid
= { 0x00000001, 0x57ee, 0x1e5c, { 0x00, 0xb4, 0xd0, 0x00, 0x0b, 0xb1, 0xe1, 0x1e }};
612 DWORD
*keys
; /* sortkey table, indexed by char */
613 USHORT
*casemap
; /* casemap table, in l_intl.nls format */
614 WORD
*ctypes
; /* CT_CTYPE1,2,3 values */
615 BYTE
*ctype_idx
; /* index to map char to ctypes array entry */
616 DWORD version
; /* NLS version */
617 DWORD guid_count
; /* number of sort GUIDs */
618 struct sortguid
*guids
; /* table of sort GUIDs */
621 static CRITICAL_SECTION locale_section
;
622 static CRITICAL_SECTION_DEBUG critsect_debug
=
624 0, 0, &locale_section
,
625 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
626 0, 0, { (DWORD_PTR
)(__FILE__
": locale_section") }
628 static CRITICAL_SECTION locale_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
631 static void load_locale_nls(void)
647 RtlGetLocaleFileMappingAddress( (void **)&header
, &lcid
, &dummy
);
648 locale_table
= (const NLS_LOCALE_HEADER
*)((char *)header
+ header
->locales
);
649 lcids_index
= (const NLS_LOCALE_LCID_INDEX
*)((char *)locale_table
+ locale_table
->lcids_offset
);
650 lcnames_index
= (const NLS_LOCALE_LCNAME_INDEX
*)((char *)locale_table
+ locale_table
->lcnames_offset
);
651 locale_strings
= (const WCHAR
*)((char *)locale_table
+ locale_table
->strings_offset
);
655 static void init_sortkeys( DWORD
*ptr
)
660 sort
.keys
= (DWORD
*)((char *)ptr
+ ptr
[0]);
661 sort
.casemap
= (USHORT
*)((char *)ptr
+ ptr
[1]);
663 ctype
= (WORD
*)((char *)ptr
+ ptr
[2]);
664 sort
.ctypes
= ctype
+ 2;
665 sort
.ctype_idx
= (BYTE
*)ctype
+ ctype
[1] + 2;
667 table
= (DWORD
*)((char *)ptr
+ ptr
[3]);
668 sort
.version
= table
[0];
669 sort
.guid_count
= table
[1];
670 sort
.guids
= (struct sortguid
*)(table
+ 2);
674 static const struct sortguid
*find_sortguid( const GUID
*guid
)
676 int pos
, ret
, min
= 0, max
= sort
.guid_count
- 1;
680 pos
= (min
+ max
) / 2;
681 ret
= memcmp( guid
, &sort
.guids
[pos
].id
, sizeof(*guid
) );
682 if (!ret
) return &sort
.guids
[pos
];
683 if (ret
> 0) min
= pos
+ 1;
686 ERR( "no sort found for %s\n", debugstr_guid( guid
));
691 static const struct sortguid
*get_language_sort( const WCHAR
*locale
)
693 WCHAR
*p
, *end
, buffer
[LOCALE_NAME_MAX_LENGTH
], guidstr
[39];
694 const struct sortguid
*ret
;
700 if (locale
== LOCALE_NAME_USER_DEFAULT
)
702 if (current_locale_sort
) return current_locale_sort
;
703 GetUserDefaultLocaleName( buffer
, ARRAY_SIZE( buffer
));
705 else lstrcpynW( buffer
, locale
, LOCALE_NAME_MAX_LENGTH
);
707 if (buffer
[0] && !RegOpenKeyExW( nls_key
, L
"Sorting\\Ids", 0, KEY_READ
, &key
))
711 size
= sizeof(guidstr
);
712 if (!RegQueryValueExW( key
, buffer
, NULL
, &type
, (BYTE
*)guidstr
, &size
) && type
== REG_SZ
)
714 RtlInitUnicodeString( &str
, guidstr
);
715 if (!RtlGUIDFromString( &str
, &guid
))
717 ret
= find_sortguid( &guid
);
722 for (p
= end
= buffer
; *p
; p
++) if (*p
== '-' || *p
== '_') end
= p
;
723 if (end
== buffer
) break;
727 ret
= find_sortguid( &default_sort_guid
);
734 static const NLS_LOCALE_DATA
*get_locale_data( UINT idx
)
736 ULONG offset
= locale_table
->locales_offset
+ idx
* locale_table
->locale_size
;
737 return (const NLS_LOCALE_DATA
*)((const char *)locale_table
+ offset
);
741 static int compare_locale_names( const WCHAR
*n1
, const WCHAR
*n2
)
747 if (ch1
>= 'a' && ch1
<= 'z') ch1
-= 'a' - 'A';
748 else if (ch1
== '_') ch1
= '-';
749 if (ch2
>= 'a' && ch2
<= 'z') ch2
-= 'a' - 'A';
750 else if (ch2
== '_') ch2
= '-';
751 if (!ch1
|| ch1
!= ch2
) return ch1
- ch2
;
756 static const NLS_LOCALE_LCNAME_INDEX
*find_lcname_entry( const WCHAR
*name
)
758 int min
= 0, max
= locale_table
->nb_lcnames
- 1;
762 int res
, pos
= (min
+ max
) / 2;
763 const WCHAR
*str
= locale_strings
+ lcnames_index
[pos
].name
;
764 res
= compare_locale_names( name
, str
+ 1 );
765 if (res
< 0) max
= pos
- 1;
766 else if (res
> 0) min
= pos
+ 1;
767 else return &lcnames_index
[pos
];
773 static const NLS_LOCALE_LCID_INDEX
*find_lcid_entry( LCID lcid
)
775 int min
= 0, max
= locale_table
->nb_lcids
- 1;
779 int pos
= (min
+ max
) / 2;
780 if (lcid
< lcids_index
[pos
].id
) max
= pos
- 1;
781 else if (lcid
> lcids_index
[pos
].id
) min
= pos
+ 1;
782 else return &lcids_index
[pos
];
788 static const NLS_LOCALE_DATA
*get_locale_by_name( const WCHAR
*name
, LCID
*lcid
)
790 const NLS_LOCALE_LCNAME_INDEX
*entry
;
792 if (name
== LOCALE_NAME_USER_DEFAULT
)
797 if (!(entry
= find_lcname_entry( name
))) return NULL
;
799 return get_locale_data( entry
->idx
);
803 static const NLS_LOCALE_DATA
*get_locale_by_id( LCID
*lcid
, DWORD flags
)
805 const NLS_LOCALE_LCID_INDEX
*entry
;
806 const NLS_LOCALE_DATA
*locale
;
810 case LOCALE_SYSTEM_DEFAULT
:
812 return system_locale
;
814 case LOCALE_USER_DEFAULT
:
815 case LOCALE_CUSTOM_DEFAULT
:
819 if (!(entry
= find_lcid_entry( *lcid
))) return NULL
;
820 locale
= get_locale_data( entry
->idx
);
821 if (!(flags
& LOCALE_ALLOW_NEUTRAL_NAMES
) && !locale
->inotneutral
)
822 locale
= get_locale_by_name( locale_strings
+ locale
->ssortlocale
+ 1, lcid
);
828 /***********************************************************************
831 void init_locale(void)
833 UINT ansi_cp
= 0, oem_cp
= 0;
834 USHORT
*ansi_ptr
, *oem_ptr
;
836 WCHAR bufferW
[LOCALE_NAME_MAX_LENGTH
];
837 DYNAMIC_TIME_ZONE_INFORMATION timezone
;
838 GEOID geoid
= GEOID_NOT_AVAILABLE
;
839 DWORD count
, dispos
, i
;
844 NtQueryDefaultLocale( FALSE
, &system_lcid
);
845 NtQueryDefaultLocale( FALSE
, &user_lcid
);
846 system_locale
= get_locale_by_id( &system_lcid
, 0 );
847 user_locale
= get_locale_by_id( &user_lcid
, 0 );
849 if (GetEnvironmentVariableW( L
"WINEUNIXCP", bufferW
, ARRAY_SIZE(bufferW
) ))
850 unix_cp
= wcstoul( bufferW
, NULL
, 10 );
852 kernel32_handle
= GetModuleHandleW( L
"kernel32.dll" );
854 GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT
, LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
,
855 (WCHAR
*)&ansi_cp
, sizeof(ansi_cp
)/sizeof(WCHAR
) );
856 GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT
, LOCALE_IDEFAULTMACCODEPAGE
| LOCALE_RETURN_NUMBER
,
857 (WCHAR
*)&mac_cp
, sizeof(mac_cp
)/sizeof(WCHAR
) );
858 GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT
, LOCALE_IDEFAULTCODEPAGE
| LOCALE_RETURN_NUMBER
,
859 (WCHAR
*)&oem_cp
, sizeof(oem_cp
)/sizeof(WCHAR
) );
861 NtGetNlsSectionPtr( 9, 0, NULL
, &sort_ptr
, &size
);
862 NtGetNlsSectionPtr( 12, NormalizationC
, NULL
, (void **)&norm_info
, &size
);
863 init_sortkeys( sort_ptr
);
865 if (!ansi_cp
|| NtGetNlsSectionPtr( 11, ansi_cp
, NULL
, (void **)&ansi_ptr
, &size
))
866 NtGetNlsSectionPtr( 11, 1252, NULL
, (void **)&ansi_ptr
, &size
);
867 if (!oem_cp
|| NtGetNlsSectionPtr( 11, oem_cp
, 0, (void **)&oem_ptr
, &size
))
868 NtGetNlsSectionPtr( 11, 437, NULL
, (void **)&oem_ptr
, &size
);
869 NtCurrentTeb()->Peb
->AnsiCodePageData
= ansi_ptr
;
870 NtCurrentTeb()->Peb
->OemCodePageData
= oem_ptr
;
871 NtCurrentTeb()->Peb
->UnicodeCaseTableData
= sort
.casemap
;
872 RtlInitNlsTables( ansi_ptr
, oem_ptr
, sort
.casemap
, &nls_info
);
873 RtlResetRtlTranslations( &nls_info
);
875 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\Nls",
876 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &nls_key
, NULL
);
877 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
878 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &tz_key
, NULL
);
879 RegCreateKeyExW( HKEY_CURRENT_USER
, L
"Control Panel\\International",
880 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &intl_key
, NULL
);
882 current_locale_sort
= get_language_sort( LOCALE_NAME_USER_DEFAULT
);
884 if (GetDynamicTimeZoneInformation( &timezone
) != TIME_ZONE_ID_INVALID
&&
885 !RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\TimeZoneInformation",
886 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
888 RegSetValueExW( hkey
, L
"StandardName", 0, REG_SZ
, (BYTE
*)timezone
.StandardName
,
889 (lstrlenW(timezone
.StandardName
) + 1) * sizeof(WCHAR
) );
890 RegSetValueExW( hkey
, L
"TimeZoneKeyName", 0, REG_SZ
, (BYTE
*)timezone
.TimeZoneKeyName
,
891 (lstrlenW(timezone
.TimeZoneKeyName
) + 1) * sizeof(WCHAR
) );
895 if (!RegCreateKeyExW( intl_key
, L
"Geo", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, &dispos
))
897 if (dispos
== REG_CREATED_NEW_KEY
)
899 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IGEOID
| LOCALE_RETURN_NUMBER
,
900 (WCHAR
*)&geoid
, sizeof(geoid
) / sizeof(WCHAR
) );
901 SetUserGeoID( geoid
);
906 /* Update registry contents if the user locale has changed.
907 * This simulates the action of the Windows control panel. */
909 count
= sizeof(bufferW
);
910 if (!RegQueryValueExW( intl_key
, L
"Locale", NULL
, NULL
, (BYTE
*)bufferW
, &count
))
912 if (wcstoul( bufferW
, NULL
, 16 ) == user_lcid
) return; /* already set correctly */
913 TRACE( "updating registry, locale changed %s -> %08lx\n", debugstr_w(bufferW
), user_lcid
);
915 else TRACE( "updating registry, locale changed none -> %08lx\n", user_lcid
);
916 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%08x", user_lcid
);
917 RegSetValueExW( intl_key
, L
"Locale", 0, REG_SZ
,
918 (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
920 for (i
= 0; i
< ARRAY_SIZE(registry_values
); i
++)
922 GetLocaleInfoW( LOCALE_USER_DEFAULT
, registry_values
[i
].lctype
| LOCALE_NOUSEROVERRIDE
,
923 bufferW
, ARRAY_SIZE( bufferW
));
924 RegSetValueExW( intl_key
, registry_values
[i
].name
, 0, REG_SZ
,
925 (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
928 if (geoid
== GEOID_NOT_AVAILABLE
)
930 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IGEOID
| LOCALE_RETURN_NUMBER
,
931 (WCHAR
*)&geoid
, sizeof(geoid
) / sizeof(WCHAR
) );
932 SetUserGeoID( geoid
);
935 if (!RegCreateKeyExW( nls_key
, L
"Codepage",
936 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
938 count
= swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03d", ansi_cp
);
939 RegSetValueExW( hkey
, L
"ACP", 0, REG_SZ
, (BYTE
*)bufferW
, (count
+ 1) * sizeof(WCHAR
) );
940 count
= swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03d", oem_cp
);
941 RegSetValueExW( hkey
, L
"OEMCP", 0, REG_SZ
, (BYTE
*)bufferW
, (count
+ 1) * sizeof(WCHAR
) );
942 count
= swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03d", mac_cp
);
943 RegSetValueExW( hkey
, L
"MACCP", 0, REG_SZ
, (BYTE
*)bufferW
, (count
+ 1) * sizeof(WCHAR
) );
949 static inline USHORT
get_table_entry( const USHORT
*table
, WCHAR ch
)
951 return table
[table
[table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0xf)];
955 static inline WCHAR
casemap( const USHORT
*table
, WCHAR ch
)
957 return ch
+ table
[table
[table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0x0f)];
961 static inline WORD
get_char_type( DWORD type
, WCHAR ch
)
963 const BYTE
*ptr
= sort
.ctype_idx
+ ((const WORD
*)sort
.ctype_idx
)[ch
>> 8];
964 ptr
= sort
.ctype_idx
+ ((const WORD
*)ptr
)[(ch
>> 4) & 0x0f] + (ch
& 0x0f);
965 return sort
.ctypes
[*ptr
* 3 + type
/ 2];
969 static BYTE
rol( BYTE val
, BYTE count
)
971 return (val
<< count
) | (val
>> (8 - count
));
975 static BYTE
get_char_props( const struct norm_table
*info
, unsigned int ch
)
977 const BYTE
*level1
= (const BYTE
*)((const USHORT
*)info
+ info
->props_level1
);
978 const BYTE
*level2
= (const BYTE
*)((const USHORT
*)info
+ info
->props_level2
);
979 BYTE off
= level1
[ch
/ 128];
981 if (!off
|| off
>= 0xfb) return rol( off
, 5 );
982 return level2
[(off
- 1) * 128 + ch
% 128];
986 static const WCHAR
*get_decomposition( WCHAR ch
, unsigned int *ret_len
)
988 const struct pair
{ WCHAR src
; USHORT dst
; } *pairs
;
989 const USHORT
*hash_table
= (const USHORT
*)norm_info
+ norm_info
->decomp_hash
;
991 unsigned int i
, pos
, end
, len
, hash
;
994 hash
= ch
% norm_info
->decomp_size
;
995 pos
= hash_table
[hash
];
998 if (get_char_props( norm_info
, ch
) != 0xbf) return NULL
;
999 ret
= (const USHORT
*)norm_info
+ norm_info
->decomp_seq
+ (pos
& 0x1fff);
1004 pairs
= (const struct pair
*)((const USHORT
*)norm_info
+ norm_info
->decomp_map
);
1006 /* find the end of the hash bucket */
1007 for (i
= hash
+ 1; i
< norm_info
->decomp_size
; i
++) if (!(hash_table
[i
] >> 13)) break;
1008 if (i
< norm_info
->decomp_size
) end
= hash_table
[i
];
1009 else for (end
= pos
; pairs
[end
].src
; end
++) ;
1011 for ( ; pos
< end
; pos
++)
1013 if (pairs
[pos
].src
!= (WCHAR
)ch
) continue;
1014 ret
= (const USHORT
*)norm_info
+ norm_info
->decomp_seq
+ (pairs
[pos
].dst
& 0x1fff);
1015 len
= pairs
[pos
].dst
>> 13;
1018 if (pos
>= end
) return NULL
;
1021 if (len
== 7) while (ret
[len
]) len
++;
1022 if (!ret
[0]) len
= 0; /* ignored char */
1028 static WCHAR
compose_chars( WCHAR ch1
, WCHAR ch2
)
1030 const USHORT
*table
= (const USHORT
*)norm_info
+ norm_info
->comp_hash
;
1031 const WCHAR
*chars
= (const USHORT
*)norm_info
+ norm_info
->comp_seq
;
1032 unsigned int hash
, start
, end
, i
;
1035 hash
= (ch1
+ 95 * ch2
) % norm_info
->comp_size
;
1036 start
= table
[hash
];
1037 end
= table
[hash
+ 1];
1040 for (i
= 0; i
< 3; i
++, start
++)
1042 ch
[i
] = chars
[start
];
1043 if (IS_HIGH_SURROGATE( ch
[i
] )) start
++;
1045 if (ch
[0] == ch1
&& ch
[1] == ch2
) return ch
[2];
1051 static UINT
get_lcid_codepage( LCID lcid
, ULONG flags
)
1053 UINT ret
= GetACP();
1055 if (!(flags
& LOCALE_USE_CP_ACP
) && lcid
!= GetSystemDefaultLCID())
1056 GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
,
1057 (WCHAR
*)&ret
, sizeof(ret
)/sizeof(WCHAR
) );
1062 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
1064 switch (LOWORD(lctype
))
1066 case LOCALE_SMONTHNAME1
:
1067 case LOCALE_SMONTHNAME2
:
1068 case LOCALE_SMONTHNAME3
:
1069 case LOCALE_SMONTHNAME4
:
1070 case LOCALE_SMONTHNAME5
:
1071 case LOCALE_SMONTHNAME6
:
1072 case LOCALE_SMONTHNAME7
:
1073 case LOCALE_SMONTHNAME8
:
1074 case LOCALE_SMONTHNAME9
:
1075 case LOCALE_SMONTHNAME10
:
1076 case LOCALE_SMONTHNAME11
:
1077 case LOCALE_SMONTHNAME12
:
1078 case LOCALE_SMONTHNAME13
:
1086 static int get_value_base_by_lctype( LCTYPE lctype
)
1088 return lctype
== LOCALE_ILANGUAGE
|| lctype
== LOCALE_IDEFAULTLANGUAGE
? 16 : 10;
1092 static const struct registry_value
*get_locale_registry_value( DWORD lctype
)
1096 for (i
= 0; i
< ARRAY_SIZE( registry_values
); i
++)
1097 if (registry_values
[i
].lctype
== lctype
) return ®istry_values
[i
];
1102 static INT
get_registry_locale_info( const struct registry_value
*registry_value
, LPWSTR buffer
, INT len
)
1104 DWORD size
, index
= registry_value
- registry_values
;
1107 RtlEnterCriticalSection( &locale_section
);
1109 if (!registry_cache
[index
])
1111 size
= len
* sizeof(WCHAR
);
1112 ret
= RegQueryValueExW( intl_key
, registry_value
->name
, NULL
, NULL
, (BYTE
*)buffer
, &size
);
1115 if (buffer
&& (registry_cache
[index
] = HeapAlloc( GetProcessHeap(), 0, size
+ sizeof(WCHAR
) )))
1117 memcpy( registry_cache
[index
], buffer
, size
);
1118 registry_cache
[index
][size
/ sizeof(WCHAR
)] = 0;
1120 RtlLeaveCriticalSection( &locale_section
);
1121 return size
/ sizeof(WCHAR
);
1125 RtlLeaveCriticalSection( &locale_section
);
1126 if (ret
== ERROR_FILE_NOT_FOUND
) return -1;
1127 if (ret
== ERROR_MORE_DATA
) SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1128 else SetLastError( ret
);
1133 ret
= lstrlenW( registry_cache
[index
] ) + 1;
1138 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1141 else lstrcpyW( buffer
, registry_cache
[index
] );
1143 RtlLeaveCriticalSection( &locale_section
);
1148 static const CPTABLEINFO
*get_codepage_table( UINT codepage
)
1157 return &nls_info
.AnsiTableInfo
;
1159 return &nls_info
.OemTableInfo
;
1164 if (NtCurrentTeb()->CurrentLocale
== GetUserDefaultLCID()) return &nls_info
.AnsiTableInfo
;
1165 codepage
= get_lcid_codepage( NtCurrentTeb()->CurrentLocale
, 0 );
1166 if (!codepage
) return &nls_info
.AnsiTableInfo
;
1169 if (codepage
== nls_info
.AnsiTableInfo
.CodePage
) return &nls_info
.AnsiTableInfo
;
1170 if (codepage
== nls_info
.OemTableInfo
.CodePage
) return &nls_info
.OemTableInfo
;
1174 RtlEnterCriticalSection( &locale_section
);
1176 for (i
= 0; i
< nb_codepages
; i
++) if (codepages
[i
].CodePage
== codepage
) goto done
;
1178 if (i
== ARRAY_SIZE( codepages
))
1180 RtlLeaveCriticalSection( &locale_section
);
1181 ERR( "too many codepages\n" );
1184 if (NtGetNlsSectionPtr( 11, codepage
, NULL
, (void **)&ptr
, &size
))
1186 RtlLeaveCriticalSection( &locale_section
);
1187 SetLastError( ERROR_INVALID_PARAMETER
);
1190 RtlInitCodePageTable( ptr
, &codepages
[i
] );
1193 RtlLeaveCriticalSection( &locale_section
);
1194 return &codepages
[i
];
1198 static const WCHAR
*get_ligature( WCHAR wc
)
1200 int low
= 0, high
= ARRAY_SIZE( ligatures
) -1;
1203 int pos
= (low
+ high
) / 2;
1204 if (ligatures
[pos
][0] < wc
) low
= pos
+ 1;
1205 else if (ligatures
[pos
][0] > wc
) high
= pos
- 1;
1206 else return ligatures
[pos
] + 1;
1212 static NTSTATUS
expand_ligatures( const WCHAR
*src
, int srclen
, WCHAR
*dst
, int *dstlen
)
1214 int i
, len
, pos
= 0;
1215 NTSTATUS ret
= STATUS_SUCCESS
;
1216 const WCHAR
*expand
;
1218 for (i
= 0; i
< srclen
; i
++)
1220 if (!(expand
= get_ligature( src
[i
] )))
1225 else len
= lstrlenW( expand
);
1227 if (*dstlen
&& ret
== STATUS_SUCCESS
)
1229 if (pos
+ len
<= *dstlen
) memcpy( dst
+ pos
, expand
, len
* sizeof(WCHAR
) );
1230 else ret
= STATUS_BUFFER_TOO_SMALL
;
1239 static NTSTATUS
fold_digits( const WCHAR
*src
, int srclen
, WCHAR
*dst
, int *dstlen
)
1241 extern const WCHAR wine_digitmap
[] DECLSPEC_HIDDEN
;
1242 int i
, len
= *dstlen
;
1245 if (!len
) return STATUS_SUCCESS
;
1246 if (srclen
> len
) return STATUS_BUFFER_TOO_SMALL
;
1247 for (i
= 0; i
< srclen
; i
++)
1249 WCHAR digit
= get_table_entry( wine_digitmap
, src
[i
] );
1250 dst
[i
] = digit
? digit
: src
[i
];
1252 return STATUS_SUCCESS
;
1256 static NTSTATUS
fold_string( DWORD flags
, const WCHAR
*src
, int srclen
, WCHAR
*dst
, int *dstlen
)
1263 case MAP_PRECOMPOSED
:
1264 return RtlNormalizeString( NormalizationC
, src
, srclen
, dst
, dstlen
);
1266 case MAP_PRECOMPOSED
| MAP_FOLDCZONE
:
1267 return RtlNormalizeString( NormalizationKC
, src
, srclen
, dst
, dstlen
);
1269 return RtlNormalizeString( NormalizationD
, src
, srclen
, dst
, dstlen
);
1270 case MAP_COMPOSITE
| MAP_FOLDCZONE
:
1271 return RtlNormalizeString( NormalizationKD
, src
, srclen
, dst
, dstlen
);
1272 case MAP_FOLDDIGITS
:
1273 return fold_digits( src
, srclen
, dst
, dstlen
);
1274 case MAP_EXPAND_LIGATURES
:
1275 case MAP_EXPAND_LIGATURES
| MAP_FOLDCZONE
:
1276 return expand_ligatures( src
, srclen
, dst
, dstlen
);
1277 case MAP_FOLDDIGITS
| MAP_PRECOMPOSED
:
1278 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1279 return STATUS_NO_MEMORY
;
1280 fold_digits( src
, srclen
, tmp
, &srclen
);
1281 ret
= RtlNormalizeString( NormalizationC
, tmp
, srclen
, dst
, dstlen
);
1283 case MAP_FOLDDIGITS
| MAP_FOLDCZONE
:
1284 case MAP_FOLDDIGITS
| MAP_PRECOMPOSED
| MAP_FOLDCZONE
:
1285 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1286 return STATUS_NO_MEMORY
;
1287 fold_digits( src
, srclen
, tmp
, &srclen
);
1288 ret
= RtlNormalizeString( NormalizationKC
, tmp
, srclen
, dst
, dstlen
);
1290 case MAP_FOLDDIGITS
| MAP_COMPOSITE
:
1291 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1292 return STATUS_NO_MEMORY
;
1293 fold_digits( src
, srclen
, tmp
, &srclen
);
1294 ret
= RtlNormalizeString( NormalizationD
, tmp
, srclen
, dst
, dstlen
);
1296 case MAP_FOLDDIGITS
| MAP_COMPOSITE
| MAP_FOLDCZONE
:
1297 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1298 return STATUS_NO_MEMORY
;
1299 fold_digits( src
, srclen
, tmp
, &srclen
);
1300 ret
= RtlNormalizeString( NormalizationKD
, tmp
, srclen
, dst
, dstlen
);
1302 case MAP_EXPAND_LIGATURES
| MAP_FOLDDIGITS
:
1303 case MAP_EXPAND_LIGATURES
| MAP_FOLDDIGITS
| MAP_FOLDCZONE
:
1304 if (!(tmp
= RtlAllocateHeap( GetProcessHeap(), 0, srclen
* sizeof(WCHAR
) )))
1305 return STATUS_NO_MEMORY
;
1306 fold_digits( src
, srclen
, tmp
, &srclen
);
1307 ret
= expand_ligatures( tmp
, srclen
, dst
, dstlen
);
1310 return STATUS_INVALID_PARAMETER_1
;
1312 RtlFreeHeap( GetProcessHeap(), 0, tmp
);
1317 static int mbstowcs_cpsymbol( DWORD flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
)
1323 SetLastError( ERROR_INVALID_FLAGS
);
1326 if (!dstlen
) return srclen
;
1327 len
= min( srclen
, dstlen
);
1328 for (i
= 0; i
< len
; i
++)
1330 unsigned char c
= src
[i
];
1331 dst
[i
] = (c
< 0x20) ? c
: c
+ 0xf000;
1335 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1342 static int mbstowcs_utf7( DWORD flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
)
1344 static const signed char base64_decoding_table
[] =
1346 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0F */
1347 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1F */
1348 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20-0x2F */
1349 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30-0x3F */
1350 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40-0x4F */
1351 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50-0x5F */
1352 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60-0x6F */
1353 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70-0x7F */
1356 const char *source_end
= src
+ srclen
;
1357 int offset
= 0, pos
= 0;
1358 DWORD byte_pair
= 0;
1362 SetLastError( ERROR_INVALID_FLAGS
);
1365 #define OUTPUT(ch) \
1369 if (pos >= dstlen) goto overflow; \
1375 while (src
< source_end
)
1380 if (src
>= source_end
) break;
1383 /* just a plus sign escaped as +- */
1391 signed char sextet
= *src
;
1394 /* skip over the dash and end base64 decoding
1395 * the current, unfinished byte pair is discarded */
1402 /* the next character of src is < 0 and therefore not part of a base64 sequence
1403 * the current, unfinished byte pair is NOT discarded in this case
1404 * this is probably a bug in Windows */
1407 sextet
= base64_decoding_table
[sextet
];
1410 /* -1 means that the next character of src is not part of a base64 sequence
1411 * in other words, all sextets in this base64 sequence have been processed
1412 * the current, unfinished byte pair is discarded */
1417 byte_pair
= (byte_pair
<< 6) | sextet
;
1421 /* this byte pair is done */
1422 OUTPUT( byte_pair
>> (offset
- 16) );
1427 while (src
< source_end
);
1431 OUTPUT( (unsigned char)*src
);
1438 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1444 static int mbstowcs_utf8( DWORD flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
)
1449 if (flags
& ~(MB_PRECOMPOSED
| MB_COMPOSITE
| MB_USEGLYPHCHARS
| MB_ERR_INVALID_CHARS
))
1451 SetLastError( ERROR_INVALID_FLAGS
);
1454 if (!dstlen
) dst
= NULL
;
1455 status
= RtlUTF8ToUnicodeN( dst
, dstlen
* sizeof(WCHAR
), &reslen
, src
, srclen
);
1456 if (status
== STATUS_SOME_NOT_MAPPED
)
1458 if (flags
& MB_ERR_INVALID_CHARS
)
1460 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1464 else if (!set_ntstatus( status
)) reslen
= 0;
1466 return reslen
/ sizeof(WCHAR
);
1470 static inline int is_private_use_area_char( WCHAR code
)
1472 return (code
>= 0xe000 && code
<= 0xf8ff);
1476 static int check_invalid_chars( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
)
1478 if (info
->DBCSOffsets
)
1480 for ( ; srclen
; src
++, srclen
-- )
1482 USHORT off
= info
->DBCSOffsets
[*src
];
1485 if (srclen
== 1) break; /* partial char, error */
1486 if (info
->DBCSOffsets
[off
+ src
[1]] == info
->UniDefaultChar
&&
1487 ((src
[0] << 8) | src
[1]) != info
->TransUniDefaultChar
) break;
1492 if (info
->MultiByteTable
[*src
] == info
->UniDefaultChar
&& *src
!= info
->TransUniDefaultChar
)
1494 if (is_private_use_area_char( info
->MultiByteTable
[*src
] )) break;
1499 for ( ; srclen
; src
++, srclen
-- )
1501 if (info
->MultiByteTable
[*src
] == info
->UniDefaultChar
&& *src
!= info
->TransUniDefaultChar
)
1503 if (is_private_use_area_char( info
->MultiByteTable
[*src
] )) break;
1511 static int mbstowcs_decompose( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
,
1512 WCHAR
*dst
, int dstlen
)
1517 const WCHAR
*decomp
;
1518 unsigned int decomp_len
;
1520 if (info
->DBCSOffsets
)
1522 if (!dstlen
) /* compute length */
1524 for (len
= 0; srclen
; srclen
--, src
++, len
+= decomp_len
)
1526 if ((off
= info
->DBCSOffsets
[*src
]))
1528 if (srclen
> 1 && src
[1])
1532 ch
= info
->DBCSOffsets
[off
+ *src
];
1534 else ch
= info
->UniDefaultChar
;
1536 else ch
= info
->MultiByteTable
[*src
];
1537 get_decomposition( ch
, &decomp_len
);
1542 for (len
= dstlen
; srclen
&& len
; srclen
--, src
++, dst
+= decomp_len
, len
-= decomp_len
)
1544 if ((off
= info
->DBCSOffsets
[*src
]))
1546 if (srclen
> 1 && src
[1])
1550 ch
= info
->DBCSOffsets
[off
+ *src
];
1552 else ch
= info
->UniDefaultChar
;
1554 else ch
= info
->MultiByteTable
[*src
];
1556 if ((decomp
= get_decomposition( ch
, &decomp_len
)))
1558 if (len
< decomp_len
) break;
1559 memcpy( dst
, decomp
, decomp_len
* sizeof(WCHAR
) );
1566 if (!dstlen
) /* compute length */
1568 for (len
= 0; srclen
; srclen
--, src
++, len
+= decomp_len
)
1569 get_decomposition( info
->MultiByteTable
[*src
], &decomp_len
);
1573 for (len
= dstlen
; srclen
&& len
; srclen
--, src
++, dst
+= decomp_len
, len
-= decomp_len
)
1575 ch
= info
->MultiByteTable
[*src
];
1576 if ((decomp
= get_decomposition( ch
, &decomp_len
)))
1578 if (len
< decomp_len
) break;
1579 memcpy( dst
, decomp
, decomp_len
* sizeof(WCHAR
) );
1587 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1590 return dstlen
- len
;
1594 static int mbstowcs_sbcs( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
,
1595 WCHAR
*dst
, int dstlen
)
1597 const USHORT
*table
= info
->MultiByteTable
;
1600 if (!dstlen
) return srclen
;
1602 if (dstlen
< srclen
) /* buffer too small: fill it up to dstlen and return error */
1605 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1609 while (srclen
>= 16)
1611 dst
[0] = table
[src
[0]];
1612 dst
[1] = table
[src
[1]];
1613 dst
[2] = table
[src
[2]];
1614 dst
[3] = table
[src
[3]];
1615 dst
[4] = table
[src
[4]];
1616 dst
[5] = table
[src
[5]];
1617 dst
[6] = table
[src
[6]];
1618 dst
[7] = table
[src
[7]];
1619 dst
[8] = table
[src
[8]];
1620 dst
[9] = table
[src
[9]];
1621 dst
[10] = table
[src
[10]];
1622 dst
[11] = table
[src
[11]];
1623 dst
[12] = table
[src
[12]];
1624 dst
[13] = table
[src
[13]];
1625 dst
[14] = table
[src
[14]];
1626 dst
[15] = table
[src
[15]];
1632 /* now handle the remaining characters */
1637 case 15: dst
[-15] = table
[src
[-15]];
1638 case 14: dst
[-14] = table
[src
[-14]];
1639 case 13: dst
[-13] = table
[src
[-13]];
1640 case 12: dst
[-12] = table
[src
[-12]];
1641 case 11: dst
[-11] = table
[src
[-11]];
1642 case 10: dst
[-10] = table
[src
[-10]];
1643 case 9: dst
[-9] = table
[src
[-9]];
1644 case 8: dst
[-8] = table
[src
[-8]];
1645 case 7: dst
[-7] = table
[src
[-7]];
1646 case 6: dst
[-6] = table
[src
[-6]];
1647 case 5: dst
[-5] = table
[src
[-5]];
1648 case 4: dst
[-4] = table
[src
[-4]];
1649 case 3: dst
[-3] = table
[src
[-3]];
1650 case 2: dst
[-2] = table
[src
[-2]];
1651 case 1: dst
[-1] = table
[src
[-1]];
1658 static int mbstowcs_dbcs( const CPTABLEINFO
*info
, const unsigned char *src
, int srclen
,
1659 WCHAR
*dst
, int dstlen
)
1666 for (i
= 0; srclen
; i
++, src
++, srclen
--)
1667 if (info
->DBCSOffsets
[*src
] && srclen
> 1 && src
[1]) { src
++; srclen
--; }
1671 for (i
= dstlen
; srclen
&& i
; i
--, srclen
--, src
++, dst
++)
1673 if ((off
= info
->DBCSOffsets
[*src
]))
1675 if (srclen
> 1 && src
[1])
1679 *dst
= info
->DBCSOffsets
[off
+ *src
];
1681 else *dst
= info
->UniDefaultChar
;
1683 else *dst
= info
->MultiByteTable
[*src
];
1687 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1694 static int mbstowcs_codepage( UINT codepage
, DWORD flags
, const char *src
, int srclen
,
1695 WCHAR
*dst
, int dstlen
)
1697 CPTABLEINFO local_info
;
1698 const CPTABLEINFO
*info
= get_codepage_table( codepage
);
1699 const unsigned char *str
= (const unsigned char *)src
;
1703 SetLastError( ERROR_INVALID_PARAMETER
);
1706 if (flags
& ~(MB_PRECOMPOSED
| MB_COMPOSITE
| MB_USEGLYPHCHARS
| MB_ERR_INVALID_CHARS
))
1708 SetLastError( ERROR_INVALID_FLAGS
);
1712 if ((flags
& MB_USEGLYPHCHARS
) && info
->MultiByteTable
[256] == 256)
1715 local_info
.MultiByteTable
+= 257;
1718 if ((flags
& MB_ERR_INVALID_CHARS
) && check_invalid_chars( info
, str
, srclen
))
1720 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1724 if (flags
& MB_COMPOSITE
) return mbstowcs_decompose( info
, str
, srclen
, dst
, dstlen
);
1726 if (info
->DBCSOffsets
)
1727 return mbstowcs_dbcs( info
, str
, srclen
, dst
, dstlen
);
1729 return mbstowcs_sbcs( info
, str
, srclen
, dst
, dstlen
);
1733 static int wcstombs_cpsymbol( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
,
1734 const char *defchar
, BOOL
*used
)
1740 SetLastError( ERROR_INVALID_FLAGS
);
1743 if (defchar
|| used
)
1745 SetLastError( ERROR_INVALID_PARAMETER
);
1748 if (!dstlen
) return srclen
;
1749 len
= min( srclen
, dstlen
);
1750 for (i
= 0; i
< len
; i
++)
1752 if (src
[i
] < 0x20) dst
[i
] = src
[i
];
1753 else if (src
[i
] >= 0xf020 && src
[i
] < 0xf100) dst
[i
] = src
[i
] - 0xf000;
1756 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1762 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1769 static int wcstombs_utf7( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
,
1770 const char *defchar
, BOOL
*used
)
1772 static const char directly_encodable
[] =
1774 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0x00 - 0x0f */
1775 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */
1776 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* 0x20 - 0x2f */
1777 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x30 - 0x3f */
1778 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */
1779 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */
1780 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */
1781 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* 0x70 - 0x7a */
1783 #define ENCODABLE(ch) ((ch) <= 0x7a && directly_encodable[(ch)])
1785 static const char base64_encoding_table
[] =
1786 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1788 const WCHAR
*source_end
= src
+ srclen
;
1791 if (defchar
|| used
)
1793 SetLastError( ERROR_INVALID_PARAMETER
);
1798 SetLastError( ERROR_INVALID_FLAGS
);
1802 #define OUTPUT(ch) \
1806 if (pos >= dstlen) goto overflow; \
1812 while (src
< source_end
)
1820 else if (ENCODABLE(*src
))
1827 unsigned int offset
= 0, byte_pair
= 0;
1830 while (src
< source_end
&& !ENCODABLE(*src
))
1832 byte_pair
= (byte_pair
<< 16) | *src
;
1837 OUTPUT( base64_encoding_table
[(byte_pair
>> offset
) & 0x3f] );
1843 /* Windows won't create a padded base64 character if there's no room for the - sign
1844 * as well ; this is probably a bug in Windows */
1845 if (dstlen
> 0 && pos
+ 1 >= dstlen
) goto overflow
;
1846 byte_pair
<<= (6 - offset
);
1847 OUTPUT( base64_encoding_table
[byte_pair
& 0x3f] );
1849 /* Windows always explicitly terminates the base64 sequence
1850 even though RFC 2152 (page 3, rule 2) does not require this */
1857 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1864 static int wcstombs_utf8( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
,
1865 const char *defchar
, BOOL
*used
)
1870 if (defchar
|| used
)
1872 SetLastError( ERROR_INVALID_PARAMETER
);
1875 if (flags
& ~(WC_DISCARDNS
| WC_SEPCHARS
| WC_DEFAULTCHAR
| WC_ERR_INVALID_CHARS
|
1876 WC_COMPOSITECHECK
| WC_NO_BEST_FIT_CHARS
))
1878 SetLastError( ERROR_INVALID_FLAGS
);
1881 if (!dstlen
) dst
= NULL
;
1882 status
= RtlUnicodeToUTF8N( dst
, dstlen
, &reslen
, src
, srclen
* sizeof(WCHAR
) );
1883 if (status
== STATUS_SOME_NOT_MAPPED
)
1885 if (flags
& WC_ERR_INVALID_CHARS
)
1887 SetLastError( ERROR_NO_UNICODE_TRANSLATION
);
1891 else if (!set_ntstatus( status
)) reslen
= 0;
1896 static int wcstombs_sbcs( const CPTABLEINFO
*info
, const WCHAR
*src
, unsigned int srclen
,
1897 char *dst
, unsigned int dstlen
)
1899 const char *table
= info
->WideCharTable
;
1902 if (!dstlen
) return srclen
;
1904 if (dstlen
< srclen
)
1906 /* buffer too small: fill it up to dstlen and return error */
1908 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1912 while (srclen
>= 16)
1914 dst
[0] = table
[src
[0]];
1915 dst
[1] = table
[src
[1]];
1916 dst
[2] = table
[src
[2]];
1917 dst
[3] = table
[src
[3]];
1918 dst
[4] = table
[src
[4]];
1919 dst
[5] = table
[src
[5]];
1920 dst
[6] = table
[src
[6]];
1921 dst
[7] = table
[src
[7]];
1922 dst
[8] = table
[src
[8]];
1923 dst
[9] = table
[src
[9]];
1924 dst
[10] = table
[src
[10]];
1925 dst
[11] = table
[src
[11]];
1926 dst
[12] = table
[src
[12]];
1927 dst
[13] = table
[src
[13]];
1928 dst
[14] = table
[src
[14]];
1929 dst
[15] = table
[src
[15]];
1935 /* now handle remaining characters */
1940 case 15: dst
[-15] = table
[src
[-15]];
1941 case 14: dst
[-14] = table
[src
[-14]];
1942 case 13: dst
[-13] = table
[src
[-13]];
1943 case 12: dst
[-12] = table
[src
[-12]];
1944 case 11: dst
[-11] = table
[src
[-11]];
1945 case 10: dst
[-10] = table
[src
[-10]];
1946 case 9: dst
[-9] = table
[src
[-9]];
1947 case 8: dst
[-8] = table
[src
[-8]];
1948 case 7: dst
[-7] = table
[src
[-7]];
1949 case 6: dst
[-6] = table
[src
[-6]];
1950 case 5: dst
[-5] = table
[src
[-5]];
1951 case 4: dst
[-4] = table
[src
[-4]];
1952 case 3: dst
[-3] = table
[src
[-3]];
1953 case 2: dst
[-2] = table
[src
[-2]];
1954 case 1: dst
[-1] = table
[src
[-1]];
1961 static int wcstombs_dbcs( const CPTABLEINFO
*info
, const WCHAR
*src
, unsigned int srclen
,
1962 char *dst
, unsigned int dstlen
)
1964 const USHORT
*table
= info
->WideCharTable
;
1969 for (i
= 0; srclen
; src
++, srclen
--, i
++) if (table
[*src
] & 0xff00) i
++;
1973 for (i
= dstlen
; srclen
&& i
; i
--, srclen
--, src
++)
1975 if (table
[*src
] & 0xff00)
1977 if (i
== 1) break; /* do not output a partial char */
1979 *dst
++ = table
[*src
] >> 8;
1981 *dst
++ = (char)table
[*src
];
1985 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1992 static inline int is_valid_sbcs_mapping( const CPTABLEINFO
*info
, DWORD flags
, unsigned int wch
)
1994 const unsigned char *table
= info
->WideCharTable
;
1996 if (wch
>= 0x10000) return 0;
1997 if ((flags
& WC_NO_BEST_FIT_CHARS
) || table
[wch
] == info
->DefaultChar
)
1998 return (info
->MultiByteTable
[table
[wch
]] == wch
);
2003 static inline int is_valid_dbcs_mapping( const CPTABLEINFO
*info
, DWORD flags
, unsigned int wch
)
2005 const unsigned short *table
= info
->WideCharTable
;
2008 if (wch
>= 0x10000) return 0;
2010 if ((flags
& WC_NO_BEST_FIT_CHARS
) || ch
== info
->DefaultChar
)
2012 if (ch
>> 8) return info
->DBCSOffsets
[info
->DBCSOffsets
[ch
>> 8] + (ch
& 0xff)] == wch
;
2013 return info
->MultiByteTable
[ch
] == wch
;
2019 static int wcstombs_sbcs_slow( const CPTABLEINFO
*info
, DWORD flags
, const WCHAR
*src
, unsigned int srclen
,
2020 char *dst
, unsigned int dstlen
, const char *defchar
, BOOL
*used
)
2022 const char *table
= info
->WideCharTable
;
2023 const char def
= defchar
? *defchar
: (char)info
->DefaultChar
;
2027 unsigned int composed
;
2029 if (!used
) used
= &tmp
; /* avoid checking on every char */
2034 for (i
= 0; srclen
; i
++, src
++, srclen
--)
2037 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
2039 /* now check if we can use the composed char */
2040 if (is_valid_sbcs_mapping( info
, flags
, composed
))
2042 /* we have a good mapping, use it */
2047 /* no mapping for the composed char, check the other flags */
2048 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
2051 src
++; /* skip the non-spacing char */
2055 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
2060 /* WC_SEPCHARS is the default */
2062 if (!*used
) *used
= !is_valid_sbcs_mapping( info
, flags
, wch
);
2067 for (i
= dstlen
; srclen
&& i
; dst
++, i
--, src
++, srclen
--)
2070 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
2072 /* now check if we can use the composed char */
2073 if (is_valid_sbcs_mapping( info
, flags
, composed
))
2075 /* we have a good mapping, use it */
2076 *dst
= table
[composed
];
2081 /* no mapping for the composed char, check the other flags */
2082 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
2086 src
++; /* skip the non-spacing char */
2090 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
2095 /* WC_SEPCHARS is the default */
2099 if (!is_valid_sbcs_mapping( info
, flags
, wch
))
2107 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
2114 static int wcstombs_dbcs_slow( const CPTABLEINFO
*info
, DWORD flags
, const WCHAR
*src
, unsigned int srclen
,
2115 char *dst
, unsigned int dstlen
, const char *defchar
, BOOL
*used
)
2117 const USHORT
*table
= info
->WideCharTable
;
2118 WCHAR wch
, defchar_value
;
2119 unsigned int composed
;
2124 if (!defchar
[1]) defchar_value
= (unsigned char)defchar
[0];
2125 else defchar_value
= ((unsigned char)defchar
[0] << 8) | (unsigned char)defchar
[1];
2127 if (!used
) used
= &tmp
; /* avoid checking on every char */
2132 if (!defchar
&& !used
&& !(flags
& WC_COMPOSITECHECK
))
2134 for (i
= 0; srclen
; srclen
--, src
++, i
++) if (table
[*src
] & 0xff00) i
++;
2137 for (i
= 0; srclen
; srclen
--, src
++, i
++)
2140 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
2142 /* now check if we can use the composed char */
2143 if (is_valid_dbcs_mapping( info
, flags
, composed
))
2145 /* we have a good mapping for the composed char, use it */
2146 res
= table
[composed
];
2147 if (res
& 0xff00) i
++;
2152 /* no mapping for the composed char, check the other flags */
2153 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
2155 if (defchar_value
& 0xff00) i
++;
2157 src
++; /* skip the non-spacing char */
2161 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
2166 /* WC_SEPCHARS is the default */
2170 if (!is_valid_dbcs_mapping( info
, flags
, wch
))
2172 res
= defchar_value
;
2175 if (res
& 0xff00) i
++;
2181 for (i
= dstlen
; srclen
&& i
; i
--, srclen
--, src
++)
2184 if ((flags
& WC_COMPOSITECHECK
) && (srclen
> 1) && (composed
= compose_chars( src
[0], src
[1] )))
2186 /* now check if we can use the composed char */
2187 if (is_valid_dbcs_mapping( info
, flags
, composed
))
2189 /* we have a good mapping for the composed char, use it */
2190 res
= table
[composed
];
2195 /* no mapping for the composed char, check the other flags */
2196 if (flags
& WC_DEFAULTCHAR
) /* use the default char instead */
2198 res
= defchar_value
;
2200 src
++; /* skip the non-spacing char */
2204 if (flags
& WC_DISCARDNS
) /* skip the second char of the composition */
2209 /* WC_SEPCHARS is the default */
2213 if (!is_valid_dbcs_mapping( info
, flags
, wch
))
2215 res
= defchar_value
;
2222 if (i
== 1) break; /* do not output a partial char */
2230 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
2237 static int wcstombs_codepage( UINT codepage
, DWORD flags
, const WCHAR
*src
, int srclen
,
2238 char *dst
, int dstlen
, const char *defchar
, BOOL
*used
)
2240 const CPTABLEINFO
*info
= get_codepage_table( codepage
);
2244 SetLastError( ERROR_INVALID_PARAMETER
);
2247 if (flags
& ~(WC_DISCARDNS
| WC_SEPCHARS
| WC_DEFAULTCHAR
| WC_ERR_INVALID_CHARS
|
2248 WC_COMPOSITECHECK
| WC_NO_BEST_FIT_CHARS
))
2250 SetLastError( ERROR_INVALID_FLAGS
);
2253 if (flags
|| defchar
|| used
)
2255 if (!defchar
) defchar
= (const char *)&info
->DefaultChar
;
2256 if (info
->DBCSOffsets
)
2257 return wcstombs_dbcs_slow( info
, flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
2259 return wcstombs_sbcs_slow( info
, flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
2261 if (info
->DBCSOffsets
)
2262 return wcstombs_dbcs( info
, src
, srclen
, dst
, dstlen
);
2264 return wcstombs_sbcs( info
, src
, srclen
, dst
, dstlen
);
2268 static int get_sortkey( DWORD flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
)
2270 WCHAR dummy
[4]; /* no decomposition is larger than 4 chars */
2273 const WCHAR
*src_save
= src
;
2274 int srclen_save
= srclen
;
2276 key_len
[0] = key_len
[1] = key_len
[2] = key_len
[3] = 0;
2277 for (; srclen
; srclen
--, src
++)
2279 unsigned int i
, decomposed_len
= 1;/*wine_decompose(*src, dummy, 4);*/
2283 for (i
= 0; i
< decomposed_len
; i
++)
2285 WCHAR wch
= dummy
[i
];
2288 if ((flags
& NORM_IGNORESYMBOLS
) &&
2289 (get_char_type( CT_CTYPE1
, wch
) & (C1_PUNCT
| C1_SPACE
)))
2292 if (flags
& NORM_IGNORECASE
) wch
= casemap( nls_info
.LowerCaseTable
, wch
);
2294 ce
= collation_table
[collation_table
[collation_table
[wch
>> 8] + ((wch
>> 4) & 0x0f)] + (wch
& 0xf)];
2295 if (ce
!= (unsigned int)-1)
2297 if (ce
>> 16) key_len
[0] += 2;
2298 if ((ce
>> 8) & 0xff) key_len
[1]++;
2299 if ((ce
>> 4) & 0x0f) key_len
[2]++;
2302 if (wch
>> 8) key_len
[3]++;
2309 if (wch
>> 8) key_len
[0]++;
2310 if (wch
& 0xff) key_len
[0]++;
2316 if (!dstlen
) /* compute length */
2317 /* 4 * '\1' + key length */
2318 return key_len
[0] + key_len
[1] + key_len
[2] + key_len
[3] + 4;
2320 if (dstlen
< key_len
[0] + key_len
[1] + key_len
[2] + key_len
[3] + 4 + 1)
2321 return 0; /* overflow */
2324 srclen
= srclen_save
;
2327 key_ptr
[1] = key_ptr
[0] + key_len
[0] + 1;
2328 key_ptr
[2] = key_ptr
[1] + key_len
[1] + 1;
2329 key_ptr
[3] = key_ptr
[2] + key_len
[2] + 1;
2331 for (; srclen
; srclen
--, src
++)
2333 unsigned int i
, decomposed_len
= 1;/*wine_decompose(*src, dummy, 4);*/
2337 for (i
= 0; i
< decomposed_len
; i
++)
2339 WCHAR wch
= dummy
[i
];
2342 if ((flags
& NORM_IGNORESYMBOLS
) &&
2343 (get_char_type( CT_CTYPE1
, wch
) & (C1_PUNCT
| C1_SPACE
)))
2346 if (flags
& NORM_IGNORECASE
) wch
= casemap( nls_info
.LowerCaseTable
, wch
);
2348 ce
= collation_table
[collation_table
[collation_table
[wch
>> 8] + ((wch
>> 4) & 0x0f)] + (wch
& 0xf)];
2349 if (ce
!= (unsigned int)-1)
2352 if ((key
= ce
>> 16))
2354 *key_ptr
[0]++ = key
>> 8;
2355 *key_ptr
[0]++ = key
& 0xff;
2357 /* make key 1 start from 2 */
2358 if ((key
= (ce
>> 8) & 0xff)) *key_ptr
[1]++ = key
+ 1;
2359 /* make key 2 start from 2 */
2360 if ((key
= (ce
>> 4) & 0x0f)) *key_ptr
[2]++ = key
+ 1;
2361 /* key 3 is always a character code */
2364 if (wch
>> 8) *key_ptr
[3]++ = wch
>> 8;
2365 if (wch
& 0xff) *key_ptr
[3]++ = wch
& 0xff;
2370 *key_ptr
[0]++ = 0xff;
2371 *key_ptr
[0]++ = 0xfe;
2372 if (wch
>> 8) *key_ptr
[0]++ = wch
>> 8;
2373 if (wch
& 0xff) *key_ptr
[0]++ = wch
& 0xff;
2384 return key_ptr
[3] - dst
;
2388 /* compose a full-width katakana. return consumed source characters. */
2389 static int compose_katakana( const WCHAR
*src
, int srclen
, WCHAR
*dst
)
2391 static const BYTE katakana_map
[] =
2393 /* */ 0x02, 0x0c, 0x0d, 0x01, 0xfb, 0xf2, 0xa1, /* U+FF61- */
2394 0xa3, 0xa5, 0xa7, 0xa9, 0xe3, 0xe5, 0xe7, 0xc3, /* U+FF68- */
2395 0xfc, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xab, 0xad, /* U+FF70- */
2396 0xaf, 0xb1, 0xb3, 0xb5, 0xb7, 0xb9, 0xbb, 0xbd, /* U+FF78- */
2397 0xbf, 0xc1, 0xc4, 0xc6, 0xc8, 0xca, 0xcb, 0xcc, /* U+FF80- */
2398 0xcd, 0xce, 0xcf, 0xd2, 0xd5, 0xd8, 0xdb, 0xde, /* U+FF88- */
2399 0xdf, 0xe0, 0xe1, 0xe2, 0xe4, 0xe6, 0xe8, 0xe9, /* U+FF90- */
2400 0xea, 0xeb, 0xec, 0xed, 0xef, 0xf3, 0x99, 0x9a, /* U+FF98- */
2405 if (!dst
) dst
= &dummy
;
2419 shift
= *src
- 0xff61;
2420 if (shift
< 0 || shift
>= ARRAY_SIZE( katakana_map
)) return 0;
2421 *dst
= katakana_map
[shift
] | 0x3000;
2425 if (srclen
<= 1) return 1;
2429 case 0xff9e: /* datakuten (voiced sound) */
2430 if ((*src
>= 0xff76 && *src
<= 0xff84) || (*src
>= 0xff8a && *src
<= 0xff8e) || *src
== 0x30fd)
2432 else if (*src
== 0xff73)
2433 *dst
= 0x30f4; /* KATAKANA LETTER VU */
2434 else if (*src
== 0xff9c)
2435 *dst
= 0x30f7; /* KATAKANA LETTER VA */
2436 else if (*src
== 0x30f0)
2437 *dst
= 0x30f8; /* KATAKANA LETTER VI */
2438 else if (*src
== 0x30f1)
2439 *dst
= 0x30f9; /* KATAKANA LETTER VE */
2440 else if (*src
== 0xff66)
2441 *dst
= 0x30fa; /* KATAKANA LETTER VO */
2445 case 0xff9f: /* handakuten (semi-voiced sound) */
2446 if (*src
>= 0xff8a && *src
<= 0xff8e)
2457 /* map one or two half-width characters to one full-width character */
2458 static int map_to_fullwidth( const WCHAR
*src
, int srclen
, WCHAR
*dst
)
2462 if (*src
<= '~' && *src
> ' ' && *src
!= '\\')
2463 *dst
= *src
- 0x20 + 0xff00;
2464 else if (*src
== ' ')
2466 else if (*src
<= 0x00af && *src
>= 0x00a2)
2468 static const BYTE misc_symbols_table
[] =
2470 0xe0, 0xe1, 0x00, 0xe5, 0xe4, 0x00, 0x00, /* U+00A2- */
2471 0x00, 0x00, 0x00, 0xe2, 0x00, 0x00, 0xe3 /* U+00A9- */
2473 if (misc_symbols_table
[*src
- 0x00a2])
2474 *dst
= misc_symbols_table
[*src
- 0x00a2] | 0xff00;
2478 else if (*src
== 0x20a9) /* WON SIGN */
2480 else if ((n
= compose_katakana(src
, srclen
, dst
)) > 0)
2482 else if (*src
>= 0xffa0 && *src
<= 0xffdc)
2484 static const BYTE hangul_mapping_table
[] =
2486 0x64, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* U+FFA0- */
2487 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* U+FFA8- */
2488 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* U+FFB0- */
2489 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x00, /* U+FFB8- */
2490 0x00, 0x00, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, /* U+FFC0- */
2491 0x00, 0x00, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, /* U+FFC8- */
2492 0x00, 0x00, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, /* U+FFD0- */
2493 0x00, 0x00, 0x61, 0x62, 0x63 /* U+FFD8- */
2496 if (hangul_mapping_table
[*src
- 0xffa0])
2497 *dst
= hangul_mapping_table
[*src
- 0xffa0] | 0x3100;
2507 /* decompose a full-width katakana character into one or two half-width characters. */
2508 static int decompose_katakana( WCHAR c
, WCHAR
*dst
, int dstlen
)
2510 static const BYTE katakana_map
[] =
2512 /* */ 0x9e, 0x9f, 0x9e, 0x9f, 0x00, 0x00, 0x00, /* U+3099- */
2513 0x00, 0x67, 0x71, 0x68, 0x72, 0x69, 0x73, 0x6a, /* U+30a1- */
2514 0x74, 0x6b, 0x75, 0x76, 0x01, 0x77, 0x01, 0x78, /* U+30a8- */
2515 0x01, 0x79, 0x01, 0x7a, 0x01, 0x7b, 0x01, 0x7c, /* U+30b0- */
2516 0x01, 0x7d, 0x01, 0x7e, 0x01, 0x7f, 0x01, 0x80, /* U+30b8- */
2517 0x01, 0x81, 0x01, 0x6f, 0x82, 0x01, 0x83, 0x01, /* U+30c0- */
2518 0x84, 0x01, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, /* U+30c8- */
2519 0x01, 0x02, 0x8b, 0x01, 0x02, 0x8c, 0x01, 0x02, /* U+30d0- */
2520 0x8d, 0x01, 0x02, 0x8e, 0x01, 0x02, 0x8f, 0x90, /* U+30d8- */
2521 0x91, 0x92, 0x93, 0x6c, 0x94, 0x6d, 0x95, 0x6e, /* U+30e0- */
2522 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x00, 0x9c, /* U+30e8- */
2523 0x00, 0x00, 0x66, 0x9d, 0x4e, 0x00, 0x00, 0x08, /* U+30f0- */
2524 0x58, 0x58, 0x08, 0x65, 0x70, 0x00, 0x51 /* U+30f8- */
2526 int len
= 0, shift
= c
- 0x3099;
2529 if (shift
< 0 || shift
>= ARRAY_SIZE( katakana_map
)) return 0;
2531 k
= katakana_map
[shift
];
2534 if (dstlen
> 0) *dst
= c
;
2539 if (dstlen
> 0) *dst
= k
| 0xff00;
2546 dst
[0] = (k
> 0x50) ? (c
- (k
& 0xf)) : (katakana_map
[shift
- k
] | 0xff00);
2547 dst
[1] = (k
== 2) ? 0xff9f : 0xff9e;
2554 /* map single full-width character to single or double half-width characters. */
2555 static int map_to_halfwidth( WCHAR c
, WCHAR
*dst
, int dstlen
)
2557 int n
= decompose_katakana( c
, dst
, dstlen
);
2558 if (n
> 0) return n
;
2562 else if (c
== 0x3001)
2564 else if (c
== 0x3002)
2566 else if (c
== 0x300c || c
== 0x300d)
2567 *dst
= (c
- 0x300c) + 0xff62;
2568 else if (c
>= 0x3131 && c
<= 0x3163)
2570 *dst
= c
- 0x3131 + 0xffa1;
2571 if (*dst
>= 0xffbf) *dst
+= 3;
2572 if (*dst
>= 0xffc8) *dst
+= 2;
2573 if (*dst
>= 0xffd0) *dst
+= 2;
2574 if (*dst
>= 0xffd8) *dst
+= 2;
2576 else if (c
== 0x3164)
2578 else if (c
== 0x2019)
2580 else if (c
== 0x201d)
2582 else if (c
> 0xff00 && c
< 0xff5f && c
!= 0xff3c)
2583 *dst
= c
- 0xff00 + 0x20;
2584 else if (c
>= 0xffe0 && c
<= 0xffe6)
2586 static const WCHAR misc_symbol_map
[] = { 0x00a2, 0x00a3, 0x00ac, 0x00af, 0x00a6, 0x00a5, 0x20a9 };
2587 *dst
= misc_symbol_map
[c
- 0xffe0];
2596 /* 32-bit collation element table format:
2597 * unicode weight - high 16 bit, diacritic weight - high 8 bit of low 16 bit,
2598 * case weight - high 4 bit of low 8 bit.
2601 enum weight
{ UNICODE_WEIGHT
, DIACRITIC_WEIGHT
, CASE_WEIGHT
};
2603 static unsigned int get_weight( WCHAR ch
, enum weight type
)
2607 ret
= collation_table
[collation_table
[collation_table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0xf)];
2608 if (ret
== ~0u) return ch
;
2612 case UNICODE_WEIGHT
: return ret
>> 16;
2613 case DIACRITIC_WEIGHT
: return (ret
>> 8) & 0xff;
2614 case CASE_WEIGHT
: return (ret
>> 4) & 0x0f;
2620 static void inc_str_pos( const WCHAR
**str
, int *len
, unsigned int *dpos
, unsigned int *dlen
)
2632 static int compare_weights(int flags
, const WCHAR
*str1
, int len1
,
2633 const WCHAR
*str2
, int len2
, enum weight type
)
2635 unsigned int ce1
, ce2
, dpos1
= 0, dpos2
= 0, dlen1
= 0, dlen2
= 0;
2636 const WCHAR
*dstr1
= NULL
, *dstr2
= NULL
;
2638 while (len1
> 0 && len2
> 0)
2640 if (!dlen1
&& !(dstr1
= get_decomposition( *str1
, &dlen1
))) dstr1
= str1
;
2641 if (!dlen2
&& !(dstr2
= get_decomposition( *str2
, &dlen2
))) dstr2
= str2
;
2643 if (flags
& NORM_IGNORESYMBOLS
)
2646 /* FIXME: not tested */
2647 if (get_char_type( CT_CTYPE1
, dstr1
[dpos1
] ) & (C1_PUNCT
| C1_SPACE
))
2649 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2652 if (get_char_type( CT_CTYPE1
, dstr2
[dpos2
] ) & (C1_PUNCT
| C1_SPACE
))
2654 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2660 /* hyphen and apostrophe are treated differently depending on
2661 * whether SORT_STRINGSORT specified or not
2663 if (type
== UNICODE_WEIGHT
&& !(flags
& SORT_STRINGSORT
))
2665 if (dstr1
[dpos1
] == '-' || dstr1
[dpos1
] == '\'')
2667 if (dstr2
[dpos2
] != '-' && dstr2
[dpos2
] != '\'')
2669 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2673 else if (dstr2
[dpos2
] == '-' || dstr2
[dpos2
] == '\'')
2675 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2680 ce1
= get_weight( dstr1
[dpos1
], type
);
2683 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2686 ce2
= get_weight( dstr2
[dpos2
], type
);
2689 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2693 if (ce1
- ce2
) return ce1
- ce2
;
2695 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2696 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2700 if (!dlen1
&& !(dstr1
= get_decomposition( *str1
, &dlen1
))) dstr1
= str1
;
2701 ce1
= get_weight( dstr1
[dpos1
], type
);
2703 inc_str_pos( &str1
, &len1
, &dpos1
, &dlen1
);
2707 if (!dlen2
&& !(dstr2
= get_decomposition( *str2
, &dlen2
))) dstr2
= str2
;
2708 ce2
= get_weight( dstr2
[dpos2
], type
);
2710 inc_str_pos( &str2
, &len2
, &dpos2
, &dlen2
);
2716 static const struct geoinfo
*get_geoinfo_ptr( GEOID geoid
)
2718 int min
= 0, max
= ARRAY_SIZE( geoinfodata
)-1;
2722 int n
= (min
+ max
)/2;
2723 const struct geoinfo
*ptr
= &geoinfodata
[n
];
2724 if (geoid
== ptr
->id
) /* we don't need empty entries */
2725 return *ptr
->iso2W
? ptr
: NULL
;
2726 if (ptr
->id
> geoid
) max
= n
-1;
2733 static int compare_tzdate( const TIME_FIELDS
*tf
, const SYSTEMTIME
*compare
)
2735 static const int month_lengths
[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
2736 int first
, last
, limit
, dayinsecs
;
2738 if (tf
->Month
< compare
->wMonth
) return -1; /* We are in a month before the date limit. */
2739 if (tf
->Month
> compare
->wMonth
) return 1; /* We are in a month after the date limit. */
2741 /* if year is 0 then date is in day-of-week format, otherwise
2742 * it's absolute date.
2744 if (!compare
->wYear
)
2746 /* wDay is interpreted as number of the week in the month
2747 * 5 means: the last week in the month */
2748 /* calculate the day of the first DayOfWeek in the month */
2749 first
= (6 + compare
->wDayOfWeek
- tf
->Weekday
+ tf
->Day
) % 7 + 1;
2750 /* check needed for the 5th weekday of the month */
2751 last
= month_lengths
[tf
->Month
- 1] +
2752 (tf
->Month
== 2 && (!(tf
->Year
% 4) && (tf
->Year
% 100 || !(tf
->Year
% 400))));
2753 limit
= first
+ 7 * (compare
->wDay
- 1);
2754 if (limit
> last
) limit
-= 7;
2756 else limit
= compare
->wDay
;
2758 limit
= ((limit
* 24 + compare
->wHour
) * 60 + compare
->wMinute
) * 60;
2759 dayinsecs
= ((tf
->Day
* 24 + tf
->Hour
) * 60 + tf
->Minute
) * 60 + tf
->Second
;
2760 return dayinsecs
- limit
;
2764 static DWORD
get_timezone_id( const TIME_ZONE_INFORMATION
*info
, LARGE_INTEGER time
, BOOL is_local
)
2767 BOOL before_standard_date
, after_daylight_date
;
2771 if (!info
->DaylightDate
.wMonth
) return TIME_ZONE_ID_UNKNOWN
;
2773 /* if year is 0 then date is in day-of-week format, otherwise it's absolute date */
2774 if (info
->StandardDate
.wMonth
== 0 ||
2775 (info
->StandardDate
.wYear
== 0 &&
2776 (info
->StandardDate
.wDay
< 1 || info
->StandardDate
.wDay
> 5 ||
2777 info
->DaylightDate
.wDay
< 1 || info
->DaylightDate
.wDay
> 5)))
2779 SetLastError( ERROR_INVALID_PARAMETER
);
2780 return TIME_ZONE_ID_INVALID
;
2783 if (!is_local
) time
.QuadPart
-= info
->Bias
* (LONGLONG
)600000000;
2784 RtlTimeToTimeFields( &time
, &tf
);
2788 t2
.QuadPart
= time
.QuadPart
- info
->DaylightBias
* (LONGLONG
)600000000;
2789 RtlTimeToTimeFields( &t2
, &tf
);
2791 if (tf
.Year
== year
)
2792 before_standard_date
= compare_tzdate( &tf
, &info
->StandardDate
) < 0;
2794 before_standard_date
= tf
.Year
< year
;
2798 t2
.QuadPart
= time
.QuadPart
- info
->StandardBias
* (LONGLONG
)600000000;
2799 RtlTimeToTimeFields( &t2
, &tf
);
2801 if (tf
.Year
== year
)
2802 after_daylight_date
= compare_tzdate( &tf
, &info
->DaylightDate
) >= 0;
2804 after_daylight_date
= tf
.Year
> year
;
2806 if (info
->DaylightDate
.wMonth
< info
->StandardDate
.wMonth
) /* Northern hemisphere */
2808 if (before_standard_date
&& after_daylight_date
) return TIME_ZONE_ID_DAYLIGHT
;
2810 else /* Down south */
2812 if (before_standard_date
|| after_daylight_date
) return TIME_ZONE_ID_DAYLIGHT
;
2814 return TIME_ZONE_ID_STANDARD
;
2818 /* Note: the Internal_ functions are not documented. The number of parameters
2819 * should be correct, but their exact meaning may not.
2822 /******************************************************************************
2823 * Internal_EnumCalendarInfo (kernelbase.@)
2825 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumCalendarInfo( CALINFO_ENUMPROCW proc
, LCID lcid
, CALID id
,
2826 CALTYPE type
, BOOL unicode
, BOOL ex
,
2827 BOOL exex
, LPARAM lparam
)
2830 CALID calendars
[2] = { id
};
2835 SetLastError( ERROR_INVALID_PARAMETER
);
2839 if (id
== ENUM_ALL_CALENDARS
)
2841 if (!GetLocaleInfoW( lcid
, LOCALE_ICALENDARTYPE
| LOCALE_RETURN_NUMBER
,
2842 (WCHAR
*)&calendars
[0], sizeof(calendars
[0]) / sizeof(WCHAR
) )) return FALSE
;
2843 if (!GetLocaleInfoW( lcid
, LOCALE_IOPTIONALCALENDAR
| LOCALE_RETURN_NUMBER
,
2844 (WCHAR
*)&calendars
[1], sizeof(calendars
[1]) / sizeof(WCHAR
) )) calendars
[1] = 0;
2847 for (i
= 0; i
< ARRAY_SIZE(calendars
) && calendars
[i
]; i
++)
2850 if (type
& CAL_RETURN_NUMBER
)
2851 ret
= GetCalendarInfoW( lcid
, id
, type
, NULL
, 0, (LPDWORD
)buffer
);
2853 ret
= GetCalendarInfoW( lcid
, id
, type
, buffer
, ARRAY_SIZE(buffer
), NULL
);
2857 ret
= GetCalendarInfoW( lcid
, id
, type
, bufW
, ARRAY_SIZE(bufW
), NULL
);
2858 if (ret
) WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, (char *)buffer
, sizeof(buffer
), NULL
, NULL
);
2863 if (exex
) ret
= ((CALINFO_ENUMPROCEXEX
)proc
)( buffer
, id
, NULL
, lparam
);
2864 else if (ex
) ret
= ((CALINFO_ENUMPROCEXW
)proc
)( buffer
, id
);
2865 else ret
= proc( buffer
);
2873 /**************************************************************************
2874 * Internal_EnumDateFormats (kernelbase.@)
2876 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumDateFormats( DATEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
,
2877 BOOL unicode
, BOOL ex
, BOOL exex
, LPARAM lparam
)
2886 SetLastError( ERROR_INVALID_PARAMETER
);
2889 if (!GetLocaleInfoW( lcid
, LOCALE_ICALENDARTYPE
|LOCALE_RETURN_NUMBER
,
2890 (LPWSTR
)&cal_id
, sizeof(cal_id
)/sizeof(WCHAR
) ))
2893 switch (flags
& ~LOCALE_USE_CP_ACP
)
2896 case DATE_SHORTDATE
:
2897 lctype
= LOCALE_SSHORTDATE
;
2900 lctype
= LOCALE_SLONGDATE
;
2902 case DATE_YEARMONTH
:
2903 lctype
= LOCALE_SYEARMONTH
;
2906 FIXME( "unknown date format 0x%08lx\n", flags
);
2907 SetLastError( ERROR_INVALID_PARAMETER
);
2911 lctype
|= flags
& LOCALE_USE_CP_ACP
;
2913 ret
= GetLocaleInfoW( lcid
, lctype
, buffer
, ARRAY_SIZE(buffer
) );
2915 ret
= GetLocaleInfoA( lcid
, lctype
, (char *)buffer
, sizeof(buffer
) );
2919 if (exex
) ((DATEFMT_ENUMPROCEXEX
)proc
)( buffer
, cal_id
, lparam
);
2920 else if (ex
) ((DATEFMT_ENUMPROCEXW
)proc
)( buffer
, cal_id
);
2921 else proc( buffer
);
2927 /******************************************************************************
2928 * Internal_EnumLanguageGroupLocales (kernelbase.@)
2930 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumLanguageGroupLocales( LANGGROUPLOCALE_ENUMPROCW proc
, LGRPID id
,
2931 DWORD flags
, LONG_PTR param
, BOOL unicode
)
2933 WCHAR name
[10], value
[10];
2934 DWORD name_len
, value_len
, type
, index
= 0, alt
= 0;
2938 if (!proc
|| id
< LGRPID_WESTERN_EUROPE
|| id
> LGRPID_ARMENIAN
)
2940 SetLastError( ERROR_INVALID_PARAMETER
);
2944 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
2945 if (RegOpenKeyExW( key
, L
"Alternate Sorts", 0, KEY_READ
, &altkey
)) altkey
= 0;
2949 name_len
= ARRAY_SIZE(name
);
2950 value_len
= sizeof(value
);
2951 if (RegEnumValueW( alt
? altkey
: key
, index
++, name
, &name_len
, NULL
,
2952 &type
, (BYTE
*)value
, &value_len
))
2958 if (type
!= REG_SZ
) continue;
2959 if (id
!= wcstoul( value
, NULL
, 16 )) continue;
2960 lcid
= wcstoul( name
, NULL
, 16 );
2964 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
2965 if (!((LANGGROUPLOCALE_ENUMPROCA
)proc
)( id
, lcid
, nameA
, param
)) break;
2967 else if (!proc( id
, lcid
, name
, param
)) break;
2969 RegCloseKey( altkey
);
2975 /***********************************************************************
2976 * Internal_EnumSystemCodePages (kernelbase.@)
2978 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumSystemCodePages( CODEPAGE_ENUMPROCW proc
, DWORD flags
,
2982 DWORD name_len
, type
, index
= 0;
2985 if (RegOpenKeyExW( nls_key
, L
"Codepage", 0, KEY_READ
, &key
)) return FALSE
;
2989 name_len
= ARRAY_SIZE(name
);
2990 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
2991 if (type
!= REG_SZ
) continue;
2992 if (!wcstoul( name
, NULL
, 10 )) continue;
2996 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
2997 if (!((CODEPAGE_ENUMPROCA
)proc
)( nameA
)) break;
2999 else if (!proc( name
)) break;
3006 /******************************************************************************
3007 * Internal_EnumSystemLanguageGroups (kernelbase.@)
3009 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumSystemLanguageGroups( LANGUAGEGROUP_ENUMPROCW proc
,
3010 DWORD flags
, LONG_PTR param
, BOOL unicode
)
3012 WCHAR name
[10], value
[10], descr
[80];
3013 DWORD name_len
, value_len
, type
, index
= 0;
3019 SetLastError( ERROR_INVALID_PARAMETER
);
3026 flags
= LGRPID_INSTALLED
;
3028 case LGRPID_INSTALLED
:
3029 case LGRPID_SUPPORTED
:
3032 SetLastError( ERROR_INVALID_FLAGS
);
3036 if (RegOpenKeyExW( nls_key
, L
"Language Groups", 0, KEY_READ
, &key
)) return FALSE
;
3040 name_len
= ARRAY_SIZE(name
);
3041 value_len
= sizeof(value
);
3042 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, (BYTE
*)value
, &value_len
)) break;
3043 if (type
!= REG_SZ
) continue;
3045 id
= wcstoul( name
, NULL
, 16 );
3047 if (!(flags
& LGRPID_SUPPORTED
) && !wcstoul( value
, NULL
, 10 )) continue;
3048 if (!LoadStringW( kernel32_handle
, 0x2000 + id
, descr
, ARRAY_SIZE(descr
) )) descr
[0] = 0;
3049 TRACE( "%p: %lu %s %s %lx %Ix\n", proc
, id
, debugstr_w(name
), debugstr_w(descr
), flags
, param
);
3052 char nameA
[10], descrA
[80];
3053 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
3054 WideCharToMultiByte( CP_ACP
, 0, descr
, -1, descrA
, sizeof(descrA
), NULL
, NULL
);
3055 if (!((LANGUAGEGROUP_ENUMPROCA
)proc
)( id
, nameA
, descrA
, flags
, param
)) break;
3057 else if (!proc( id
, name
, descr
, flags
, param
)) break;
3064 /**************************************************************************
3065 * Internal_EnumTimeFormats (kernelbase.@)
3067 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumTimeFormats( TIMEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
,
3068 BOOL unicode
, BOOL ex
, LPARAM lparam
)
3076 SetLastError( ERROR_INVALID_PARAMETER
);
3079 switch (flags
& ~LOCALE_USE_CP_ACP
)
3082 lctype
= LOCALE_STIMEFORMAT
;
3084 case TIME_NOSECONDS
:
3085 lctype
= LOCALE_SSHORTTIME
;
3088 FIXME( "Unknown time format %lx\n", flags
);
3089 SetLastError( ERROR_INVALID_PARAMETER
);
3093 lctype
|= flags
& LOCALE_USE_CP_ACP
;
3095 ret
= GetLocaleInfoW( lcid
, lctype
, buffer
, ARRAY_SIZE(buffer
) );
3097 ret
= GetLocaleInfoA( lcid
, lctype
, (char *)buffer
, sizeof(buffer
) );
3101 if (ex
) ((TIMEFMT_ENUMPROCEX
)proc
)( buffer
, lparam
);
3102 else proc( buffer
);
3108 /******************************************************************************
3109 * Internal_EnumUILanguages (kernelbase.@)
3111 BOOL WINAPI DECLSPEC_HOTPATCH
Internal_EnumUILanguages( UILANGUAGE_ENUMPROCW proc
, DWORD flags
,
3112 LONG_PTR param
, BOOL unicode
)
3115 DWORD name_len
, type
, index
= 0;
3120 SetLastError( ERROR_INVALID_PARAMETER
);
3123 if (flags
& ~MUI_LANGUAGE_ID
)
3125 SetLastError( ERROR_INVALID_FLAGS
);
3129 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3133 name_len
= ARRAY_SIZE(name
);
3134 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
3135 if (type
!= REG_SZ
) continue;
3136 if (!wcstoul( name
, NULL
, 16 )) continue;
3140 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
);
3141 if (!((UILANGUAGE_ENUMPROCA
)proc
)( nameA
, param
)) break;
3143 else if (!proc( name
, param
)) break;
3150 /******************************************************************************
3151 * CompareStringEx (kernelbase.@)
3153 INT WINAPI
CompareStringEx( const WCHAR
*locale
, DWORD flags
, const WCHAR
*str1
, int len1
,
3154 const WCHAR
*str2
, int len2
, NLSVERSIONINFO
*version
,
3155 void *reserved
, LPARAM handle
)
3157 DWORD supported_flags
= NORM_IGNORECASE
| NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
| SORT_STRINGSORT
|
3158 NORM_IGNOREKANATYPE
| NORM_IGNOREWIDTH
| LOCALE_USE_CP_ACP
;
3159 DWORD semistub_flags
= NORM_LINGUISTIC_CASING
| LINGUISTIC_IGNORECASE
| LINGUISTIC_IGNOREDIACRITIC
|
3160 SORT_DIGITSASNUMBERS
| 0x10000000;
3161 /* 0x10000000 is related to diacritics in Arabic, Japanese, and Hebrew */
3165 if (version
) FIXME( "unexpected version parameter\n" );
3166 if (reserved
) FIXME( "unexpected reserved value\n" );
3167 if (handle
) FIXME( "unexpected handle\n" );
3171 SetLastError( ERROR_INVALID_PARAMETER
);
3175 if (flags
& ~(supported_flags
| semistub_flags
))
3177 SetLastError( ERROR_INVALID_FLAGS
);
3181 if (flags
& semistub_flags
)
3183 if (!once
++) FIXME( "semi-stub behavior for flag(s) 0x%lx\n", flags
& semistub_flags
);
3186 if (len1
< 0) len1
= lstrlenW(str1
);
3187 if (len2
< 0) len2
= lstrlenW(str2
);
3189 ret
= compare_weights( flags
, str1
, len1
, str2
, len2
, UNICODE_WEIGHT
);
3192 if (!(flags
& NORM_IGNORENONSPACE
))
3193 ret
= compare_weights( flags
, str1
, len1
, str2
, len2
, DIACRITIC_WEIGHT
);
3194 if (!ret
&& !(flags
& NORM_IGNORECASE
))
3195 ret
= compare_weights( flags
, str1
, len1
, str2
, len2
, CASE_WEIGHT
);
3197 if (!ret
) return CSTR_EQUAL
;
3198 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
3202 /******************************************************************************
3203 * CompareStringA (kernelbase.@)
3205 INT WINAPI DECLSPEC_HOTPATCH
CompareStringA( LCID lcid
, DWORD flags
, const char *str1
, int len1
,
3206 const char *str2
, int len2
)
3208 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
3209 WCHAR
*buf2W
= buf1W
+ 130;
3210 LPWSTR str1W
, str2W
;
3211 INT len1W
= 0, len2W
= 0, ret
;
3212 UINT locale_cp
= CP_ACP
;
3216 SetLastError( ERROR_INVALID_PARAMETER
);
3220 if (flags
& SORT_DIGITSASNUMBERS
)
3222 SetLastError( ERROR_INVALID_FLAGS
);
3226 if (len1
< 0) len1
= strlen(str1
);
3227 if (len2
< 0) len2
= strlen(str2
);
3229 locale_cp
= get_lcid_codepage( lcid
, flags
);
3232 if (len1
<= 130) len1W
= MultiByteToWideChar( locale_cp
, 0, str1
, len1
, buf1W
, 130 );
3233 if (len1W
) str1W
= buf1W
;
3236 len1W
= MultiByteToWideChar( locale_cp
, 0, str1
, len1
, NULL
, 0 );
3237 str1W
= HeapAlloc( GetProcessHeap(), 0, len1W
* sizeof(WCHAR
) );
3240 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3243 MultiByteToWideChar( locale_cp
, 0, str1
, len1
, str1W
, len1W
);
3254 if (len2
<= 130) len2W
= MultiByteToWideChar( locale_cp
, 0, str2
, len2
, buf2W
, 130 );
3255 if (len2W
) str2W
= buf2W
;
3258 len2W
= MultiByteToWideChar( locale_cp
, 0, str2
, len2
, NULL
, 0 );
3259 str2W
= HeapAlloc( GetProcessHeap(), 0, len2W
* sizeof(WCHAR
) );
3262 if (str1W
!= buf1W
) HeapFree( GetProcessHeap(), 0, str1W
);
3263 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3266 MultiByteToWideChar( locale_cp
, 0, str2
, len2
, str2W
, len2W
);
3275 ret
= CompareStringW( lcid
, flags
, str1W
, len1W
, str2W
, len2W
);
3277 if (str1W
!= buf1W
) HeapFree( GetProcessHeap(), 0, str1W
);
3278 if (str2W
!= buf2W
) HeapFree( GetProcessHeap(), 0, str2W
);
3283 /******************************************************************************
3284 * CompareStringW (kernelbase.@)
3286 INT WINAPI DECLSPEC_HOTPATCH
CompareStringW( LCID lcid
, DWORD flags
, const WCHAR
*str1
, int len1
,
3287 const WCHAR
*str2
, int len2
)
3289 return CompareStringEx( NULL
, flags
, str1
, len1
, str2
, len2
, NULL
, NULL
, 0 );
3293 /******************************************************************************
3294 * CompareStringOrdinal (kernelbase.@)
3296 INT WINAPI DECLSPEC_HOTPATCH
CompareStringOrdinal( const WCHAR
*str1
, INT len1
,
3297 const WCHAR
*str2
, INT len2
, BOOL ignore_case
)
3303 SetLastError( ERROR_INVALID_PARAMETER
);
3306 if (len1
< 0) len1
= lstrlenW( str1
);
3307 if (len2
< 0) len2
= lstrlenW( str2
);
3309 ret
= RtlCompareUnicodeStrings( str1
, len1
, str2
, len2
, ignore_case
);
3310 if (ret
< 0) return CSTR_LESS_THAN
;
3311 if (ret
> 0) return CSTR_GREATER_THAN
;
3316 /******************************************************************************
3317 * ConvertDefaultLocale (kernelbase.@)
3319 LCID WINAPI DECLSPEC_HOTPATCH
ConvertDefaultLocale( LCID lcid
)
3321 get_locale_by_id( &lcid
, 0 );
3326 /******************************************************************************
3327 * EnumCalendarInfoW (kernelbase.@)
3329 BOOL WINAPI DECLSPEC_HOTPATCH
EnumCalendarInfoW( CALINFO_ENUMPROCW proc
, LCID lcid
,
3330 CALID id
, CALTYPE type
)
3332 return Internal_EnumCalendarInfo( proc
, lcid
, id
, type
, TRUE
, FALSE
, FALSE
, 0 );
3336 /******************************************************************************
3337 * EnumCalendarInfoExW (kernelbase.@)
3339 BOOL WINAPI DECLSPEC_HOTPATCH
EnumCalendarInfoExW( CALINFO_ENUMPROCEXW proc
, LCID lcid
,
3340 CALID id
, CALTYPE type
)
3342 return Internal_EnumCalendarInfo( (CALINFO_ENUMPROCW
)proc
, lcid
, id
, type
, TRUE
, TRUE
, FALSE
, 0 );
3345 /******************************************************************************
3346 * EnumCalendarInfoExEx (kernelbase.@)
3348 BOOL WINAPI DECLSPEC_HOTPATCH
EnumCalendarInfoExEx( CALINFO_ENUMPROCEXEX proc
, LPCWSTR locale
, CALID id
,
3349 LPCWSTR reserved
, CALTYPE type
, LPARAM lparam
)
3351 LCID lcid
= LocaleNameToLCID( locale
, 0 );
3352 return Internal_EnumCalendarInfo( (CALINFO_ENUMPROCW
)proc
, lcid
, id
, type
, TRUE
, TRUE
, TRUE
, lparam
);
3356 /**************************************************************************
3357 * EnumDateFormatsW (kernelbase.@)
3359 BOOL WINAPI DECLSPEC_HOTPATCH
EnumDateFormatsW( DATEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
)
3361 return Internal_EnumDateFormats( proc
, lcid
, flags
, TRUE
, FALSE
, FALSE
, 0 );
3365 /**************************************************************************
3366 * EnumDateFormatsExW (kernelbase.@)
3368 BOOL WINAPI DECLSPEC_HOTPATCH
EnumDateFormatsExW( DATEFMT_ENUMPROCEXW proc
, LCID lcid
, DWORD flags
)
3370 return Internal_EnumDateFormats( (DATEFMT_ENUMPROCW
)proc
, lcid
, flags
, TRUE
, TRUE
, FALSE
, 0 );
3374 /**************************************************************************
3375 * EnumDateFormatsExEx (kernelbase.@)
3377 BOOL WINAPI DECLSPEC_HOTPATCH
EnumDateFormatsExEx( DATEFMT_ENUMPROCEXEX proc
, const WCHAR
*locale
,
3378 DWORD flags
, LPARAM lparam
)
3380 LCID lcid
= LocaleNameToLCID( locale
, 0 );
3381 return Internal_EnumDateFormats( (DATEFMT_ENUMPROCW
)proc
, lcid
, flags
, TRUE
, TRUE
, TRUE
, lparam
);
3386 /******************************************************************************
3387 * EnumDynamicTimeZoneInformation (kernelbase.@)
3389 DWORD WINAPI DECLSPEC_HOTPATCH
EnumDynamicTimeZoneInformation( DWORD index
,
3390 DYNAMIC_TIME_ZONE_INFORMATION
*info
)
3392 DYNAMIC_TIME_ZONE_INFORMATION tz
;
3396 if (!info
) return ERROR_INVALID_PARAMETER
;
3398 size
= ARRAY_SIZE(tz
.TimeZoneKeyName
);
3399 ret
= RegEnumKeyExW( tz_key
, index
, tz
.TimeZoneKeyName
, &size
, NULL
, NULL
, NULL
, NULL
);
3400 if (ret
) return ret
;
3402 tz
.DynamicDaylightTimeDisabled
= TRUE
;
3403 if (!GetTimeZoneInformationForYear( 0, &tz
, (TIME_ZONE_INFORMATION
*)info
)) return GetLastError();
3405 lstrcpyW( info
->TimeZoneKeyName
, tz
.TimeZoneKeyName
);
3406 info
->DynamicDaylightTimeDisabled
= FALSE
;
3411 /******************************************************************************
3412 * EnumLanguageGroupLocalesW (kernelbase.@)
3414 BOOL WINAPI DECLSPEC_HOTPATCH
EnumLanguageGroupLocalesW( LANGGROUPLOCALE_ENUMPROCW proc
, LGRPID id
,
3415 DWORD flags
, LONG_PTR param
)
3417 return Internal_EnumLanguageGroupLocales( proc
, id
, flags
, param
, TRUE
);
3421 /******************************************************************************
3422 * EnumUILanguagesW (kernelbase.@)
3424 BOOL WINAPI DECLSPEC_HOTPATCH
EnumUILanguagesW( UILANGUAGE_ENUMPROCW proc
, DWORD flags
, LONG_PTR param
)
3426 return Internal_EnumUILanguages( proc
, flags
, param
, TRUE
);
3430 /***********************************************************************
3431 * EnumSystemCodePagesW (kernelbase.@)
3433 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW proc
, DWORD flags
)
3435 return Internal_EnumSystemCodePages( proc
, flags
, TRUE
);
3439 /******************************************************************************
3440 * EnumSystemGeoID (kernelbase.@)
3442 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemGeoID( GEOCLASS
class, GEOID parent
, GEO_ENUMPROC proc
)
3446 TRACE( "(%ld, %ld, %p)\n", class, parent
, proc
);
3450 SetLastError( ERROR_INVALID_PARAMETER
);
3453 if (class != GEOCLASS_NATION
&& class != GEOCLASS_REGION
&& class != GEOCLASS_ALL
)
3455 SetLastError( ERROR_INVALID_FLAGS
);
3459 for (i
= 0; i
< ARRAY_SIZE(geoinfodata
); i
++)
3461 const struct geoinfo
*ptr
= &geoinfodata
[i
];
3463 if (class == GEOCLASS_NATION
&& (ptr
->kind
!= LOCATION_NATION
)) continue;
3464 /* LOCATION_BOTH counts as region */
3465 if (class == GEOCLASS_REGION
&& (ptr
->kind
== LOCATION_NATION
)) continue;
3466 if (parent
&& ptr
->parent
!= parent
) continue;
3467 if (!proc( ptr
->id
)) break;
3473 /******************************************************************************
3474 * EnumSystemLanguageGroupsW (kernelbase.@)
3476 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLanguageGroupsW( LANGUAGEGROUP_ENUMPROCW proc
,
3477 DWORD flags
, LONG_PTR param
)
3479 return Internal_EnumSystemLanguageGroups( proc
, flags
, param
, TRUE
);
3483 /******************************************************************************
3484 * EnumSystemLocalesA (kernelbase.@)
3486 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLocalesA( LOCALE_ENUMPROCA proc
, DWORD flags
)
3489 DWORD name_len
, type
, index
= 0;
3492 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3496 name_len
= ARRAY_SIZE(name
);
3497 if (RegEnumValueA( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
3498 if (type
!= REG_SZ
) continue;
3499 if (!strtoul( name
, NULL
, 16 )) continue;
3500 if (!proc( name
)) break;
3507 /******************************************************************************
3508 * EnumSystemLocalesW (kernelbase.@)
3510 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLocalesW( LOCALE_ENUMPROCW proc
, DWORD flags
)
3513 DWORD name_len
, type
, index
= 0;
3516 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3520 name_len
= ARRAY_SIZE(name
);
3521 if (RegEnumValueW( key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
)) break;
3522 if (type
!= REG_SZ
) continue;
3523 if (!wcstoul( name
, NULL
, 16 )) continue;
3524 if (!proc( name
)) break;
3531 /******************************************************************************
3532 * EnumSystemLocalesEx (kernelbase.@)
3534 BOOL WINAPI DECLSPEC_HOTPATCH
EnumSystemLocalesEx( LOCALE_ENUMPROCEX proc
, DWORD wanted_flags
,
3535 LPARAM param
, void *reserved
)
3537 WCHAR buffer
[256], name
[10];
3538 DWORD name_len
, type
, neutral
, flags
, index
= 0, alt
= 0;
3544 SetLastError( ERROR_INVALID_PARAMETER
);
3548 if (RegOpenKeyExW( nls_key
, L
"Locale", 0, KEY_READ
, &key
)) return FALSE
;
3549 if (RegOpenKeyExW( key
, L
"Alternate Sorts", 0, KEY_READ
, &altkey
)) altkey
= 0;
3553 name_len
= ARRAY_SIZE(name
);
3554 if (RegEnumValueW( alt
? altkey
: key
, index
++, name
, &name_len
, NULL
, &type
, NULL
, NULL
))
3560 if (type
!= REG_SZ
) continue;
3561 if (!(lcid
= wcstoul( name
, NULL
, 16 ))) continue;
3563 GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, buffer
, ARRAY_SIZE( buffer
));
3564 if (!GetLocaleInfoW( lcid
, LOCALE_INEUTRAL
| LOCALE_NOUSEROVERRIDE
| LOCALE_RETURN_NUMBER
,
3565 (LPWSTR
)&neutral
, sizeof(neutral
) / sizeof(WCHAR
) ))
3569 flags
= LOCALE_ALTERNATE_SORTS
;
3571 flags
= LOCALE_WINDOWS
| (neutral
? LOCALE_NEUTRALDATA
: LOCALE_SPECIFICDATA
);
3573 if (wanted_flags
&& !(flags
& wanted_flags
)) continue;
3574 if (!proc( buffer
, flags
, param
)) break;
3576 RegCloseKey( altkey
);
3582 /**************************************************************************
3583 * EnumTimeFormatsW (kernelbase.@)
3585 BOOL WINAPI DECLSPEC_HOTPATCH
EnumTimeFormatsW( TIMEFMT_ENUMPROCW proc
, LCID lcid
, DWORD flags
)
3587 return Internal_EnumTimeFormats( proc
, lcid
, flags
, TRUE
, FALSE
, 0 );
3591 /**************************************************************************
3592 * EnumTimeFormatsEx (kernelbase.@)
3594 BOOL WINAPI DECLSPEC_HOTPATCH
EnumTimeFormatsEx( TIMEFMT_ENUMPROCEX proc
, const WCHAR
*locale
,
3595 DWORD flags
, LPARAM lparam
)
3597 LCID lcid
= LocaleNameToLCID( locale
, 0 );
3598 return Internal_EnumTimeFormats( (TIMEFMT_ENUMPROCW
)proc
, lcid
, flags
, TRUE
, TRUE
, lparam
);
3602 /**************************************************************************
3603 * FindNLSString (kernelbase.@)
3605 INT WINAPI DECLSPEC_HOTPATCH
FindNLSString( LCID lcid
, DWORD flags
, const WCHAR
*src
,
3606 int srclen
, const WCHAR
*value
, int valuelen
, int *found
)
3608 WCHAR locale
[LOCALE_NAME_MAX_LENGTH
];
3610 LCIDToLocaleName( lcid
, locale
, ARRAY_SIZE(locale
), 0 );
3611 return FindNLSStringEx( locale
, flags
, src
, srclen
, value
, valuelen
, found
, NULL
, NULL
, 0 );
3615 /**************************************************************************
3616 * FindNLSStringEx (kernelbase.@)
3618 INT WINAPI DECLSPEC_HOTPATCH
FindNLSStringEx( const WCHAR
*locale
, DWORD flags
, const WCHAR
*src
,
3619 int srclen
, const WCHAR
*value
, int valuelen
, int *found
,
3620 NLSVERSIONINFO
*version
, void *reserved
, LPARAM handle
)
3622 /* FIXME: this function should normalize strings before calling CompareStringEx() */
3624 int offset
, inc
, count
;
3626 TRACE( "%s %lx %s %d %s %d %p %p %p %Id\n", wine_dbgstr_w(locale
), flags
,
3627 wine_dbgstr_w(src
), srclen
, wine_dbgstr_w(value
), valuelen
, found
,
3628 version
, reserved
, handle
);
3630 if (version
|| reserved
|| handle
|| !IsValidLocaleName(locale
) ||
3631 !src
|| !srclen
|| srclen
< -1 || !value
|| !valuelen
|| valuelen
< -1)
3633 SetLastError( ERROR_INVALID_PARAMETER
);
3636 if (srclen
== -1) srclen
= lstrlenW(src
);
3637 if (valuelen
== -1) valuelen
= lstrlenW(value
);
3640 if (srclen
< 0) return -1;
3642 mask
= flags
& ~(FIND_FROMSTART
| FIND_FROMEND
| FIND_STARTSWITH
| FIND_ENDSWITH
);
3643 count
= flags
& (FIND_FROMSTART
| FIND_FROMEND
) ? srclen
+ 1 : 1;
3644 offset
= flags
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 0 : srclen
;
3645 inc
= flags
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 1 : -1;
3648 if (CompareStringEx( locale
, mask
, src
+ offset
, valuelen
,
3649 value
, valuelen
, NULL
, NULL
, 0 ) == CSTR_EQUAL
)
3651 if (found
) *found
= valuelen
;
3660 /******************************************************************************
3661 * FindStringOrdinal (kernelbase.@)
3663 INT WINAPI DECLSPEC_HOTPATCH
FindStringOrdinal( DWORD flag
, const WCHAR
*src
, INT src_size
,
3664 const WCHAR
*val
, INT val_size
, BOOL ignore_case
)
3666 INT offset
, inc
, count
;
3668 TRACE( "%#lx %s %d %s %d %d\n", flag
, wine_dbgstr_w(src
), src_size
,
3669 wine_dbgstr_w(val
), val_size
, ignore_case
);
3673 SetLastError( ERROR_INVALID_PARAMETER
);
3677 if (flag
!= FIND_FROMSTART
&& flag
!= FIND_FROMEND
&& flag
!= FIND_STARTSWITH
&& flag
!= FIND_ENDSWITH
)
3679 SetLastError( ERROR_INVALID_FLAGS
);
3683 if (src_size
== -1) src_size
= lstrlenW( src
);
3684 if (val_size
== -1) val_size
= lstrlenW( val
);
3686 SetLastError( ERROR_SUCCESS
);
3687 src_size
-= val_size
;
3688 if (src_size
< 0) return -1;
3690 count
= flag
& (FIND_FROMSTART
| FIND_FROMEND
) ? src_size
+ 1 : 1;
3691 offset
= flag
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 0 : src_size
;
3692 inc
= flag
& (FIND_FROMSTART
| FIND_STARTSWITH
) ? 1 : -1;
3695 if (CompareStringOrdinal( src
+ offset
, val_size
, val
, val_size
, ignore_case
) == CSTR_EQUAL
)
3703 /******************************************************************************
3704 * FoldStringW (kernelbase.@)
3706 INT WINAPI DECLSPEC_HOTPATCH
FoldStringW( DWORD flags
, LPCWSTR src
, INT srclen
, LPWSTR dst
, INT dstlen
)
3712 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
3714 SetLastError( ERROR_INVALID_PARAMETER
);
3717 if (srclen
== -1) srclen
= lstrlenW(src
) + 1;
3719 if (!dstlen
&& (flags
& (MAP_PRECOMPOSED
| MAP_FOLDCZONE
| MAP_COMPOSITE
)))
3722 if (!(buf
= RtlAllocateHeap( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
3724 SetLastError( ERROR_OUTOFMEMORY
);
3731 status
= fold_string( flags
, src
, srclen
, buf
, &len
);
3732 if (buf
!= dst
) RtlFreeHeap( GetProcessHeap(), 0, buf
);
3733 if (status
!= STATUS_BUFFER_TOO_SMALL
) break;
3734 if (!(buf
= RtlAllocateHeap( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
3736 SetLastError( ERROR_OUTOFMEMORY
);
3740 if (status
== STATUS_INVALID_PARAMETER_1
)
3742 SetLastError( ERROR_INVALID_FLAGS
);
3745 if (!set_ntstatus( status
)) return 0;
3747 if (dstlen
&& dstlen
< len
) SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3752 static const WCHAR
*get_message( DWORD flags
, const void *src
, UINT id
, UINT lang
,
3753 BOOL ansi
, WCHAR
**buffer
)
3757 if (!(flags
& FORMAT_MESSAGE_FROM_STRING
))
3759 const MESSAGE_RESOURCE_ENTRY
*entry
;
3760 NTSTATUS status
= STATUS_INVALID_PARAMETER
;
3762 if (flags
& FORMAT_MESSAGE_FROM_HMODULE
)
3764 HMODULE module
= (HMODULE
)src
;
3765 if (!module
) module
= GetModuleHandleW( 0 );
3766 status
= RtlFindMessage( module
, RT_MESSAGETABLE
, lang
, id
, &entry
);
3768 if (status
&& (flags
& FORMAT_MESSAGE_FROM_SYSTEM
))
3770 /* Fold win32 hresult to its embedded error code. */
3771 if (HRESULT_SEVERITY(id
) == SEVERITY_ERROR
&& HRESULT_FACILITY(id
) == FACILITY_WIN32
)
3772 id
= HRESULT_CODE( id
);
3773 status
= RtlFindMessage( kernel32_handle
, RT_MESSAGETABLE
, lang
, id
, &entry
);
3775 if (!set_ntstatus( status
)) return NULL
;
3778 ansi
= !(entry
->Flags
& MESSAGE_RESOURCE_UNICODE
);
3781 if (!ansi
) return src
;
3782 len
= MultiByteToWideChar( CP_ACP
, 0, src
, -1, NULL
, 0 );
3783 if (!(*buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return NULL
;
3784 MultiByteToWideChar( CP_ACP
, 0, src
, -1, *buffer
, len
);
3789 /***********************************************************************
3790 * FormatMessageA (kernelbase.@)
3792 DWORD WINAPI DECLSPEC_HOTPATCH
FormatMessageA( DWORD flags
, const void *source
, DWORD msgid
, DWORD langid
,
3793 char *buffer
, DWORD size
, va_list *args
)
3796 ULONG len
, retsize
= 0;
3797 ULONG width
= (flags
& FORMAT_MESSAGE_MAX_WIDTH_MASK
);
3799 WCHAR
*result
, *message
= NULL
;
3802 TRACE( "(0x%lx,%p,%#lx,0x%lx,%p,%lu,%p)\n", flags
, source
, msgid
, langid
, buffer
, size
, args
);
3804 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
)
3808 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3811 *(char **)buffer
= NULL
;
3815 SetLastError( ERROR_INVALID_PARAMETER
);
3819 if (width
== 0xff) width
= ~0u;
3821 if (!(src
= get_message( flags
, source
, msgid
, langid
, TRUE
, &message
))) return 0;
3823 if (!(result
= HeapAlloc( GetProcessHeap(), 0, 65536 )))
3824 status
= STATUS_NO_MEMORY
;
3826 status
= RtlFormatMessage( src
, width
, !!(flags
& FORMAT_MESSAGE_IGNORE_INSERTS
),
3827 TRUE
, !!(flags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
), args
,
3828 result
, 65536, &retsize
);
3830 HeapFree( GetProcessHeap(), 0, message
);
3832 if (status
== STATUS_BUFFER_OVERFLOW
)
3834 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3837 if (!set_ntstatus( status
)) goto done
;
3839 len
= WideCharToMultiByte( CP_ACP
, 0, result
, retsize
/ sizeof(WCHAR
), NULL
, 0, NULL
, NULL
);
3842 SetLastError( ERROR_NO_WORK_DONE
);
3846 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
)
3848 char *buf
= LocalAlloc( LMEM_ZEROINIT
, max( size
, len
));
3851 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
3854 *(char **)buffer
= buf
;
3855 WideCharToMultiByte( CP_ACP
, 0, result
, retsize
/ sizeof(WCHAR
), buf
, max( size
, len
), NULL
, NULL
);
3857 else if (len
> size
)
3859 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3862 else WideCharToMultiByte( CP_ACP
, 0, result
, retsize
/ sizeof(WCHAR
), buffer
, size
, NULL
, NULL
);
3867 HeapFree( GetProcessHeap(), 0, result
);
3872 /***********************************************************************
3873 * FormatMessageW (kernelbase.@)
3875 DWORD WINAPI DECLSPEC_HOTPATCH
FormatMessageW( DWORD flags
, const void *source
, DWORD msgid
, DWORD langid
,
3876 WCHAR
*buffer
, DWORD size
, va_list *args
)
3879 ULONG width
= (flags
& FORMAT_MESSAGE_MAX_WIDTH_MASK
);
3881 WCHAR
*message
= NULL
;
3884 TRACE( "(0x%lx,%p,%#lx,0x%lx,%p,%lu,%p)\n", flags
, source
, msgid
, langid
, buffer
, size
, args
);
3888 SetLastError( ERROR_INVALID_PARAMETER
);
3892 if (width
== 0xff) width
= ~0u;
3894 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
) *(LPWSTR
*)buffer
= NULL
;
3896 if (!(src
= get_message( flags
, source
, msgid
, langid
, FALSE
, &message
))) return 0;
3898 if (flags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
)
3901 ULONG alloc
= max( size
* sizeof(WCHAR
), 65536 );
3905 if (!(result
= HeapAlloc( GetProcessHeap(), 0, alloc
)))
3907 status
= STATUS_NO_MEMORY
;
3910 status
= RtlFormatMessage( src
, width
, !!(flags
& FORMAT_MESSAGE_IGNORE_INSERTS
),
3911 FALSE
, !!(flags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
), args
,
3912 result
, alloc
, &retsize
);
3915 if (retsize
<= sizeof(WCHAR
)) HeapFree( GetProcessHeap(), 0, result
);
3916 else *(WCHAR
**)buffer
= HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY
,
3917 result
, max( retsize
, size
* sizeof(WCHAR
) ));
3920 HeapFree( GetProcessHeap(), 0, result
);
3921 if (status
!= STATUS_BUFFER_OVERFLOW
) break;
3925 else status
= RtlFormatMessage( src
, width
, !!(flags
& FORMAT_MESSAGE_IGNORE_INSERTS
),
3926 FALSE
, !!(flags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
), args
,
3927 buffer
, size
* sizeof(WCHAR
), &retsize
);
3929 HeapFree( GetProcessHeap(), 0, message
);
3931 if (status
== STATUS_BUFFER_OVERFLOW
)
3933 if (size
) buffer
[size
- 1] = 0;
3934 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
3937 if (!set_ntstatus( status
)) return 0;
3938 if (retsize
<= sizeof(WCHAR
)) SetLastError( ERROR_NO_WORK_DONE
);
3939 return retsize
/ sizeof(WCHAR
) - 1;
3943 /******************************************************************************
3944 * GetACP (kernelbase.@)
3946 UINT WINAPI
GetACP(void)
3948 return nls_info
.AnsiTableInfo
.CodePage
;
3952 /***********************************************************************
3953 * GetCPInfo (kernelbase.@)
3955 BOOL WINAPI DECLSPEC_HOTPATCH
GetCPInfo( UINT codepage
, CPINFO
*cpinfo
)
3957 const CPTABLEINFO
*table
;
3961 SetLastError( ERROR_INVALID_PARAMETER
);
3968 cpinfo
->DefaultChar
[0] = 0x3f;
3969 cpinfo
->DefaultChar
[1] = 0;
3970 memset( cpinfo
->LeadByte
, 0, sizeof(cpinfo
->LeadByte
) );
3971 cpinfo
->MaxCharSize
= (codepage
== CP_UTF7
) ? 5 : 4;
3974 if (!(table
= get_codepage_table( codepage
))) return FALSE
;
3975 cpinfo
->MaxCharSize
= table
->MaximumCharacterSize
;
3976 memcpy( cpinfo
->DefaultChar
, &table
->DefaultChar
, sizeof(cpinfo
->DefaultChar
) );
3977 memcpy( cpinfo
->LeadByte
, table
->LeadByte
, sizeof(cpinfo
->LeadByte
) );
3984 /***********************************************************************
3985 * GetCPInfoExW (kernelbase.@)
3987 BOOL WINAPI
GetCPInfoExW( UINT codepage
, DWORD flags
, CPINFOEXW
*cpinfo
)
3989 const CPTABLEINFO
*table
;
3994 SetLastError( ERROR_INVALID_PARAMETER
);
4000 cpinfo
->DefaultChar
[0] = 0x3f;
4001 cpinfo
->DefaultChar
[1] = 0;
4002 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
4003 cpinfo
->MaxCharSize
= 5;
4004 cpinfo
->CodePage
= CP_UTF7
;
4005 cpinfo
->UnicodeDefaultChar
= 0x3f;
4008 cpinfo
->DefaultChar
[0] = 0x3f;
4009 cpinfo
->DefaultChar
[1] = 0;
4010 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
4011 cpinfo
->MaxCharSize
= 4;
4012 cpinfo
->CodePage
= CP_UTF8
;
4013 cpinfo
->UnicodeDefaultChar
= 0x3f;
4016 if (!(table
= get_codepage_table( codepage
))) return FALSE
;
4017 cpinfo
->MaxCharSize
= table
->MaximumCharacterSize
;
4018 memcpy( cpinfo
->DefaultChar
, &table
->DefaultChar
, sizeof(cpinfo
->DefaultChar
) );
4019 memcpy( cpinfo
->LeadByte
, table
->LeadByte
, sizeof(cpinfo
->LeadByte
) );
4020 cpinfo
->CodePage
= table
->CodePage
;
4021 cpinfo
->UnicodeDefaultChar
= table
->UniDefaultChar
;
4026 max
= ARRAY_SIZE(codepage_names
) - 1;
4027 cpinfo
->CodePageName
[0] = 0;
4030 pos
= (min
+ max
) / 2;
4031 if (codepage_names
[pos
].cp
< cpinfo
->CodePage
) min
= pos
+ 1;
4032 else if (codepage_names
[pos
].cp
> cpinfo
->CodePage
) max
= pos
- 1;
4035 wcscpy( cpinfo
->CodePageName
, codepage_names
[pos
].name
);
4043 /***********************************************************************
4044 * GetCalendarInfoW (kernelbase.@)
4046 INT WINAPI DECLSPEC_HOTPATCH
GetCalendarInfoW( LCID lcid
, CALID calendar
, CALTYPE type
,
4047 WCHAR
*data
, INT count
, DWORD
*value
)
4049 static const LCTYPE lctype_map
[] =
4052 0, /* CAL_ICALINTVALUE */
4053 0, /* CAL_SCALNAME */
4054 0, /* CAL_IYEAROFFSETRANGE */
4055 0, /* CAL_SERASTRING */
4065 LOCALE_SABBREVDAYNAME1
,
4066 LOCALE_SABBREVDAYNAME2
,
4067 LOCALE_SABBREVDAYNAME3
,
4068 LOCALE_SABBREVDAYNAME4
,
4069 LOCALE_SABBREVDAYNAME5
,
4070 LOCALE_SABBREVDAYNAME6
,
4071 LOCALE_SABBREVDAYNAME7
,
4081 LOCALE_SMONTHNAME10
,
4082 LOCALE_SMONTHNAME11
,
4083 LOCALE_SMONTHNAME12
,
4084 LOCALE_SMONTHNAME13
,
4085 LOCALE_SABBREVMONTHNAME1
,
4086 LOCALE_SABBREVMONTHNAME2
,
4087 LOCALE_SABBREVMONTHNAME3
,
4088 LOCALE_SABBREVMONTHNAME4
,
4089 LOCALE_SABBREVMONTHNAME5
,
4090 LOCALE_SABBREVMONTHNAME6
,
4091 LOCALE_SABBREVMONTHNAME7
,
4092 LOCALE_SABBREVMONTHNAME8
,
4093 LOCALE_SABBREVMONTHNAME9
,
4094 LOCALE_SABBREVMONTHNAME10
,
4095 LOCALE_SABBREVMONTHNAME11
,
4096 LOCALE_SABBREVMONTHNAME12
,
4097 LOCALE_SABBREVMONTHNAME13
,
4099 0, /* CAL_ITWODIGITYEARMAX */
4100 LOCALE_SSHORTESTDAYNAME1
,
4101 LOCALE_SSHORTESTDAYNAME2
,
4102 LOCALE_SSHORTESTDAYNAME3
,
4103 LOCALE_SSHORTESTDAYNAME4
,
4104 LOCALE_SSHORTESTDAYNAME5
,
4105 LOCALE_SSHORTESTDAYNAME6
,
4106 LOCALE_SSHORTESTDAYNAME7
,
4108 0, /* CAL_SABBREVERASTRING */
4111 CALTYPE calinfo
= type
& 0xffff;
4113 if (type
& CAL_NOUSEROVERRIDE
) FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
4114 if (type
& CAL_USE_CP_ACP
) FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
4116 if ((type
& CAL_RETURN_NUMBER
) && !value
)
4118 SetLastError( ERROR_INVALID_PARAMETER
);
4122 if (type
& CAL_RETURN_GENITIVE_NAMES
) flags
|= LOCALE_RETURN_GENITIVE_NAMES
;
4126 case CAL_ICALINTVALUE
:
4127 if (type
& CAL_RETURN_NUMBER
)
4128 return GetLocaleInfoW( lcid
, LOCALE_RETURN_NUMBER
| LOCALE_ICALENDARTYPE
,
4129 (WCHAR
*)value
, sizeof(*value
) / sizeof(WCHAR
) );
4130 return GetLocaleInfoW( lcid
, LOCALE_ICALENDARTYPE
, data
, count
);
4133 FIXME( "Unimplemented caltype %ld\n", calinfo
);
4134 if (data
) *data
= 0;
4137 case CAL_IYEAROFFSETRANGE
:
4138 case CAL_SERASTRING
:
4139 case CAL_SABBREVERASTRING
:
4140 FIXME( "Unimplemented caltype %ld\n", calinfo
);
4143 case CAL_SSHORTDATE
:
4152 case CAL_SABBREVDAYNAME1
:
4153 case CAL_SABBREVDAYNAME2
:
4154 case CAL_SABBREVDAYNAME3
:
4155 case CAL_SABBREVDAYNAME4
:
4156 case CAL_SABBREVDAYNAME5
:
4157 case CAL_SABBREVDAYNAME6
:
4158 case CAL_SABBREVDAYNAME7
:
4159 case CAL_SMONTHNAME1
:
4160 case CAL_SMONTHNAME2
:
4161 case CAL_SMONTHNAME3
:
4162 case CAL_SMONTHNAME4
:
4163 case CAL_SMONTHNAME5
:
4164 case CAL_SMONTHNAME6
:
4165 case CAL_SMONTHNAME7
:
4166 case CAL_SMONTHNAME8
:
4167 case CAL_SMONTHNAME9
:
4168 case CAL_SMONTHNAME10
:
4169 case CAL_SMONTHNAME11
:
4170 case CAL_SMONTHNAME12
:
4171 case CAL_SMONTHNAME13
:
4172 case CAL_SABBREVMONTHNAME1
:
4173 case CAL_SABBREVMONTHNAME2
:
4174 case CAL_SABBREVMONTHNAME3
:
4175 case CAL_SABBREVMONTHNAME4
:
4176 case CAL_SABBREVMONTHNAME5
:
4177 case CAL_SABBREVMONTHNAME6
:
4178 case CAL_SABBREVMONTHNAME7
:
4179 case CAL_SABBREVMONTHNAME8
:
4180 case CAL_SABBREVMONTHNAME9
:
4181 case CAL_SABBREVMONTHNAME10
:
4182 case CAL_SABBREVMONTHNAME11
:
4183 case CAL_SABBREVMONTHNAME12
:
4184 case CAL_SABBREVMONTHNAME13
:
4186 case CAL_SYEARMONTH
:
4187 case CAL_SSHORTESTDAYNAME1
:
4188 case CAL_SSHORTESTDAYNAME2
:
4189 case CAL_SSHORTESTDAYNAME3
:
4190 case CAL_SSHORTESTDAYNAME4
:
4191 case CAL_SSHORTESTDAYNAME5
:
4192 case CAL_SSHORTESTDAYNAME6
:
4193 case CAL_SSHORTESTDAYNAME7
:
4194 return GetLocaleInfoW( lcid
, lctype_map
[calinfo
] | flags
, data
, count
);
4196 case CAL_ITWODIGITYEARMAX
:
4197 if (type
& CAL_RETURN_NUMBER
)
4199 *value
= CALINFO_MAX_YEAR
;
4200 return sizeof(DWORD
) / sizeof(WCHAR
);
4205 int ret
= swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%u", CALINFO_MAX_YEAR
) + 1;
4206 if (!data
) return ret
;
4209 lstrcpyW( data
, buffer
);
4212 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4217 FIXME( "Unknown caltype %ld\n", calinfo
);
4218 SetLastError( ERROR_INVALID_FLAGS
);
4225 /***********************************************************************
4226 * GetCalendarInfoEx (kernelbase.@)
4228 INT WINAPI DECLSPEC_HOTPATCH
GetCalendarInfoEx( const WCHAR
*locale
, CALID calendar
, const WCHAR
*reserved
,
4229 CALTYPE type
, WCHAR
*data
, INT count
, DWORD
*value
)
4231 LCID lcid
= LocaleNameToLCID( locale
, 0 );
4232 return GetCalendarInfoW( lcid
, calendar
, type
, data
, count
, value
);
4235 static CRITICAL_SECTION tzname_section
;
4236 static CRITICAL_SECTION_DEBUG tzname_section_debug
=
4238 0, 0, &tzname_section
,
4239 { &tzname_section_debug
.ProcessLocksList
, &tzname_section_debug
.ProcessLocksList
},
4240 0, 0, { (DWORD_PTR
)(__FILE__
": tzname_section") }
4242 static CRITICAL_SECTION tzname_section
= { &tzname_section_debug
, -1, 0, 0, 0, 0 };
4245 WCHAR key_name
[128];
4246 WCHAR standard_name
[32];
4247 WCHAR daylight_name
[32];
4250 /***********************************************************************
4251 * GetDynamicTimeZoneInformation (kernelbase.@)
4253 DWORD WINAPI DECLSPEC_HOTPATCH
GetDynamicTimeZoneInformation( DYNAMIC_TIME_ZONE_INFORMATION
*info
)
4258 if (!set_ntstatus( RtlQueryDynamicTimeZoneInformation( (RTL_DYNAMIC_TIME_ZONE_INFORMATION
*)info
)))
4259 return TIME_ZONE_ID_INVALID
;
4261 RtlEnterCriticalSection( &tzname_section
);
4262 if (cached_tzname
.lcid
== GetThreadLocale() &&
4263 !wcscmp( info
->TimeZoneKeyName
, cached_tzname
.key_name
))
4265 wcscpy( info
->StandardName
, cached_tzname
.standard_name
);
4266 wcscpy( info
->DaylightName
, cached_tzname
.daylight_name
);
4267 RtlLeaveCriticalSection( &tzname_section
);
4271 RtlLeaveCriticalSection( &tzname_section
);
4272 if (!RegOpenKeyExW( tz_key
, info
->TimeZoneKeyName
, 0, KEY_ALL_ACCESS
, &key
))
4274 RegLoadMUIStringW( key
, L
"MUI_Std", info
->StandardName
,
4275 sizeof(info
->StandardName
), NULL
, 0, system_dir
);
4276 RegLoadMUIStringW( key
, L
"MUI_Dlt", info
->DaylightName
,
4277 sizeof(info
->DaylightName
), NULL
, 0, system_dir
);
4280 else return TIME_ZONE_ID_INVALID
;
4282 RtlEnterCriticalSection( &tzname_section
);
4283 cached_tzname
.lcid
= GetThreadLocale();
4284 wcscpy( cached_tzname
.key_name
, info
->TimeZoneKeyName
);
4285 wcscpy( cached_tzname
.standard_name
, info
->StandardName
);
4286 wcscpy( cached_tzname
.daylight_name
, info
->DaylightName
);
4287 RtlLeaveCriticalSection( &tzname_section
);
4290 NtQuerySystemTime( &now
);
4291 return get_timezone_id( (TIME_ZONE_INFORMATION
*)info
, now
, FALSE
);
4295 /******************************************************************************
4296 * GetDynamicTimeZoneInformationEffectiveYears (kernelbase.@)
4298 DWORD WINAPI DECLSPEC_HOTPATCH
GetDynamicTimeZoneInformationEffectiveYears( const DYNAMIC_TIME_ZONE_INFORMATION
*info
,
4299 DWORD
*first
, DWORD
*last
)
4301 HKEY key
, dst_key
= 0;
4302 DWORD type
, count
, ret
= ERROR_FILE_NOT_FOUND
;
4304 if (RegOpenKeyExW( tz_key
, info
->TimeZoneKeyName
, 0, KEY_ALL_ACCESS
, &key
)) return ret
;
4306 if (RegOpenKeyExW( key
, L
"Dynamic DST", 0, KEY_ALL_ACCESS
, &dst_key
)) goto done
;
4307 count
= sizeof(DWORD
);
4308 if (RegQueryValueExW( dst_key
, L
"FirstEntry", NULL
, &type
, (BYTE
*)first
, &count
)) goto done
;
4309 if (type
!= REG_DWORD
) goto done
;
4310 count
= sizeof(DWORD
);
4311 if (RegQueryValueExW( dst_key
, L
"LastEntry", NULL
, &type
, (BYTE
*)last
, &count
)) goto done
;
4312 if (type
!= REG_DWORD
) goto done
;
4316 RegCloseKey( dst_key
);
4322 /******************************************************************************
4323 * GetFileMUIInfo (kernelbase.@)
4325 BOOL WINAPI
/* DECLSPEC_HOTPATCH */ GetFileMUIInfo( DWORD flags
, const WCHAR
*path
,
4326 FILEMUIINFO
*info
, DWORD
*size
)
4328 FIXME( "stub: %lu, %s, %p, %p\n", flags
, debugstr_w(path
), info
, size
);
4329 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
4334 /******************************************************************************
4335 * GetFileMUIPath (kernelbase.@)
4337 BOOL WINAPI
/* DECLSPEC_HOTPATCH */ GetFileMUIPath( DWORD flags
, const WCHAR
*filepath
,
4338 WCHAR
*language
, ULONG
*languagelen
,
4339 WCHAR
*muipath
, ULONG
*muipathlen
,
4340 ULONGLONG
*enumerator
)
4342 FIXME( "stub: 0x%lx, %s, %s, %p, %p, %p, %p\n", flags
, debugstr_w(filepath
),
4343 debugstr_w(language
), languagelen
, muipath
, muipathlen
, enumerator
);
4344 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
4349 /******************************************************************************
4350 * GetGeoInfoW (kernelbase.@)
4352 INT WINAPI DECLSPEC_HOTPATCH
GetGeoInfoW( GEOID id
, GEOTYPE type
, WCHAR
*data
, int count
, LANGID lang
)
4354 const struct geoinfo
*ptr
= get_geoinfo_ptr( id
);
4356 const WCHAR
*str
= bufferW
;
4359 TRACE( "%ld %ld %p %d %d\n", id
, type
, data
, count
, lang
);
4363 SetLastError( ERROR_INVALID_PARAMETER
);
4369 if (ptr
->kind
!= LOCATION_NATION
) return 0;
4372 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%u", ptr
->id
);
4374 case GEO_ISO_UN_NUMBER
:
4375 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03u", ptr
->uncode
);
4378 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%u", ptr
->parent
);
4388 case GEO_FRIENDLYNAME
:
4389 case GEO_OFFICIALNAME
:
4391 case GEO_OFFICIALLANGUAGES
:
4394 case GEO_DIALINGCODE
:
4395 case GEO_CURRENCYCODE
:
4396 case GEO_CURRENCYSYMBOL
:
4398 FIXME( "type %ld is not supported\n", type
);
4399 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
4402 WARN( "unrecognized type %ld\n", type
);
4403 SetLastError( ERROR_INVALID_FLAGS
);
4407 len
= lstrlenW(str
) + 1;
4408 if (!data
|| !count
) return len
;
4410 memcpy( data
, str
, min(len
, count
) * sizeof(WCHAR
) );
4411 if (count
< len
) SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4412 return count
< len
? 0 : len
;
4416 /******************************************************************************
4417 * GetLocaleInfoA (kernelbase.@)
4419 INT WINAPI DECLSPEC_HOTPATCH
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, char *buffer
, INT len
)
4424 TRACE( "lcid=0x%lx lctype=0x%lx %p %d\n", lcid
, lctype
, buffer
, len
);
4426 if (len
< 0 || (len
&& !buffer
))
4428 SetLastError( ERROR_INVALID_PARAMETER
);
4431 if (LOWORD(lctype
) == LOCALE_SSHORTTIME
|| (lctype
& LOCALE_RETURN_GENITIVE_NAMES
))
4433 SetLastError( ERROR_INVALID_FLAGS
);
4437 if (LOWORD(lctype
) == LOCALE_FONTSIGNATURE
|| (lctype
& LOCALE_RETURN_NUMBER
))
4438 return GetLocaleInfoW( lcid
, lctype
, (WCHAR
*)buffer
, len
/ sizeof(WCHAR
) ) * sizeof(WCHAR
);
4440 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
4442 if (!(bufferW
= RtlAllocateHeap( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
4444 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
4447 ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
);
4448 if (ret
) ret
= WideCharToMultiByte( get_lcid_codepage( lcid
, lctype
), 0,
4449 bufferW
, ret
, buffer
, len
, NULL
, NULL
);
4450 RtlFreeHeap( GetProcessHeap(), 0, bufferW
);
4455 /******************************************************************************
4456 * GetLocaleInfoW (kernelbase.@)
4458 INT WINAPI DECLSPEC_HOTPATCH
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, WCHAR
*buffer
, INT len
)
4463 UINT lcflags
= lctype
;
4467 if (len
< 0 || (len
&& !buffer
))
4469 SetLastError( ERROR_INVALID_PARAMETER
);
4472 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&& !is_genitive_name_supported( lctype
))
4474 SetLastError( ERROR_INVALID_FLAGS
);
4478 if (!len
) buffer
= NULL
;
4480 lcid
= ConvertDefaultLocale( lcid
);
4481 lctype
= LOWORD(lctype
);
4483 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d)\n", lcid
, lctype
, buffer
, len
);
4485 /* first check for overrides in the registry */
4487 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) && lcid
== ConvertDefaultLocale( LOCALE_USER_DEFAULT
))
4489 const struct registry_value
*value
= get_locale_registry_value( lctype
);
4493 if (lcflags
& LOCALE_RETURN_NUMBER
)
4496 ret
= get_registry_locale_info( value
, tmp
, ARRAY_SIZE( tmp
));
4500 UINT number
= wcstol( tmp
, &end
, get_value_base_by_lctype( lctype
) );
4501 if (*end
) /* invalid number */
4503 SetLastError( ERROR_INVALID_FLAGS
);
4506 ret
= sizeof(UINT
) / sizeof(WCHAR
);
4507 if (!len
) return ret
;
4510 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4513 memcpy( buffer
, &number
, sizeof(number
) );
4516 else ret
= get_registry_locale_info( value
, buffer
, len
);
4518 if (ret
!= -1) return ret
;
4522 /* now load it from kernel resources */
4524 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
4525 ULongToPtr((lctype
>> 4) + 1), lcid
)))
4527 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
4530 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
))) return 0;
4532 p
= LockResource( hmem
);
4533 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
4535 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
) / sizeof(WCHAR
);
4536 else if (is_genitive_name_supported( lctype
) && *p
)
4538 /* genitive form is stored after a null separator from a nominative */
4539 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
4541 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
4549 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
4551 if (!len
) return ret
;
4555 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4559 if (lcflags
& LOCALE_RETURN_NUMBER
)
4562 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
4564 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
4566 number
= wcstol( tmp
, &end
, get_value_base_by_lctype( lctype
) );
4568 memcpy( buffer
, &number
, sizeof(number
) );
4569 else /* invalid number */
4571 SetLastError( ERROR_INVALID_FLAGS
);
4574 HeapFree( GetProcessHeap(), 0, tmp
);
4576 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning number %d\n",
4577 lcid
, lctype
, buffer
, len
, number
);
4581 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
4582 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
4584 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning %d %s\n",
4585 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
4591 /******************************************************************************
4592 * GetLocaleInfoEx (kernelbase.@)
4594 INT WINAPI DECLSPEC_HOTPATCH
GetLocaleInfoEx( const WCHAR
*locale
, LCTYPE info
, WCHAR
*buffer
, INT len
)
4596 LCID lcid
= LocaleNameToLCID( locale
, 0 );
4598 TRACE( "%s lcid=0x%lx 0x%lx\n", debugstr_w(locale
), lcid
, info
);
4600 if (!lcid
) return 0;
4602 /* special handling for neutral locale names */
4603 if (locale
&& lstrlenW( locale
) == 2)
4605 switch (LOWORD( info
))
4610 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4613 if (len
) lstrcpyW( buffer
, locale
);
4615 case LOCALE_SPARENT
:
4616 if (len
) buffer
[0] = 0;
4620 return GetLocaleInfoW( lcid
, info
, buffer
, len
);
4624 /******************************************************************************
4625 * GetNLSVersion (kernelbase.@)
4627 BOOL WINAPI DECLSPEC_HOTPATCH
GetNLSVersion( NLS_FUNCTION func
, LCID lcid
, NLSVERSIONINFO
*info
)
4629 WCHAR locale
[LOCALE_NAME_MAX_LENGTH
];
4631 if (info
->dwNLSVersionInfoSize
< offsetof( NLSVERSIONINFO
, dwEffectiveId
))
4633 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4636 if (!LCIDToLocaleName( lcid
, locale
, LOCALE_NAME_MAX_LENGTH
, LOCALE_ALLOW_NEUTRAL_NAMES
))
4638 SetLastError( ERROR_INVALID_PARAMETER
);
4641 return GetNLSVersionEx( func
, locale
, (NLSVERSIONINFOEX
*)info
);
4645 /******************************************************************************
4646 * GetNLSVersionEx (kernelbase.@)
4648 BOOL WINAPI DECLSPEC_HOTPATCH
GetNLSVersionEx( NLS_FUNCTION func
, const WCHAR
*locale
,
4649 NLSVERSIONINFOEX
*info
)
4653 if (func
!= COMPARE_STRING
)
4655 SetLastError( ERROR_INVALID_FLAGS
);
4658 if (info
->dwNLSVersionInfoSize
< sizeof(*info
) &&
4659 (info
->dwNLSVersionInfoSize
!= offsetof( NLSVERSIONINFO
, dwEffectiveId
)))
4661 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
4665 if (!(lcid
= LocaleNameToLCID( locale
, 0 ))) return FALSE
;
4667 info
->dwNLSVersion
= info
->dwDefinedVersion
= sort
.version
;
4668 if (info
->dwNLSVersionInfoSize
>= sizeof(*info
))
4670 const struct sortguid
*sortid
= get_language_sort( locale
);
4671 info
->dwEffectiveId
= lcid
;
4672 info
->guidCustomVersion
= sortid
? sortid
->id
: default_sort_guid
;
4678 /******************************************************************************
4679 * GetOEMCP (kernelbase.@)
4681 UINT WINAPI
GetOEMCP(void)
4683 return nls_info
.OemTableInfo
.CodePage
;
4687 /***********************************************************************
4688 * GetProcessPreferredUILanguages (kernelbase.@)
4690 BOOL WINAPI DECLSPEC_HOTPATCH
GetProcessPreferredUILanguages( DWORD flags
, ULONG
*count
,
4691 WCHAR
*buffer
, ULONG
*size
)
4693 return set_ntstatus( RtlGetProcessPreferredUILanguages( flags
, count
, buffer
, size
));
4697 /***********************************************************************
4698 * GetStringTypeA (kernelbase.@)
4700 BOOL WINAPI DECLSPEC_HOTPATCH
GetStringTypeA( LCID locale
, DWORD type
, const char *src
, int count
,
4708 if (count
== -1) count
= strlen(src
) + 1;
4710 cp
= get_lcid_codepage( locale
, 0 );
4711 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
4712 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4714 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
4716 * NOTE: the target buffer has 1 word for each CHARACTER in the source
4717 * string, with multibyte characters there maybe be more bytes in count
4718 * than character space in the buffer!
4720 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
4721 HeapFree(GetProcessHeap(), 0, srcW
);
4727 /***********************************************************************
4728 * GetStringTypeW (kernelbase.@)
4730 BOOL WINAPI DECLSPEC_HOTPATCH
GetStringTypeW( DWORD type
, const WCHAR
*src
, INT count
, WORD
*chartype
)
4734 SetLastError( ERROR_INVALID_PARAMETER
);
4737 if (type
!= CT_CTYPE1
&& type
!= CT_CTYPE2
&& type
!= CT_CTYPE3
)
4739 SetLastError( ERROR_INVALID_PARAMETER
);
4743 if (count
== -1) count
= lstrlenW(src
) + 1;
4745 while (count
--) *chartype
++ = get_char_type( type
, *src
++ );
4751 /***********************************************************************
4752 * GetStringTypeExW (kernelbase.@)
4754 BOOL WINAPI DECLSPEC_HOTPATCH
GetStringTypeExW( LCID locale
, DWORD type
, const WCHAR
*src
, int count
,
4757 /* locale is ignored for Unicode */
4758 return GetStringTypeW( type
, src
, count
, chartype
);
4762 /***********************************************************************
4763 * GetSystemDefaultLCID (kernelbase.@)
4765 LCID WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultLCID(void)
4771 /***********************************************************************
4772 * GetSystemDefaultLangID (kernelbase.@)
4774 LANGID WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultLangID(void)
4776 return LANGIDFROMLCID( GetSystemDefaultLCID() );
4780 /***********************************************************************
4781 * GetSystemDefaultLocaleName (kernelbase.@)
4783 INT WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultLocaleName( LPWSTR name
, INT len
)
4785 return LCIDToLocaleName( GetSystemDefaultLCID(), name
, len
, 0 );
4789 /***********************************************************************
4790 * GetSystemDefaultUILanguage (kernelbase.@)
4792 LANGID WINAPI DECLSPEC_HOTPATCH
GetSystemDefaultUILanguage(void)
4795 NtQueryInstallUILanguage( &lang
);
4800 /***********************************************************************
4801 * GetSystemPreferredUILanguages (kernelbase.@)
4803 BOOL WINAPI DECLSPEC_HOTPATCH
GetSystemPreferredUILanguages( DWORD flags
, ULONG
*count
,
4804 WCHAR
*buffer
, ULONG
*size
)
4806 return set_ntstatus( RtlGetSystemPreferredUILanguages( flags
, 0, count
, buffer
, size
));
4810 /***********************************************************************
4811 * GetThreadPreferredUILanguages (kernelbase.@)
4813 BOOL WINAPI DECLSPEC_HOTPATCH
GetThreadPreferredUILanguages( DWORD flags
, ULONG
*count
,
4814 WCHAR
*buffer
, ULONG
*size
)
4816 return set_ntstatus( RtlGetThreadPreferredUILanguages( flags
, count
, buffer
, size
));
4820 /***********************************************************************
4821 * GetTimeZoneInformation (kernelbase.@)
4823 DWORD WINAPI DECLSPEC_HOTPATCH
GetTimeZoneInformation( TIME_ZONE_INFORMATION
*info
)
4825 DYNAMIC_TIME_ZONE_INFORMATION tzinfo
;
4826 DWORD ret
= GetDynamicTimeZoneInformation( &tzinfo
);
4828 memcpy( info
, &tzinfo
, sizeof(*info
) );
4833 /***********************************************************************
4834 * GetTimeZoneInformationForYear (kernelbase.@)
4836 BOOL WINAPI DECLSPEC_HOTPATCH
GetTimeZoneInformationForYear( USHORT year
,
4837 DYNAMIC_TIME_ZONE_INFORMATION
*dynamic
,
4838 TIME_ZONE_INFORMATION
*info
)
4840 DYNAMIC_TIME_ZONE_INFORMATION local_info
;
4841 HKEY key
= 0, dst_key
;
4849 SYSTEMTIME std_date
;
4850 SYSTEMTIME dlt_date
;
4853 TRACE( "(%u,%p)\n", year
, info
);
4857 if (GetDynamicTimeZoneInformation( &local_info
) == TIME_ZONE_ID_INVALID
) return FALSE
;
4858 dynamic
= &local_info
;
4861 if ((ret
= RegOpenKeyExW( tz_key
, dynamic
->TimeZoneKeyName
, 0, KEY_ALL_ACCESS
, &key
))) goto done
;
4862 if (RegLoadMUIStringW( key
, L
"MUI_Std", info
->StandardName
,
4863 sizeof(info
->StandardName
), NULL
, 0, system_dir
))
4865 count
= sizeof(info
->StandardName
);
4866 if ((ret
= RegQueryValueExW( key
, L
"Std", NULL
, NULL
, (BYTE
*)info
->StandardName
, &count
)))
4869 if (RegLoadMUIStringW( key
, L
"MUI_Dlt", info
->DaylightName
,
4870 sizeof(info
->DaylightName
), NULL
, 0, system_dir
))
4872 count
= sizeof(info
->DaylightName
);
4873 if ((ret
= RegQueryValueExW( key
, L
"Dlt", NULL
, NULL
, (BYTE
*)info
->DaylightName
, &count
)))
4877 ret
= ERROR_FILE_NOT_FOUND
;
4878 if (!dynamic
->DynamicDaylightTimeDisabled
&&
4879 !RegOpenKeyExW( key
, L
"Dynamic DST", 0, KEY_ALL_ACCESS
, &dst_key
))
4882 swprintf( yearW
, ARRAY_SIZE(yearW
), L
"%u", year
);
4883 count
= sizeof(data
);
4884 ret
= RegQueryValueExW( dst_key
, yearW
, NULL
, NULL
, (BYTE
*)&data
, &count
);
4885 RegCloseKey( dst_key
);
4889 count
= sizeof(data
);
4890 ret
= RegQueryValueExW( key
, L
"TZI", NULL
, NULL
, (BYTE
*)&data
, &count
);
4895 info
->Bias
= data
.bias
;
4896 info
->StandardBias
= data
.std_bias
;
4897 info
->DaylightBias
= data
.dlt_bias
;
4898 info
->StandardDate
= data
.std_date
;
4899 info
->DaylightDate
= data
.dlt_date
;
4904 if (ret
) SetLastError( ret
);
4909 /***********************************************************************
4910 * GetUserDefaultLCID (kernelbase.@)
4912 LCID WINAPI DECLSPEC_HOTPATCH
GetUserDefaultLCID(void)
4918 /***********************************************************************
4919 * GetUserDefaultLangID (kernelbase.@)
4921 LANGID WINAPI DECLSPEC_HOTPATCH
GetUserDefaultLangID(void)
4923 return LANGIDFROMLCID( GetUserDefaultLCID() );
4927 /***********************************************************************
4928 * GetUserDefaultLocaleName (kernelbase.@)
4930 INT WINAPI DECLSPEC_HOTPATCH
GetUserDefaultLocaleName( LPWSTR name
, INT len
)
4932 return LCIDToLocaleName( GetUserDefaultLCID(), name
, len
, 0 );
4936 /***********************************************************************
4937 * GetUserDefaultUILanguage (kernelbase.@)
4939 LANGID WINAPI DECLSPEC_HOTPATCH
GetUserDefaultUILanguage(void)
4942 NtQueryDefaultUILanguage( &lang
);
4947 /******************************************************************************
4948 * GetUserGeoID (kernelbase.@)
4950 GEOID WINAPI DECLSPEC_HOTPATCH
GetUserGeoID( GEOCLASS geoclass
)
4959 case GEOCLASS_NATION
:
4962 case GEOCLASS_REGION
:
4966 WARN("Unknown geoclass %ld\n", geoclass
);
4967 return GEOID_NOT_AVAILABLE
;
4969 if (!RegOpenKeyExW( intl_key
, L
"Geo", 0, KEY_ALL_ACCESS
, &hkey
))
4971 DWORD count
= sizeof(bufferW
);
4972 if (!RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)bufferW
, &count
))
4973 ret
= wcstol( bufferW
, NULL
, 10 );
4974 RegCloseKey( hkey
);
4980 /******************************************************************************
4981 * GetUserPreferredUILanguages (kernelbase.@)
4983 BOOL WINAPI DECLSPEC_HOTPATCH
GetUserPreferredUILanguages( DWORD flags
, ULONG
*count
,
4984 WCHAR
*buffer
, ULONG
*size
)
4986 return set_ntstatus( RtlGetUserPreferredUILanguages( flags
, 0, count
, buffer
, size
));
4990 /******************************************************************************
4991 * IdnToAscii (kernelbase.@)
4993 INT WINAPI DECLSPEC_HOTPATCH
IdnToAscii( DWORD flags
, const WCHAR
*src
, INT srclen
,
4994 WCHAR
*dst
, INT dstlen
)
4996 NTSTATUS status
= RtlIdnToAscii( flags
, src
, srclen
, dst
, &dstlen
);
4997 if (!set_ntstatus( status
)) return 0;
5002 /******************************************************************************
5003 * IdnToNameprepUnicode (kernelbase.@)
5005 INT WINAPI DECLSPEC_HOTPATCH
IdnToNameprepUnicode( DWORD flags
, const WCHAR
*src
, INT srclen
,
5006 WCHAR
*dst
, INT dstlen
)
5008 NTSTATUS status
= RtlIdnToNameprepUnicode( flags
, src
, srclen
, dst
, &dstlen
);
5009 if (!set_ntstatus( status
)) return 0;
5014 /******************************************************************************
5015 * IdnToUnicode (kernelbase.@)
5017 INT WINAPI DECLSPEC_HOTPATCH
IdnToUnicode( DWORD flags
, const WCHAR
*src
, INT srclen
,
5018 WCHAR
*dst
, INT dstlen
)
5020 NTSTATUS status
= RtlIdnToUnicode( flags
, src
, srclen
, dst
, &dstlen
);
5021 if (!set_ntstatus( status
)) return 0;
5026 /******************************************************************************
5027 * IsCharAlphaA (kernelbase.@)
5029 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaA( CHAR c
)
5031 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5032 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_ALPHA
);
5036 /******************************************************************************
5037 * IsCharAlphaW (kernelbase.@)
5039 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaW( WCHAR wc
)
5041 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_ALPHA
);
5045 /******************************************************************************
5046 * IsCharAlphaNumericA (kernelbase.@)
5048 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaNumericA( CHAR c
)
5050 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5051 return !!(get_char_type( CT_CTYPE1
, wc
) & (C1_ALPHA
| C1_DIGIT
));
5055 /******************************************************************************
5056 * IsCharAlphaNumericW (kernelbase.@)
5058 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharAlphaNumericW( WCHAR wc
)
5060 return !!(get_char_type( CT_CTYPE1
, wc
) & (C1_ALPHA
| C1_DIGIT
));
5064 /******************************************************************************
5065 * IsCharBlankW (kernelbase.@)
5067 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharBlankW( WCHAR wc
)
5069 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_BLANK
);
5073 /******************************************************************************
5074 * IsCharCntrlW (kernelbase.@)
5076 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharCntrlW( WCHAR wc
)
5078 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_CNTRL
);
5082 /******************************************************************************
5083 * IsCharDigitW (kernelbase.@)
5085 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharDigitW( WCHAR wc
)
5087 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_DIGIT
);
5091 /******************************************************************************
5092 * IsCharLowerA (kernelbase.@)
5094 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharLowerA( CHAR c
)
5096 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5097 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_LOWER
);
5101 /******************************************************************************
5102 * IsCharLowerW (kernelbase.@)
5104 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharLowerW( WCHAR wc
)
5106 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_LOWER
);
5110 /******************************************************************************
5111 * IsCharPunctW (kernelbase.@)
5113 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharPunctW( WCHAR wc
)
5115 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_PUNCT
);
5119 /******************************************************************************
5120 * IsCharSpaceA (kernelbase.@)
5122 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharSpaceA( CHAR c
)
5124 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5125 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_SPACE
);
5129 /******************************************************************************
5130 * IsCharSpaceW (kernelbase.@)
5132 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharSpaceW( WCHAR wc
)
5134 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_SPACE
);
5138 /******************************************************************************
5139 * IsCharUpperA (kernelbase.@)
5141 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharUpperA( CHAR c
)
5143 WCHAR wc
= nls_info
.AnsiTableInfo
.MultiByteTable
[(unsigned char)c
];
5144 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_UPPER
);
5148 /******************************************************************************
5149 * IsCharUpperW (kernelbase.@)
5151 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharUpperW( WCHAR wc
)
5153 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_UPPER
);
5157 /******************************************************************************
5158 * IsCharXDigitW (kernelbase.@)
5160 BOOL WINAPI DECLSPEC_HOTPATCH
IsCharXDigitW( WCHAR wc
)
5162 return !!(get_char_type( CT_CTYPE1
, wc
) & C1_XDIGIT
);
5166 /******************************************************************************
5167 * IsDBCSLeadByte (kernelbase.@)
5169 BOOL WINAPI DECLSPEC_HOTPATCH
IsDBCSLeadByte( BYTE testchar
)
5171 return nls_info
.AnsiTableInfo
.DBCSCodePage
&& nls_info
.AnsiTableInfo
.DBCSOffsets
[testchar
];
5175 /******************************************************************************
5176 * IsDBCSLeadByteEx (kernelbase.@)
5178 BOOL WINAPI DECLSPEC_HOTPATCH
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
5180 const CPTABLEINFO
*table
= get_codepage_table( codepage
);
5181 return table
&& table
->DBCSCodePage
&& table
->DBCSOffsets
[testchar
];
5185 /******************************************************************************
5186 * IsNormalizedString (kernelbase.@)
5188 BOOL WINAPI DECLSPEC_HOTPATCH
IsNormalizedString( NORM_FORM form
, const WCHAR
*str
, INT len
)
5191 if (!set_ntstatus( RtlIsNormalizedString( form
, str
, len
, &res
))) res
= FALSE
;
5196 /******************************************************************************
5197 * IsValidCodePage (kernelbase.@)
5199 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidCodePage( UINT codepage
)
5212 return get_codepage_table( codepage
) != NULL
;
5217 /******************************************************************************
5218 * IsValidLanguageGroup (kernelbase.@)
5220 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidLanguageGroup( LGRPID id
, DWORD flags
)
5222 WCHAR name
[10], value
[10];
5223 DWORD type
, value_len
= sizeof(value
);
5227 if (RegOpenKeyExW( nls_key
, L
"Language Groups", 0, KEY_READ
, &key
)) return FALSE
;
5229 swprintf( name
, ARRAY_SIZE(name
), L
"%x", id
);
5230 if (!RegQueryValueExW( key
, name
, NULL
, &type
, (BYTE
*)value
, &value_len
) && type
== REG_SZ
)
5231 ret
= (flags
& LGRPID_SUPPORTED
) || wcstoul( value
, NULL
, 10 );
5238 /******************************************************************************
5239 * IsValidLocale (kernelbase.@)
5241 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidLocale( LCID lcid
, DWORD flags
)
5243 return !!get_locale_by_id( &lcid
, LOCALE_ALLOW_NEUTRAL_NAMES
);
5247 /******************************************************************************
5248 * IsValidLocaleName (kernelbase.@)
5250 BOOL WINAPI DECLSPEC_HOTPATCH
IsValidLocaleName( const WCHAR
*locale
)
5252 if (locale
== LOCALE_NAME_USER_DEFAULT
) return FALSE
;
5253 return !!find_lcname_entry( locale
);
5257 /******************************************************************************
5258 * IsValidNLSVersion (kernelbase.@)
5260 DWORD WINAPI DECLSPEC_HOTPATCH
IsValidNLSVersion( NLS_FUNCTION func
, const WCHAR
*locale
,
5261 NLSVERSIONINFOEX
*info
)
5263 static const GUID GUID_NULL
;
5264 NLSVERSIONINFOEX infoex
;
5267 if (func
!= COMPARE_STRING
)
5269 SetLastError( ERROR_INVALID_PARAMETER
);
5272 if (info
->dwNLSVersionInfoSize
< sizeof(*info
) &&
5273 (info
->dwNLSVersionInfoSize
!= offsetof( NLSVERSIONINFO
, dwEffectiveId
)))
5275 SetLastError( ERROR_INVALID_PARAMETER
);
5278 infoex
.dwNLSVersionInfoSize
= sizeof(infoex
);
5279 if (!GetNLSVersionEx( func
, locale
, &infoex
)) return FALSE
;
5281 ret
= (infoex
.dwNLSVersion
& ~0xff) == (info
->dwNLSVersion
& ~0xff);
5282 if (ret
&& !IsEqualGUID( &info
->guidCustomVersion
, &GUID_NULL
))
5283 ret
= find_sortguid( &info
->guidCustomVersion
) != NULL
;
5285 if (!ret
) SetLastError( ERROR_SUCCESS
);
5290 /***********************************************************************
5291 * LCIDToLocaleName (kernelbase.@)
5293 INT WINAPI DECLSPEC_HOTPATCH
LCIDToLocaleName( LCID lcid
, WCHAR
*name
, INT count
, DWORD flags
)
5296 if (flags
&& !once
++) FIXME( "unsupported flags %lx\n", flags
);
5298 return GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, name
, count
);
5302 /***********************************************************************
5303 * LCMapStringEx (kernelbase.@)
5305 INT WINAPI DECLSPEC_HOTPATCH
LCMapStringEx( const WCHAR
*locale
, DWORD flags
, const WCHAR
*src
, int srclen
,
5306 WCHAR
*dst
, int dstlen
, NLSVERSIONINFO
*version
,
5307 void *reserved
, LPARAM handle
)
5309 const struct sortguid
*sortid
= NULL
;
5313 if (version
) FIXME( "unsupported version structure %p\n", version
);
5314 if (reserved
) FIXME( "unsupported reserved pointer %p\n", reserved
);
5318 if (!once
++) FIXME( "unsupported lparam %Ix\n", handle
);
5321 if (!src
|| !srclen
|| dstlen
< 0)
5323 SetLastError( ERROR_INVALID_PARAMETER
);
5327 /* mutually exclusive flags */
5328 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
5329 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
5330 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
5331 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
) ||
5334 SetLastError( ERROR_INVALID_FLAGS
);
5338 if (!dstlen
) dst
= NULL
;
5340 if (flags
& LCMAP_LINGUISTIC_CASING
&& !(sortid
= get_language_sort( locale
)))
5342 FIXME( "unknown locale %s\n", debugstr_w(locale
) );
5343 SetLastError( ERROR_INVALID_PARAMETER
);
5347 if (flags
& LCMAP_SORTKEY
)
5353 SetLastError( ERROR_INVALID_FLAGS
);
5356 if (srclen
< 0) srclen
= lstrlenW(src
);
5358 TRACE( "(%s,0x%08lx,%s,%d,%p,%d)\n",
5359 debugstr_w(locale
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
5361 if ((ret
= get_sortkey( flags
, src
, srclen
, (char *)dst
, dstlen
))) ret
++;
5362 else SetLastError( ERROR_INSUFFICIENT_BUFFER
);
5366 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
5367 if (flags
& SORT_STRINGSORT
)
5369 SetLastError( ERROR_INVALID_FLAGS
);
5372 if (((flags
& (NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
)) &&
5373 (flags
& ~(NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
))) ||
5374 ((flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
| LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) &&
5375 (flags
& (LCMAP_SIMPLIFIED_CHINESE
| LCMAP_TRADITIONAL_CHINESE
))))
5377 SetLastError( ERROR_INVALID_FLAGS
);
5381 if (srclen
< 0) srclen
= lstrlenW(src
) + 1;
5383 TRACE( "(%s,0x%08lx,%s,%d,%p,%d)\n",
5384 debugstr_w(locale
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
5386 if (!dst
) /* return required string length */
5388 if (flags
& NORM_IGNORESYMBOLS
)
5390 for (len
= 0; srclen
; src
++, srclen
--)
5391 if (!(get_char_type( CT_CTYPE1
, *src
) & (C1_PUNCT
| C1_SPACE
))) len
++;
5393 else if (flags
& LCMAP_FULLWIDTH
)
5395 for (len
= 0; srclen
; src
++, srclen
--, len
++)
5397 if (compose_katakana( src
, srclen
, NULL
) == 2)
5404 else if (flags
& LCMAP_HALFWIDTH
)
5406 for (len
= 0; srclen
; src
++, srclen
--, len
++)
5409 /* map Hiragana to Katakana before decomposition if needed */
5410 if ((flags
& LCMAP_KATAKANA
) &&
5411 ((wch
>= 0x3041 && wch
<= 0x3096) || wch
== 0x309D || wch
== 0x309E))
5414 if (decompose_katakana( wch
, NULL
, 0 ) == 2) len
++;
5421 if (src
== dst
&& (flags
& ~(LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)))
5423 SetLastError( ERROR_INVALID_FLAGS
);
5427 if (flags
& (NORM_IGNORENONSPACE
| NORM_IGNORESYMBOLS
))
5429 for (len
= dstlen
, dst_ptr
= dst
; srclen
&& len
; src
++, srclen
--)
5431 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_type( CT_CTYPE1
, *src
) & (C1_PUNCT
| C1_SPACE
)))
5439 if (flags
& (LCMAP_FULLWIDTH
| LCMAP_HALFWIDTH
| LCMAP_HIRAGANA
| LCMAP_KATAKANA
))
5441 for (len
= dstlen
, dst_ptr
= dst
; len
&& srclen
; src
++, srclen
--, len
--, dst_ptr
++)
5444 if (flags
& LCMAP_FULLWIDTH
)
5446 /* map half-width character to full-width one,
5447 e.g. U+FF71 -> U+30A2, U+FF8C U+FF9F -> U+30D7. */
5448 if (map_to_fullwidth( src
, srclen
, &wch
) == 2)
5456 if (flags
& LCMAP_KATAKANA
)
5458 /* map hiragana to katakana, e.g. U+3041 -> U+30A1.
5459 we can't use C3_HIRAGANA as some characters can't map to katakana */
5460 if ((wch
>= 0x3041 && wch
<= 0x3096) || wch
== 0x309D || wch
== 0x309E) wch
+= 0x60;
5462 else if (flags
& LCMAP_HIRAGANA
)
5464 /* map katakana to hiragana, e.g. U+30A1 -> U+3041.
5465 we can't use C3_KATAKANA as some characters can't map to hiragana */
5466 if ((wch
>= 0x30A1 && wch
<= 0x30F6) || wch
== 0x30FD || wch
== 0x30FE) wch
-= 0x60;
5469 if (flags
& LCMAP_HALFWIDTH
)
5471 /* map full-width character to half-width one,
5472 e.g. U+30A2 -> U+FF71, U+30D7 -> U+FF8C U+FF9F. */
5473 if (map_to_halfwidth(wch
, dst_ptr
, len
) == 2)
5480 else *dst_ptr
= wch
;
5482 if (!(flags
& (LCMAP_UPPERCASE
| LCMAP_LOWERCASE
)) || srclen
) goto done
;
5484 srclen
= dst_ptr
- dst
;
5488 if (flags
& (LCMAP_UPPERCASE
| LCMAP_LOWERCASE
))
5490 const USHORT
*table
= sort
.casemap
+ (flags
& LCMAP_LINGUISTIC_CASING
? sortid
->casemap
: 0);
5491 table
= table
+ 2 + (flags
& LCMAP_LOWERCASE
? table
[1] : 0);
5492 for (len
= dstlen
, dst_ptr
= dst
; srclen
&& len
; src
++, srclen
--, len
--)
5493 *dst_ptr
++ = casemap( table
, *src
);
5497 len
= min( srclen
, dstlen
);
5498 memcpy( dst
, src
, len
* sizeof(WCHAR
) );
5499 dst_ptr
= dst
+ len
;
5506 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
5510 return dst_ptr
- dst
;
5514 /***********************************************************************
5515 * LCMapStringA (kernelbase.@)
5517 INT WINAPI DECLSPEC_HOTPATCH
LCMapStringA( LCID lcid
, DWORD flags
, const char *src
, int srclen
,
5518 char *dst
, int dstlen
)
5520 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
5522 INT ret
= 0, srclenW
, dstlenW
;
5523 UINT locale_cp
= CP_ACP
;
5525 if (!src
|| !srclen
|| dstlen
< 0)
5527 SetLastError( ERROR_INVALID_PARAMETER
);
5531 locale_cp
= get_lcid_codepage( lcid
, flags
);
5533 srclenW
= MultiByteToWideChar( locale_cp
, 0, src
, srclen
, bufW
, 260 );
5534 if (srclenW
) srcW
= bufW
;
5537 srclenW
= MultiByteToWideChar( locale_cp
, 0, src
, srclen
, NULL
, 0 );
5538 srcW
= HeapAlloc( GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
) );
5541 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
5544 MultiByteToWideChar( locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
5547 if (flags
& LCMAP_SORTKEY
)
5551 SetLastError( ERROR_INVALID_FLAGS
);
5554 ret
= LCMapStringEx( NULL
, flags
, srcW
, srclenW
, (WCHAR
*)dst
, dstlen
, NULL
, NULL
, 0 );
5558 if (flags
& SORT_STRINGSORT
)
5560 SetLastError( ERROR_INVALID_FLAGS
);
5564 dstlenW
= LCMapStringEx( NULL
, flags
, srcW
, srclenW
, NULL
, 0, NULL
, NULL
, 0 );
5565 if (!dstlenW
) goto done
;
5567 dstW
= HeapAlloc( GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
) );
5570 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
5573 LCMapStringEx( NULL
, flags
, srcW
, srclenW
, dstW
, dstlenW
, NULL
, NULL
, 0 );
5574 ret
= WideCharToMultiByte( locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
5575 HeapFree( GetProcessHeap(), 0, dstW
);
5578 if (srcW
!= bufW
) HeapFree( GetProcessHeap(), 0, srcW
);
5583 /***********************************************************************
5584 * LCMapStringW (kernelbase.@)
5586 INT WINAPI DECLSPEC_HOTPATCH
LCMapStringW( LCID lcid
, DWORD flags
, const WCHAR
*src
, int srclen
,
5587 WCHAR
*dst
, int dstlen
)
5589 return LCMapStringEx( NULL
, flags
, src
, srclen
, dst
, dstlen
, NULL
, NULL
, 0 );
5593 /***********************************************************************
5594 * LocaleNameToLCID (kernelbase.@)
5596 LCID WINAPI DECLSPEC_HOTPATCH
LocaleNameToLCID( const WCHAR
*name
, DWORD flags
)
5600 if (!name
) return GetUserDefaultLCID();
5601 if (!set_ntstatus( RtlLocaleNameToLcid( name
, &lcid
, 2 ))) return 0;
5602 if (!(flags
& LOCALE_ALLOW_NEUTRAL_NAMES
)) lcid
= ConvertDefaultLocale( lcid
);
5607 /******************************************************************************
5608 * MultiByteToWideChar (kernelbase.@)
5610 INT WINAPI DECLSPEC_HOTPATCH
MultiByteToWideChar( UINT codepage
, DWORD flags
, const char *src
, INT srclen
,
5611 WCHAR
*dst
, INT dstlen
)
5615 if (!src
|| !srclen
|| (!dst
&& dstlen
) || dstlen
< 0)
5617 SetLastError( ERROR_INVALID_PARAMETER
);
5620 if (srclen
< 0) srclen
= strlen(src
) + 1;
5625 ret
= mbstowcs_cpsymbol( flags
, src
, srclen
, dst
, dstlen
);
5628 ret
= mbstowcs_utf7( flags
, src
, srclen
, dst
, dstlen
);
5631 ret
= mbstowcs_utf8( flags
, src
, srclen
, dst
, dstlen
);
5634 if (unix_cp
== CP_UTF8
)
5636 ret
= mbstowcs_utf8( flags
, src
, srclen
, dst
, dstlen
);
5642 ret
= mbstowcs_codepage( codepage
, flags
, src
, srclen
, dst
, dstlen
);
5645 TRACE( "cp %d %s -> %s, ret = %d\n", codepage
, debugstr_an(src
, srclen
), debugstr_wn(dst
, ret
), ret
);
5650 /******************************************************************************
5651 * NormalizeString (kernelbase.@)
5653 INT WINAPI DECLSPEC_HOTPATCH
NormalizeString(NORM_FORM form
, const WCHAR
*src
, INT src_len
,
5654 WCHAR
*dst
, INT dst_len
)
5656 NTSTATUS status
= RtlNormalizeString( form
, src
, src_len
, dst
, &dst_len
);
5660 case STATUS_OBJECT_NAME_NOT_FOUND
:
5661 status
= STATUS_INVALID_PARAMETER
;
5663 case STATUS_BUFFER_TOO_SMALL
:
5664 case STATUS_NO_UNICODE_TRANSLATION
:
5668 SetLastError( RtlNtStatusToDosError( status
));
5673 /******************************************************************************
5674 * ResolveLocaleName (kernelbase.@)
5676 INT WINAPI DECLSPEC_HOTPATCH
ResolveLocaleName( LPCWSTR name
, LPWSTR buffer
, INT len
)
5678 FIXME( "stub: %s, %p, %d\n", wine_dbgstr_w(name
), buffer
, len
);
5680 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
5685 /******************************************************************************
5686 * SetLocaleInfoW (kernelbase.@)
5688 BOOL WINAPI DECLSPEC_HOTPATCH
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, const WCHAR
*data
)
5690 const struct registry_value
*value
;
5694 lctype
= LOWORD(lctype
);
5695 value
= get_locale_registry_value( lctype
);
5697 if (!data
|| !value
)
5699 SetLastError( ERROR_INVALID_PARAMETER
);
5703 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
5705 SetLastError( ERROR_INVALID_FLAGS
);
5709 TRACE( "setting %lx (%s) to %s\n", lctype
, debugstr_w(value
->name
), debugstr_w(data
) );
5711 /* FIXME: should check that data to set is sane */
5713 status
= RegSetValueExW( intl_key
, value
->name
, 0, REG_SZ
, (BYTE
*)data
, (lstrlenW(data
)+1)*sizeof(WCHAR
) );
5714 index
= value
- registry_values
;
5716 RtlEnterCriticalSection( &locale_section
);
5717 HeapFree( GetProcessHeap(), 0, registry_cache
[index
] );
5718 registry_cache
[index
] = NULL
;
5719 RtlLeaveCriticalSection( &locale_section
);
5721 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
5723 /* Set I-value from S value */
5724 WCHAR
*pD
, *pM
, *pY
, buf
[2];
5726 pD
= wcschr( data
, 'd' );
5727 pM
= wcschr( data
, 'M' );
5728 pY
= wcschr( data
, 'y' );
5730 if (pD
<= pM
) buf
[0] = '1'; /* D-M-Y */
5731 else if (pY
<= pM
) buf
[0] = '2'; /* Y-M-D */
5732 else buf
[0] = '0'; /* M-D-Y */
5735 lctype
= (lctype
== LOCALE_SSHORTDATE
) ? LOCALE_IDATE
: LOCALE_ILDATE
;
5736 value
= get_locale_registry_value( lctype
);
5737 index
= value
- registry_values
;
5739 RegSetValueExW( intl_key
, value
->name
, 0, REG_SZ
, (BYTE
*)buf
, sizeof(buf
) );
5741 RtlEnterCriticalSection( &locale_section
);
5742 HeapFree( GetProcessHeap(), 0, registry_cache
[index
] );
5743 registry_cache
[index
] = NULL
;
5744 RtlLeaveCriticalSection( &locale_section
);
5746 return set_ntstatus( status
);
5750 /***********************************************************************
5751 * SetCalendarInfoW (kernelbase.@)
5753 INT WINAPI
/* DECLSPEC_HOTPATCH */ SetCalendarInfoW( LCID lcid
, CALID calendar
, CALTYPE type
, const WCHAR
*data
)
5755 FIXME( "(%08lx,%08lx,%08lx,%s): stub\n", lcid
, calendar
, type
, debugstr_w(data
) );
5760 /***********************************************************************
5761 * SetProcessPreferredUILanguages (kernelbase.@)
5763 BOOL WINAPI DECLSPEC_HOTPATCH
SetProcessPreferredUILanguages( DWORD flags
, PCZZWSTR buffer
, ULONG
*count
)
5765 return set_ntstatus( RtlSetProcessPreferredUILanguages( flags
, buffer
, count
));
5769 /***********************************************************************
5770 * SetThreadPreferredUILanguages (kernelbase.@)
5772 BOOL WINAPI DECLSPEC_HOTPATCH
SetThreadPreferredUILanguages( DWORD flags
, PCZZWSTR buffer
, ULONG
*count
)
5774 return set_ntstatus( RtlSetThreadPreferredUILanguages( flags
, buffer
, count
));
5778 /***********************************************************************
5779 * SetTimeZoneInformation (kernelbase.@)
5781 BOOL WINAPI DECLSPEC_HOTPATCH
SetTimeZoneInformation( const TIME_ZONE_INFORMATION
*info
)
5783 return set_ntstatus( RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION
*)info
));
5787 /******************************************************************************
5788 * SetUserGeoID (kernelbase.@)
5790 BOOL WINAPI DECLSPEC_HOTPATCH
SetUserGeoID( GEOID id
)
5792 const struct geoinfo
*geoinfo
= get_geoinfo_ptr( id
);
5798 SetLastError( ERROR_INVALID_PARAMETER
);
5801 if (!RegCreateKeyExW( intl_key
, L
"Geo", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
5803 const WCHAR
*name
= geoinfo
->kind
== LOCATION_NATION
? L
"Nation" : L
"Region";
5804 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%u", geoinfo
->id
);
5805 RegSetValueExW( hkey
, name
, 0, REG_SZ
, (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
5807 if (geoinfo
->kind
== LOCATION_NATION
|| geoinfo
->kind
== LOCATION_BOTH
)
5808 lstrcpyW( bufferW
, geoinfo
->iso2W
);
5810 swprintf( bufferW
, ARRAY_SIZE(bufferW
), L
"%03u", geoinfo
->uncode
);
5811 RegSetValueExW( hkey
, L
"Name", 0, REG_SZ
, (BYTE
*)bufferW
, (lstrlenW(bufferW
) + 1) * sizeof(WCHAR
) );
5812 RegCloseKey( hkey
);
5818 /***********************************************************************
5819 * SystemTimeToTzSpecificLocalTime (kernelbase.@)
5821 BOOL WINAPI DECLSPEC_HOTPATCH
SystemTimeToTzSpecificLocalTime( const TIME_ZONE_INFORMATION
*info
,
5822 const SYSTEMTIME
*system
,
5825 TIME_ZONE_INFORMATION tzinfo
;
5830 RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
5834 if (!SystemTimeToFileTime( system
, (FILETIME
*)&ft
)) return FALSE
;
5835 switch (get_timezone_id( info
, ft
, FALSE
))
5837 case TIME_ZONE_ID_UNKNOWN
:
5838 ft
.QuadPart
-= info
->Bias
* (LONGLONG
)600000000;
5840 case TIME_ZONE_ID_STANDARD
:
5841 ft
.QuadPart
-= (info
->Bias
+ info
->StandardBias
) * (LONGLONG
)600000000;
5843 case TIME_ZONE_ID_DAYLIGHT
:
5844 ft
.QuadPart
-= (info
->Bias
+ info
->DaylightBias
) * (LONGLONG
)600000000;
5849 return FileTimeToSystemTime( (FILETIME
*)&ft
, local
);
5853 /***********************************************************************
5854 * TzSpecificLocalTimeToSystemTime (kernelbase.@)
5856 BOOL WINAPI DECLSPEC_HOTPATCH
TzSpecificLocalTimeToSystemTime( const TIME_ZONE_INFORMATION
*info
,
5857 const SYSTEMTIME
*local
,
5858 SYSTEMTIME
*system
)
5860 TIME_ZONE_INFORMATION tzinfo
;
5865 RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
5869 if (!SystemTimeToFileTime( local
, (FILETIME
*)&ft
)) return FALSE
;
5870 switch (get_timezone_id( info
, ft
, TRUE
))
5872 case TIME_ZONE_ID_UNKNOWN
:
5873 ft
.QuadPart
+= info
->Bias
* (LONGLONG
)600000000;
5875 case TIME_ZONE_ID_STANDARD
:
5876 ft
.QuadPart
+= (info
->Bias
+ info
->StandardBias
) * (LONGLONG
)600000000;
5878 case TIME_ZONE_ID_DAYLIGHT
:
5879 ft
.QuadPart
+= (info
->Bias
+ info
->DaylightBias
) * (LONGLONG
)600000000;
5884 return FileTimeToSystemTime( (FILETIME
*)&ft
, system
);
5888 /***********************************************************************
5889 * VerLanguageNameA (kernelbase.@)
5891 DWORD WINAPI DECLSPEC_HOTPATCH
VerLanguageNameA( DWORD lang
, LPSTR buffer
, DWORD size
)
5893 return GetLocaleInfoA( MAKELCID( lang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, buffer
, size
);
5897 /***********************************************************************
5898 * VerLanguageNameW (kernelbase.@)
5900 DWORD WINAPI DECLSPEC_HOTPATCH
VerLanguageNameW( DWORD lang
, LPWSTR buffer
, DWORD size
)
5902 return GetLocaleInfoW( MAKELCID( lang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, buffer
, size
);
5906 /***********************************************************************
5907 * WideCharToMultiByte (kernelbase.@)
5909 INT WINAPI DECLSPEC_HOTPATCH
WideCharToMultiByte( UINT codepage
, DWORD flags
, LPCWSTR src
, INT srclen
,
5910 LPSTR dst
, INT dstlen
, LPCSTR defchar
, BOOL
*used
)
5914 if (!src
|| !srclen
|| (!dst
&& dstlen
) || dstlen
< 0)
5916 SetLastError( ERROR_INVALID_PARAMETER
);
5920 if (srclen
< 0) srclen
= lstrlenW(src
) + 1;
5925 ret
= wcstombs_cpsymbol( flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5928 ret
= wcstombs_utf7( flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5931 ret
= wcstombs_utf8( flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5934 if (unix_cp
== CP_UTF8
)
5936 if (used
) *used
= FALSE
;
5937 ret
= wcstombs_utf8( flags
, src
, srclen
, dst
, dstlen
, NULL
, NULL
);
5943 ret
= wcstombs_codepage( codepage
, flags
, src
, srclen
, dst
, dstlen
, defchar
, used
);
5946 TRACE( "cp %d %s -> %s, ret = %d\n", codepage
, debugstr_wn(src
, srclen
), debugstr_an(dst
, ret
), ret
);
5951 /***********************************************************************
5952 * GetUserDefaultGeoName (kernelbase.@)
5954 INT WINAPI
GetUserDefaultGeoName(LPWSTR geo_name
, int count
)
5956 const struct geoinfo
*geoinfo
;
5962 TRACE( "geo_name %p, count %d.\n", geo_name
, count
);
5964 if (count
&& !geo_name
)
5966 SetLastError( ERROR_INVALID_PARAMETER
);
5969 if (!(status
= RegOpenKeyExW( intl_key
, L
"Geo", 0, KEY_ALL_ACCESS
, &key
)))
5971 size
= sizeof(buffer
);
5972 status
= RegQueryValueExW( key
, L
"Name", NULL
, NULL
, (BYTE
*)buffer
, &size
);
5977 if ((geoinfo
= get_geoinfo_ptr( GetUserGeoID( GEOCLASS_NATION
))) && geoinfo
->id
!= 39070)
5978 lstrcpyW( buffer
, geoinfo
->iso2W
);
5980 lstrcpyW( buffer
, L
"001" );
5982 size
= lstrlenW( buffer
) + 1;
5987 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
5990 lstrcpyW( geo_name
, buffer
);
5995 /***********************************************************************
5996 * SetUserDefaultGeoName (kernelbase.@)
5998 BOOL WINAPI
SetUserGeoName(PWSTR geo_name
)
6004 TRACE( "geo_name %s.\n", debugstr_w( geo_name
));
6008 SetLastError( ERROR_INVALID_PARAMETER
);
6012 if (lstrlenW( geo_name
) == 3)
6014 uncode
= wcstol( geo_name
, &endptr
, 10 );
6015 if (!uncode
|| endptr
!= geo_name
+ 3)
6017 SetLastError( ERROR_INVALID_PARAMETER
);
6020 for (i
= 0; i
< ARRAY_SIZE(geoinfodata
); ++i
)
6021 if (geoinfodata
[i
].uncode
== uncode
)
6026 if (!lstrcmpiW( geo_name
, L
"XX" ))
6027 return SetUserGeoID( 39070 );
6028 for (i
= 0; i
< ARRAY_SIZE(geoinfodata
); ++i
)
6029 if (!lstrcmpiW( geo_name
, geoinfodata
[i
].iso2W
))
6032 if (i
== ARRAY_SIZE(geoinfodata
))
6034 SetLastError( ERROR_INVALID_PARAMETER
);
6037 return SetUserGeoID( geoinfodata
[i
].id
);