Merge pull request #8541 from briansull/vso-287671
[platform/upstream/coreclr.git] / src / mscorlib / src / System / Globalization / CultureData.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 namespace System.Globalization
6 {
7
8     using System;
9     using System.Collections;
10     using System.Collections.Generic;
11     using System.Text;
12     using System.Threading;
13     using System.Runtime.CompilerServices;
14     using System.Runtime.InteropServices;
15     using System.Runtime.Versioning;
16     using System.Diagnostics.Contracts;
17     using System.Security;
18
19     //
20     // List of culture data
21     // Note the we cache overrides.
22     // Note that localized names (resource names) aren't available from here.
23     //
24
25     //
26     // Our names are a tad confusing.
27     //
28     // sWindowsName -- The name that windows thinks this culture is, ie:
29     //                            en-US if you pass in en-US
30     //                            de-DE_phoneb if you pass in de-DE_phoneb
31     //                            fj-FJ if you pass in fj (neutral, on a pre-Windows 7 machine)
32     //                            fj if you pass in fj (neutral, post-Windows 7 machine)
33     //
34     // sRealName -- The name you used to construct the culture, in pretty form
35     //                       en-US if you pass in EN-us
36     //                       en if you pass in en
37     //                       de-DE_phoneb if you pass in de-DE_phoneb
38     //
39     // sSpecificCulture -- The specific culture for this culture
40     //                             en-US for en-US
41     //                             en-US for en
42     //                             de-DE_phoneb for alt sort
43     //                             fj-FJ for fj (neutral)
44     //
45     // sName -- The IETF name of this culture (ie: no sort info, could be neutral)
46     //                en-US if you pass in en-US
47     //                en if you pass in en
48     //                de-DE if you pass in de-DE_phoneb
49     //
50
51     // StructLayout is needed here otherwise compiler can re-arrange the fields.
52     // We have to keep this in-sync with the definition in comnlsinfo.h
53     //
54     // WARNING WARNING WARNING
55     //
56     // WARNING: Anything changed here also needs to be updated on the native side (object.h see type CultureDataBaseObject)
57     // WARNING: The type loader will rearrange class member offsets so the mscorwks!CultureDataBaseObject
58     // WARNING: must be manually structured to match the true loaded class layout
59     //
60     [FriendAccessAllowed]
61     internal class CultureData
62     {
63         const int undef = -1;
64
65         // Override flag
66         private String sRealName; // Name you passed in (ie: en-US, en, or de-DE_phoneb)
67         private String sWindowsName; // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
68
69         // Identity
70         private String sName; // locale name (ie: en-us, NO sort info, but could be neutral)
71         private String sParent; // Parent name (which may be a custom locale/culture)
72         private String sLocalizedDisplayName; // Localized pretty name for this locale
73         private String sEnglishDisplayName; // English pretty name for this locale
74         private String sNativeDisplayName; // Native pretty name for this locale
75         private String sSpecificCulture; // The culture name to be used in CultureInfo.CreateSpecificCulture(), en-US form if neutral, sort name if sort
76
77         // Language
78         private String sISO639Language; // ISO 639 Language Name
79         private String sLocalizedLanguage; // Localized name for this language
80         private String sEnglishLanguage; // English name for this language
81         private String sNativeLanguage; // Native name of this language
82
83         // Region
84         private String sRegionName; // (RegionInfo)
85         private int iGeoId = undef; // GeoId
86         private String sLocalizedCountry; // localized country name
87         private String sEnglishCountry; // english country name (RegionInfo)
88         private String sNativeCountry; // native country name
89         private String sISO3166CountryName; // ISO 3166 (RegionInfo), ie: US
90
91         // Numbers
92         private String sPositiveSign; // (user can override) positive sign
93         private String sNegativeSign; // (user can override) negative sign
94         private String[] saNativeDigits; // (user can override) native characters for digits 0-9
95         // (nfi populates these 5, don't have to be = undef)
96         private int iDigitSubstitution; // (user can override) Digit substitution 0=context, 1=none/arabic, 2=Native/national (2 seems to be unused)
97         private int iLeadingZeros; // (user can override) leading zeros 0 = no leading zeros, 1 = leading zeros
98         private int iDigits; // (user can override) number of fractional digits
99         private int iNegativeNumber; // (user can override) negative number format
100         private int[] waGrouping; // (user can override) grouping of digits
101         private String sDecimalSeparator; // (user can override) decimal separator
102         private String sThousandSeparator; // (user can override) thousands separator
103         private String sNaN; // Not a Number
104         private String sPositiveInfinity; // + Infinity
105         private String sNegativeInfinity; // - Infinity
106
107         // Percent
108         private int iNegativePercent = undef; // Negative Percent (0-3)
109         private int iPositivePercent = undef; // Positive Percent (0-11)
110         private String sPercent; // Percent (%) symbol
111         private String sPerMille; // PerMille (‰) symbol
112
113         // Currency
114         private String sCurrency; // (user can override) local monetary symbol
115         private String sIntlMonetarySymbol; // international monetary symbol (RegionInfo)
116         private String sEnglishCurrency; // English name for this currency
117         private String sNativeCurrency; // Native name for this currency
118         // (nfi populates these 4, don't have to be = undef)
119         private int iCurrencyDigits; // (user can override) # local monetary fractional digits
120         private int iCurrency; // (user can override) positive currency format
121         private int iNegativeCurrency; // (user can override) negative currency format
122         private int[] waMonetaryGrouping; // (user can override) monetary grouping of digits
123         private String sMonetaryDecimal; // (user can override) monetary decimal separator
124         private String sMonetaryThousand; // (user can override) monetary thousands separator
125
126         // Misc
127         private int iMeasure = undef; // (user can override) system of measurement 0=metric, 1=US (RegionInfo)
128         private String sListSeparator; // (user can override) list separator
129         //        private int    iPaperSize               ; // default paper size (RegionInfo)
130
131         // Time
132         private String sAM1159; // (user can override) AM designator
133         private String sPM2359; // (user can override) PM designator
134         private String sTimeSeparator;
135         private volatile String[] saLongTimes; // (user can override) time format
136         private volatile String[] saShortTimes; // short time format
137         private volatile String[] saDurationFormats; // time duration format
138
139         // Calendar specific data
140         private int iFirstDayOfWeek = undef; // (user can override) first day of week (gregorian really)
141         private int iFirstWeekOfYear = undef; // (user can override) first week of year (gregorian really)
142         private volatile int[] waCalendars; // all available calendar type(s).  The first one is the default calendar
143
144         // Store for specific data about each calendar
145         private CalendarData[] calendars; // Store for specific calendar data
146
147         // Text information
148         private int iReadingLayout = undef; // Reading layout data
149         // 0 - Left to right (eg en-US)
150         // 1 - Right to left (eg arabic locales)
151         // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
152         // 3 - Vertical top to bottom with columns proceeding to the right
153
154         private String sTextInfo; // Text info name to use for custom
155         private String sCompareInfo; // Compare info name (including sorting key) to use if custom
156         private String sScripts; // Typical Scripts for this locale (latn;cyrl; etc)
157
158         private int iDefaultAnsiCodePage = undef; // default ansi code page ID (ACP)
159         private int iDefaultOemCodePage = undef; // default oem code page ID (OCP or OEM)
160         private int iDefaultMacCodePage = undef; // default macintosh code page
161         private int iDefaultEbcdicCodePage = undef; // default EBCDIC code page
162
163         // These are desktop only, not coreclr
164         private int    iLanguage; // locale ID (0409) - NO sort information
165         private String sAbbrevLang; // abbreviated language name (Windows Language Name) ex: ENU
166         private String sAbbrevCountry; // abbreviated country name (RegionInfo) (Windows Region Name) ex: USA
167         private String sISO639Language2; // 3 char ISO 639 lang name 2 ex: eng
168         private String sISO3166CountryName2; // 3 char ISO 3166 country name 2 2(RegionInfo) ex: USA (ISO)
169         private int    iInputLanguageHandle=undef;// input language handle
170         private String sConsoleFallbackName; // The culture name for the console fallback UI culture
171         private String sKeyboardsToInstall; // Keyboard installation string.
172         private String fontSignature; // Font signature (16 WORDS)
173
174         // The bools all need to be in one spot
175         private bool bUseOverrides; // use user overrides?
176         private bool bNeutral; // Flags for the culture (ie: neutral or not right now)
177         private bool bWin32Installed; // Flags indicate if the culture is Win32 installed
178         private bool bFramework; // Flags for indicate if the culture is one of Whidbey cultures
179
180         // Region Name to Culture Name mapping table
181         // (In future would be nice to be in registry or something)
182
183         //Using a property so we avoid creating the dictionary untill we need it
184         private static Dictionary<string, string> RegionNames
185         {
186             get 
187             {
188                 if (s_RegionNames == null)
189                 {
190                     var regionNames = new Dictionary<string, string> {
191                         { "029", "en-029" },
192                         { "AE",  "ar-AE" },
193                         { "AF",  "prs-AF" },
194                         { "AL",  "sq-AL" },
195                         { "AM",  "hy-AM" },
196                         { "AR",  "es-AR" },
197                         { "AT",  "de-AT" },
198                         { "AU",  "en-AU" },
199                         { "AZ",  "az-Cyrl-AZ" },
200                         { "BA",  "bs-Latn-BA" },
201                         { "BD",  "bn-BD" },
202                         { "BE",  "nl-BE" },
203                         { "BG",  "bg-BG" },
204                         { "BH",  "ar-BH" },
205                         { "BN",  "ms-BN" },
206                         { "BO",  "es-BO" },
207                         { "BR",  "pt-BR" },
208                         { "BY",  "be-BY" },
209                         { "BZ",  "en-BZ" },
210                         { "CA",  "en-CA" },
211                         { "CH",  "it-CH" },
212                         { "CL",  "es-CL" },
213                         { "CN",  "zh-CN" },
214                         { "CO",  "es-CO" },
215                         { "CR",  "es-CR" },
216                         { "CS",  "sr-Cyrl-CS" },
217                         { "CZ",  "cs-CZ" },
218                         { "DE",  "de-DE" },
219                         { "DK",  "da-DK" },
220                         { "DO",  "es-DO" },
221                         { "DZ",  "ar-DZ" },
222                         { "EC",  "es-EC" },
223                         { "EE",  "et-EE" },
224                         { "EG",  "ar-EG" },
225                         { "ES",  "es-ES" },
226                         { "ET",  "am-ET" },
227                         { "FI",  "fi-FI" },
228                         { "FO",  "fo-FO" },
229                         { "FR",  "fr-FR" },
230                         { "GB",  "en-GB" },
231                         { "GE",  "ka-GE" },
232                         { "GL",  "kl-GL" },
233                         { "GR",  "el-GR" },
234                         { "GT",  "es-GT" },
235                         { "HK",  "zh-HK" },
236                         { "HN",  "es-HN" },
237                         { "HR",  "hr-HR" },
238                         { "HU",  "hu-HU" },
239                         { "ID",  "id-ID" },
240                         { "IE",  "en-IE" },
241                         { "IL",  "he-IL" },
242                         { "IN",  "hi-IN" },
243                         { "IQ",  "ar-IQ" },
244                         { "IR",  "fa-IR" },
245                         { "IS",  "is-IS" },
246                         { "IT",  "it-IT" },
247                         { "IV",  "" },
248                         { "JM",  "en-JM" },
249                         { "JO",  "ar-JO" },
250                         { "JP",  "ja-JP" },
251                         { "KE",  "sw-KE" },
252                         { "KG",  "ky-KG" },
253                         { "KH",  "km-KH" },
254                         { "KR",  "ko-KR" },
255                         { "KW",  "ar-KW" },
256                         { "KZ",  "kk-KZ" },
257                         { "LA",  "lo-LA" },
258                         { "LB",  "ar-LB" },
259                         { "LI",  "de-LI" },
260                         { "LK",  "si-LK" },
261                         { "LT",  "lt-LT" },
262                         { "LU",  "lb-LU" },
263                         { "LV",  "lv-LV" },
264                         { "LY",  "ar-LY" },
265                         { "MA",  "ar-MA" },
266                         { "MC",  "fr-MC" },
267                         { "ME",  "sr-Latn-ME" },
268                         { "MK",  "mk-MK" },
269                         { "MN",  "mn-MN" },
270                         { "MO",  "zh-MO" },
271                         { "MT",  "mt-MT" },
272                         { "MV",  "dv-MV" },
273                         { "MX",  "es-MX" },
274                         { "MY",  "ms-MY" },
275                         { "NG",  "ig-NG" },
276                         { "NI",  "es-NI" },
277                         { "NL",  "nl-NL" },
278                         { "NO",  "nn-NO" },
279                         { "NP",  "ne-NP" },
280                         { "NZ",  "en-NZ" },
281                         { "OM",  "ar-OM" },
282                         { "PA",  "es-PA" },
283                         { "PE",  "es-PE" },
284                         { "PH",  "en-PH" },
285                         { "PK",  "ur-PK" },
286                         { "PL",  "pl-PL" },
287                         { "PR",  "es-PR" },
288                         { "PT",  "pt-PT" },
289                         { "PY",  "es-PY" },
290                         { "QA",  "ar-QA" },
291                         { "RO",  "ro-RO" },
292                         { "RS",  "sr-Latn-RS" },
293                         { "RU",  "ru-RU" },
294                         { "RW",  "rw-RW" },
295                         { "SA",  "ar-SA" },
296                         { "SE",  "sv-SE" },
297                         { "SG",  "zh-SG" },
298                         { "SI",  "sl-SI" },
299                         { "SK",  "sk-SK" },
300                         { "SN",  "wo-SN" },
301                         { "SV",  "es-SV" },
302                         { "SY",  "ar-SY" },
303                         { "TH",  "th-TH" },
304                         { "TJ",  "tg-Cyrl-TJ" },
305                         { "TM",  "tk-TM" },
306                         { "TN",  "ar-TN" },
307                         { "TR",  "tr-TR" },
308                         { "TT",  "en-TT" },
309                         { "TW",  "zh-TW" },
310                         { "UA",  "uk-UA" },
311                         { "US",  "en-US" },
312                         { "UY",  "es-UY" },
313                         { "UZ",  "uz-Cyrl-UZ" },
314                         { "VE",  "es-VE" },
315                         { "VN",  "vi-VN" },
316                         { "YE",  "ar-YE" },
317                         { "ZA",  "af-ZA" },
318                         { "ZW",  "en-ZW" }
319                     };
320                     s_RegionNames = regionNames;
321                 }
322                 return s_RegionNames;
323             }
324         }
325         private volatile static Dictionary<string, string> s_RegionNames;
326
327         /////////////////////////////////////////////////////////////////////////
328         // Build our invariant information
329         //
330         // We need an invariant instance, which we build hard-coded
331         /////////////////////////////////////////////////////////////////////////
332         internal static CultureData Invariant  
333         {
334             get 
335             {
336                 if (s_Invariant == null)
337                 {
338                     // Make a new culturedata
339                     CultureData invariant = new CultureData();
340
341                     // Call the native code to get the value of bWin32Installed.
342                     // For versions <= Vista, we set this to false for compatibility with v2.
343                     // For Windows 7, the flag is true.
344                     invariant.bUseOverrides = false;
345                     invariant.sRealName = "";
346
347                     // Ask the native code to fill it out for us, we only need the field IsWin32Installed
348                     nativeInitCultureData(invariant);
349
350                     // Basics
351                     // Note that we override the resources since this IS NOT supposed to change (by definition)
352                     invariant.bUseOverrides = false;
353                     invariant.sRealName = "";                     // Name you passed in (ie: en-US, en, or de-DE_phoneb)
354                     invariant.sWindowsName = "";                     // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
355
356                     // Identity
357                     invariant.sName = "";                     // locale name (ie: en-us)
358                     invariant.sParent = "";                     // Parent name (which may be a custom locale/culture)
359                     invariant.bNeutral = false;                   // Flags for the culture (ie: neutral or not right now)
360                     // Don't set invariant.bWin32Installed, we used nativeInitCultureData for that.
361                     invariant.bFramework = true;
362
363                     invariant.sEnglishDisplayName = "Invariant Language (Invariant Country)"; // English pretty name for this locale
364                     invariant.sNativeDisplayName = "Invariant Language (Invariant Country)";  // Native pretty name for this locale
365                     invariant.sSpecificCulture = "";                     // The culture name to be used in CultureInfo.CreateSpecificCulture()
366
367                     // Language
368                     invariant.sISO639Language = "iv";                   // ISO 639 Language Name
369                     invariant.sLocalizedLanguage = "Invariant Language";   // Display name for this Language
370                     invariant.sEnglishLanguage = "Invariant Language";   // English name for this language
371                     invariant.sNativeLanguage = "Invariant Language";   // Native name of this language
372
373                     // Region
374                     invariant.sRegionName = "IV";                   // (RegionInfo)
375                     // Unused for now:
376                     //            invariant.iCountry              =1;                      // country code (RegionInfo)
377                     invariant.iGeoId = 244;                    // GeoId (Windows Only)
378                     invariant.sEnglishCountry = "Invariant Country";    // english country name (RegionInfo)
379                     invariant.sNativeCountry = "Invariant Country";    // native country name (Windows Only)
380                     invariant.sISO3166CountryName = "IV";                   // (RegionInfo), ie: US
381
382                     // Numbers
383                     invariant.sPositiveSign = "+";                    // positive sign
384                     invariant.sNegativeSign = "-";                    // negative sign
385                     invariant.saNativeDigits = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; // native characters for digits 0-9
386                     invariant.iDigitSubstitution = 1;                      // Digit substitution 0=context, 1=none/arabic, 2=Native/national (2 seems to be unused) (Windows Only)
387                     invariant.iLeadingZeros = 1;                      // leading zeros 0=no leading zeros, 1=leading zeros
388                     invariant.iDigits = 2;                      // number of fractional digits
389                     invariant.iNegativeNumber = 1;                      // negative number format
390                     invariant.waGrouping = new int[] { 3 };          // grouping of digits
391                     invariant.sDecimalSeparator = ".";                    // decimal separator
392                     invariant.sThousandSeparator = ",";                    // thousands separator
393                     invariant.sNaN = "NaN";                  // Not a Number
394                     invariant.sPositiveInfinity = "Infinity";             // + Infinity
395                     invariant.sNegativeInfinity = "-Infinity";            // - Infinity
396
397                     // Percent
398                     invariant.iNegativePercent = 0;                      // Negative Percent (0-3)
399                     invariant.iPositivePercent = 0;                      // Positive Percent (0-11)
400                     invariant.sPercent = "%";                    // Percent (%) symbol
401                     invariant.sPerMille = "\x2030";               // PerMille(‰) symbol
402
403                     // Currency
404                     invariant.sCurrency = "\x00a4";                // local monetary symbol "¤: for international monetary symbol
405                     invariant.sIntlMonetarySymbol = "XDR";                  // international monetary symbol (RegionInfo)
406                     invariant.sEnglishCurrency = "International Monetary Fund"; // English name for this currency (Windows Only)
407                     invariant.sNativeCurrency = "International Monetary Fund"; // Native name for this currency (Windows Only)
408                     invariant.iCurrencyDigits = 2;                      // # local monetary fractional digits
409                     invariant.iCurrency = 0;                      // positive currency format
410                     invariant.iNegativeCurrency = 0;                      // negative currency format
411                     invariant.waMonetaryGrouping = new int[] { 3 };          // monetary grouping of digits
412                     invariant.sMonetaryDecimal = ".";                    // monetary decimal separator
413                     invariant.sMonetaryThousand = ",";                    // monetary thousands separator
414
415                     // Misc
416                     invariant.iMeasure = 0;                      // system of measurement 0=metric, 1=US (RegionInfo)
417                     invariant.sListSeparator = ",";                    // list separator
418                     // Unused for now:
419                     //            invariant.iPaperSize            =9;                      // default paper size (RegionInfo)
420                     //            invariant.waFontSignature       ="\x0002\x0000\x0000\x0000\x0000\x0000\x0000\x8000\x0001\x0000\x0000\x8000\x0001\x0000\x0000\x8000"; // Font signature (16 WORDS) (Windows Only)
421
422                     // Time
423                     invariant.sAM1159 = "AM";                   // AM designator
424                     invariant.sPM2359 = "PM";                   // PM designator
425                     invariant.saLongTimes = new String[] { "HH:mm:ss" };                             // time format
426                     invariant.saShortTimes = new String[] { "HH:mm", "hh:mm tt", "H:mm", "h:mm tt" }; // short time format
427                     invariant.saDurationFormats = new String[] { "HH:mm:ss" };                             // time duration format
428
429                     // Calendar specific data
430                     invariant.iFirstDayOfWeek = 0;                      // first day of week
431                     invariant.iFirstWeekOfYear = 0;                      // first week of year
432                     invariant.waCalendars = new int[] { (int)CalendarId.GREGORIAN };       // all available calendar type(s).  The first one is the default calendar
433
434                     // Store for specific data about each calendar
435                     invariant.calendars = new CalendarData[CalendarData.MAX_CALENDARS];
436                     invariant.calendars[0] = CalendarData.Invariant;
437
438                     // Text information
439                     invariant.iReadingLayout = 0;                      // Reading Layout = RTL
440
441                     invariant.sTextInfo = "";                     // Text info name to use for custom
442                     invariant.sCompareInfo = "";                     // Compare info name (including sorting key) to use if custom
443                     invariant.sScripts = "Latn;";                // Typical Scripts for this locale (latn,cyrl, etc)
444
445                     invariant.iLanguage = 0x007f;                 // locale ID (0409) - NO sort information
446                     invariant.iDefaultAnsiCodePage = 1252;                   // default ansi code page ID (ACP)
447                     invariant.iDefaultOemCodePage = 437;                    // default oem code page ID (OCP or OEM)
448                     invariant.iDefaultMacCodePage = 10000;                  // default macintosh code page
449                     invariant.iDefaultEbcdicCodePage = 037;                    // default EBCDIC code page
450             invariant.sAbbrevLang = "IVL";                     // abbreviated language name (Windows Language Name)
451             invariant.sAbbrevCountry = "IVC";                  // abbreviated country name (RegionInfo) (Windows Region Name)
452                     invariant.sISO639Language2 = "ivl";                  // 3 char ISO 639 lang name 2
453                     invariant.sISO3166CountryName2 = "ivc";                  // 3 char ISO 3166 country name 2 2(RegionInfo)
454                     invariant.iInputLanguageHandle = 0x007f;                 // input language handle
455                     invariant.sConsoleFallbackName = "";                     // The culture name for the console fallback UI culture
456                     invariant.sKeyboardsToInstall = "0409:00000409";        // Keyboard installation string.
457                     // Remember it
458                     s_Invariant = invariant;
459                 }
460                 return s_Invariant;
461             }
462         }
463         private volatile static CultureData s_Invariant;
464
465         ///////////////
466         // Constructors //
467         ///////////////
468         // Cache of cultures we've already looked up
469         private static volatile Dictionary<String, CultureData> s_cachedCultures;
470
471         [FriendAccessAllowed]
472         internal static CultureData GetCultureData(String cultureName, bool useUserOverride)
473         {
474             // First do a shortcut for Invariant
475             if (String.IsNullOrEmpty(cultureName))
476             {
477                 return CultureData.Invariant;
478             }
479
480             // Try the hash table first
481             String hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
482             Dictionary<String, CultureData> tempHashTable = s_cachedCultures;
483             if (tempHashTable == null)
484             {
485                 // No table yet, make a new one
486                 tempHashTable = new Dictionary<String, CultureData>();
487             }
488             else
489             {
490                 // Check the hash table
491                 CultureData retVal;
492                 lock (((ICollection)tempHashTable).SyncRoot)
493                 {
494                     tempHashTable.TryGetValue(hashName, out retVal);
495                 }
496                 if (retVal != null)
497                 {
498                     return retVal;
499                 }
500             }
501
502             // Not found in the hash table, need to see if we can build one that works for us
503             CultureData culture = CreateCultureData(cultureName, useUserOverride);
504             if (culture == null)
505             {
506                 return null;
507             }
508
509             // Found one, add it to the cache
510             lock (((ICollection)tempHashTable).SyncRoot)
511             {
512                 tempHashTable[hashName] = culture;
513             }
514
515             // Copy the hashtable to the corresponding member variables.  This will potentially overwrite
516             // new tables simultaneously created by a new thread, but maximizes thread safety.
517             s_cachedCultures = tempHashTable;
518
519             return culture;
520         }
521
522         private static CultureData CreateCultureData(string cultureName, bool useUserOverride)
523         {
524             CultureData culture = new CultureData();
525             culture.bUseOverrides = useUserOverride;
526             culture.sRealName = cultureName;
527
528             // Ask native code if that one's real
529             if (culture.InitCultureData() == false)
530             {
531                 return null;
532             }
533
534             return culture;
535         }
536
537         private bool InitCultureData()
538         {
539             if (nativeInitCultureData(this) == false)
540             {
541                 return false;
542             }
543             return true;
544         }
545
546         // Cache of regions we've already looked up
547         private static volatile Dictionary<String, CultureData> s_cachedRegions;
548
549         internal static CultureData GetCultureDataForRegion(String cultureName, bool useUserOverride)
550         {
551             // First do a shortcut for Invariant
552             if (String.IsNullOrEmpty(cultureName))
553             {
554                 return CultureData.Invariant;
555             }
556
557             //
558             // First check if GetCultureData() can find it (ie: its a real culture)
559             //
560             CultureData retVal = GetCultureData(cultureName, useUserOverride);
561             if (retVal != null && (retVal.IsNeutralCulture == false)) return retVal;
562
563             //
564             // Not a specific culture, perhaps it's region-only name
565             // (Remember this isn't a core clr path where that's not supported)
566             //
567
568             // If it was neutral remember that so that RegionInfo() can throw the right exception
569             CultureData neutral = retVal;
570
571             // Try the hash table next
572             String hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
573             Dictionary<String, CultureData> tempHashTable = s_cachedRegions;
574             if (tempHashTable == null)
575             {
576                 // No table yet, make a new one
577                 tempHashTable = new Dictionary<String, CultureData>();
578             }
579             else
580             {
581                 // Check the hash table
582                 lock (((ICollection)tempHashTable).SyncRoot)
583                 {
584                     tempHashTable.TryGetValue(hashName, out retVal);
585                 }
586                 if (retVal != null)
587                 {
588                     return retVal;
589                 }
590             }
591
592             //
593             // Not found in the hash table, look it up the hard way
594             //
595
596             // If not a valid mapping from the registry we'll have to try the hard coded table
597             if (retVal == null || (retVal.IsNeutralCulture == true))
598             {
599                 // Not a valid mapping, try the hard coded table
600                 if (RegionNames.ContainsKey(cultureName))
601                 {
602                     // Make sure we can get culture data for it
603                     retVal = GetCultureData(RegionNames[cultureName], useUserOverride);
604                 }
605             }
606
607             // If not found in the hard coded table we'll have to find a culture that works for us
608             if (retVal == null || (retVal.IsNeutralCulture == true))
609             {
610                 // Not found in the hard coded table, need to see if we can find a culture that works for us
611                 // Not a real culture name, see if it matches a region name
612                 // (we just return the first culture we match)
613                 CultureInfo[] specifics = SpecificCultures;
614                 for (int i = 0; i < specifics.Length; i++)
615                 {
616                     if (String.Compare(specifics[i].m_cultureData.SREGIONNAME, cultureName, StringComparison.OrdinalIgnoreCase) == 0)
617                     {
618                         // Matched, use this culture
619                         retVal = specifics[i].m_cultureData;
620                         break;
621                     }
622                 }
623             }
624
625             // If we found one we can use, then cash it for next time
626             if (retVal != null && (retVal.IsNeutralCulture == false))
627             {
628                 // first add it to the cache
629                 lock (((ICollection)tempHashTable).SyncRoot)
630                 {
631                     tempHashTable[hashName] = retVal;
632                 }
633
634                 // Copy the hashtable to the corresponding member variables.  This will potentially overwrite
635                 // new tables simultaneously created by a new thread, but maximizes thread safety.
636                 s_cachedRegions = tempHashTable;
637             }
638             else
639             {
640                 // Unable to find a matching culture/region, return null or neutral
641                 // (regionInfo throws a more specific exception on neutrals)
642                 retVal = neutral;
643             }
644
645             // Return the found culture to use, null, or the neutral culture.
646             return retVal;
647         }
648
649 #if FEATURE_USE_LCID
650         // Obtain locale name from LCID
651         // NOTE: This will get neutral names, unlike the OS API
652         [MethodImplAttribute(MethodImplOptions.InternalCall)]
653         internal static extern String LCIDToLocaleName(int lcid);
654
655         // We'd rather people use the named version since this doesn't allow custom locales
656         internal static CultureData GetCultureData(int culture, bool bUseUserOverride)
657         {
658             String localeName = null;
659             CultureData retVal = null;
660
661             if (localeName == null)
662             {
663                 // Convert the lcid to a name, then use that
664                 // Note that this'll return neutral names (unlike Vista native API)
665                 localeName = LCIDToLocaleName(culture);
666             }
667
668             // If its not valid, then throw
669             if (String.IsNullOrEmpty(localeName))
670             {
671                 // Could be valid for Invariant
672                 if (culture == 0x007f)
673                     return Invariant;
674             }
675             else
676             {
677                 // Valid name, use it
678                 retVal = GetCultureData(localeName, bUseUserOverride);
679             }
680
681             // If not successful, throw
682             if (retVal == null)
683                 throw new CultureNotFoundException(
684                     nameof(culture), culture, Environment.GetResourceString("Argument_CultureNotSupported"));
685
686             // Return the one we found
687             return retVal;
688         }
689 #endif
690
691         // Clear our internal caches
692         internal static void ClearCachedData()
693         {
694             s_cachedCultures = null;
695             s_cachedRegions = null;
696             s_replacementCultureNames = null;
697         }
698
699         internal static CultureInfo[] GetCultures(CultureTypes types)
700         {
701             // Disable  warning 618: System.Globalization.CultureTypes.FrameworkCultures' is obsolete
702 #pragma warning disable 618
703             // Validate flags
704             if ((int)types <= 0 || ((int)types & (int)~(CultureTypes.NeutralCultures | CultureTypes.SpecificCultures |
705                                                             CultureTypes.InstalledWin32Cultures | CultureTypes.UserCustomCulture |
706                                                             CultureTypes.ReplacementCultures | CultureTypes.WindowsOnlyCultures |
707                                                             CultureTypes.FrameworkCultures)) != 0)
708             {
709                 throw new ArgumentOutOfRangeException(
710                                 nameof(types),
711                                 String.Format(
712                                     CultureInfo.CurrentCulture,
713                                     Environment.GetResourceString("ArgumentOutOfRange_Range"), CultureTypes.NeutralCultures, CultureTypes.FrameworkCultures));
714             }
715
716             //
717             // CHANGE FROM Whidbey
718             //
719             // We have deprecated CultureTypes.FrameworkCultures.
720             // When this enum is used, we will enumerate Whidbey framework cultures (for compatibility).
721             //
722
723             // We have deprecated CultureTypes.WindowsOnlyCultures.
724             // When this enum is used, we will return an empty array for this enum.
725             if ((types & CultureTypes.WindowsOnlyCultures) != 0)
726             {
727                 // Remove the enum as it is an no-op.
728                 types &= (~CultureTypes.WindowsOnlyCultures);
729             }
730
731             String[] cultureNames = null;
732
733             //
734             // Call nativeEnumCultureNames() to get a string array of culture names based on the specified
735             // enumeration type.
736             //
737             // nativeEnumCultureNames is a QCall.  We need to use a reference to return the string array
738             // allocated from the QCall.  That ref has to be wrapped as object handle.
739             // See vm\qcall.h for details in QCall.
740             //
741
742             if (nativeEnumCultureNames((int)types, JitHelpers.GetObjectHandleOnStack(ref cultureNames)) == 0)
743             {
744                 return new CultureInfo[0];
745             }
746
747             int arrayLength = cultureNames.Length;
748
749             CultureInfo[] cultures = new CultureInfo[arrayLength];
750
751             for (int i = 0; i < cultureNames.Length; i++)
752             {
753                 cultures[i] = new CultureInfo(cultureNames[i]);
754             }
755 #pragma warning restore 618
756
757             return cultures;
758         }
759
760         internal static volatile CultureInfo[] specificCultures;
761
762         private static CultureInfo[] SpecificCultures
763         {
764             get
765             {
766                 if (specificCultures == null)
767                     specificCultures = GetCultures(CultureTypes.SpecificCultures);
768
769                 return specificCultures;
770             }
771         }
772
773         internal bool IsReplacementCulture
774         {
775             get
776             {
777                 return IsReplacementCultureName(this.SNAME);
778             }
779         }
780
781         internal static volatile String[] s_replacementCultureNames;
782
783         ////////////////////////////////////////////////////////////////////////
784         //
785         // Cache for the known replacement cultures.
786         // This is used by CultureInfo.CultureType to check if a culture is a
787         // replacement culture.
788         //
789         ////////////////////////////////////////////////////////////////////////
790
791
792         private static bool IsReplacementCultureName(String name)
793         {
794             Contract.Assert(name != null, "IsReplacementCultureName(): name should not be null");
795             String[] replacementCultureNames = s_replacementCultureNames;
796             if (replacementCultureNames == null)
797             {
798                 if (nativeEnumCultureNames((int)CultureTypes.ReplacementCultures, JitHelpers.GetObjectHandleOnStack(ref replacementCultureNames)) == 0)
799                 {
800                     return false;
801                 }
802
803                 // Even if we don't have any replacement cultures, the returned replacementCultureNames will still an empty string array, not null.
804                 Contract.Assert(name != null, "IsReplacementCultureName(): replacementCultureNames should not be null");
805                 Array.Sort(replacementCultureNames);
806                 s_replacementCultureNames = replacementCultureNames;
807             }
808             return Array.BinarySearch(replacementCultureNames, name) >= 0;
809         }
810
811         ////////////////////////////////////////////////////////////////////////
812         //
813         //  All the accessors
814         //
815         //  Accessors for our data object items
816         //
817         ////////////////////////////////////////////////////////////////////////
818
819         ///////////
820         // Identity //
821         ///////////
822
823         // The real name used to construct the locale (ie: de-DE_phoneb)
824         internal String CultureName
825         {
826             get
827             {
828                 Contract.Assert(this.sRealName != null, "[CultureData.CultureName] Expected this.sRealName to be populated by COMNlsInfo::nativeInitCultureData already");
829                 // since windows doesn't know about zh-CHS and zh-CHT,
830                 // we leave sRealName == zh-Hanx but we still need to
831                 // pretend that it was zh-CHX.
832                 switch (this.sName)
833                 {
834                     case "zh-CHS":
835                     case "zh-CHT":
836                         return this.sName;
837                 }
838                 return this.sRealName;
839             }
840         }
841
842         // Are overrides enabled?
843         internal bool UseUserOverride
844         {
845             get
846             {
847                 return this.bUseOverrides;
848             }
849         }
850
851         // locale name (ie: de-DE, NO sort information)
852         internal String SNAME
853         {
854             get
855             {
856                 //                Contract.Assert(this.sName != null,
857                 //                    "[CultureData.SNAME] Expected this.sName to be populated by COMNlsInfo::nativeInitCultureData already");
858                 if (this.sName == null)
859                 {
860                     this.sName = String.Empty;
861                 }
862                 return this.sName;
863             }
864         }
865
866         // Parent name (which may be a custom locale/culture)
867         internal String SPARENT
868         {
869             get
870             {
871                 if (this.sParent == null)
872                 {
873                     // Ask using the real name, so that we get parents of neutrals
874                     this.sParent = DoGetLocaleInfo(this.sRealName, LOCALE_SPARENT);
875                 }
876                 return this.sParent;
877             }
878         }
879
880         // Localized pretty name for this locale (ie: Inglis (estados Unitos))
881         internal String SLOCALIZEDDISPLAYNAME
882         {
883             get
884             {
885                 if (this.sLocalizedDisplayName == null)
886                 {
887                     // If it hasn't been found (Windows 8 and up), fallback to the system
888                     if (String.IsNullOrEmpty(this.sLocalizedDisplayName))
889                     {
890                         // If its neutral use the language name
891                         if (this.IsNeutralCulture)
892                         {
893                             this.sLocalizedDisplayName = this.SLOCALIZEDLANGUAGE;
894                         }
895                         else
896                         {
897                             // We have to make the neutral distinction in case the OS returns a specific name
898                             if (CultureInfo.UserDefaultUICulture.Name.Equals(Thread.CurrentThread.CurrentUICulture.Name))
899                             {
900                                 this.sLocalizedDisplayName = DoGetLocaleInfo(LOCALE_SLOCALIZEDDISPLAYNAME);
901                             }
902                             if (String.IsNullOrEmpty(this.sLocalizedDisplayName))
903                             {
904                                 this.sLocalizedDisplayName = this.SNATIVEDISPLAYNAME;
905                             }
906                         }
907                     }
908                 }
909                 return this.sLocalizedDisplayName;
910             }
911         }
912
913         // English pretty name for this locale (ie: English (United States))
914         internal String SENGDISPLAYNAME
915         {
916             get
917             {
918                 if (this.sEnglishDisplayName == null)
919                 {
920                     // If its neutral use the language name
921                     if (this.IsNeutralCulture)
922                     {
923                         this.sEnglishDisplayName = this.SENGLISHLANGUAGE;
924                     }
925                     else
926                     {
927                         this.sEnglishDisplayName = DoGetLocaleInfo(LOCALE_SENGLISHDISPLAYNAME);
928
929                         // if it isn't found build one:
930                         if (String.IsNullOrEmpty(this.sEnglishDisplayName))
931                         {
932                             // Our existing names mostly look like:
933                             // "English" + "United States" -> "English (United States)"
934                             // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
935                             if (this.SENGLISHLANGUAGE.EndsWith(')'))
936                             {
937                                 // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
938                                 this.sEnglishDisplayName =
939                                     this.SENGLISHLANGUAGE.Substring(0, this.sEnglishLanguage.Length - 1) +
940                                     ", " + this.SENGCOUNTRY + ")";
941                             }
942                             else
943                             {
944                                 // "English" + "United States" -> "English (United States)"
945                                 this.sEnglishDisplayName = this.SENGLISHLANGUAGE + " (" + this.SENGCOUNTRY + ")";
946                             }
947                         }
948                     }
949                 }
950                 return this.sEnglishDisplayName;
951             }
952         }
953
954         // Native pretty name for this locale (ie: Deutsch (Deutschland))
955         internal String SNATIVEDISPLAYNAME
956         {
957             get
958             {
959                 if (this.sNativeDisplayName == null)
960                 {
961                     // If its neutral use the language name
962                     if (this.IsNeutralCulture)
963                     {
964                         this.sNativeDisplayName = this.SNATIVELANGUAGE;
965                     }
966                     else
967                     {
968                         this.sNativeDisplayName = DoGetLocaleInfo(LOCALE_SNATIVEDISPLAYNAME);
969
970                         // if it isn't found build one:
971                         if (String.IsNullOrEmpty(this.sNativeDisplayName))
972                         {
973                             // These should primarily be "Deutsch (Deutschland)" type names
974                             this.sNativeDisplayName = this.SNATIVELANGUAGE + " (" + this.SNATIVECOUNTRY + ")";
975                         }
976                     }
977                 }
978                 return this.sNativeDisplayName;
979             }
980         }
981
982         // The culture name to be used in CultureInfo.CreateSpecificCulture()
983         internal String SSPECIFICCULTURE
984         {
985             get
986             {
987                 // This got populated when ComNlsInfo::nativeInitCultureData told us we had a culture
988                 Contract.Assert(this.sSpecificCulture != null, "[CultureData.SSPECIFICCULTURE] Expected this.sSpecificCulture to be populated by COMNlsInfo::nativeInitCultureData already");
989                 return this.sSpecificCulture;
990             }
991         }
992
993         /////////////
994         // Language //
995         /////////////
996
997         // iso 639 language name, ie: en
998         internal String SISO639LANGNAME
999         {
1000             get
1001             {
1002                 if (this.sISO639Language == null)
1003                 {
1004                     this.sISO639Language = DoGetLocaleInfo(LOCALE_SISO639LANGNAME);
1005                 }
1006                 return this.sISO639Language;
1007             }
1008         }
1009
1010         // iso 639 language name, ie: eng
1011         internal String SISO639LANGNAME2
1012         {
1013             get
1014             {
1015                 if (this.sISO639Language2 == null)
1016                 {
1017                     this.sISO639Language2 = DoGetLocaleInfo(LOCALE_SISO639LANGNAME2);
1018                 }
1019                 return this.sISO639Language2;
1020             }
1021         }
1022
1023         // abbreviated windows language name (ie: enu) (non-standard, avoid this)
1024         internal String SABBREVLANGNAME
1025         {
1026             get
1027             {
1028                 if (this.sAbbrevLang == null)
1029                 {
1030                     this.sAbbrevLang = DoGetLocaleInfo(LOCALE_SABBREVLANGNAME);
1031                 }
1032                 return this.sAbbrevLang;
1033             }
1034         }
1035
1036         // Localized name for this language (Windows Only) ie: Inglis
1037         // This is only valid for Windows 8 and higher neutrals:
1038         internal String SLOCALIZEDLANGUAGE
1039         {
1040             get
1041             {
1042                 if (this.sLocalizedLanguage == null)
1043                 {
1044                     if (CultureInfo.UserDefaultUICulture.Name.Equals(Thread.CurrentThread.CurrentUICulture.Name))
1045                     {
1046                         this.sLocalizedLanguage = DoGetLocaleInfo(LOCALE_SLOCALIZEDLANGUAGENAME);
1047                     }
1048                     // Some OS's might not have this resource or LCTYPE
1049                     if (String.IsNullOrEmpty(this.sLocalizedLanguage))
1050                     {
1051                         this.sLocalizedLanguage = SNATIVELANGUAGE;
1052                     }
1053                 }
1054
1055                 return this.sLocalizedLanguage;
1056             }
1057         }
1058
1059         // English name for this language (Windows Only) ie: German
1060         internal String SENGLISHLANGUAGE
1061         {
1062             get
1063             {
1064                 if (this.sEnglishLanguage == null)
1065                 {
1066                     this.sEnglishLanguage = DoGetLocaleInfo(LOCALE_SENGLISHLANGUAGENAME);
1067                 }
1068                 return this.sEnglishLanguage;
1069             }
1070         }
1071
1072         // Native name of this language (Windows Only) ie: Deutsch
1073         internal String SNATIVELANGUAGE
1074         {
1075             get
1076             {
1077                 if (this.sNativeLanguage == null)
1078                 {
1079                     {
1080                         this.sNativeLanguage = DoGetLocaleInfo(LOCALE_SNATIVELANGUAGENAME);
1081                     }
1082                 }
1083                 return this.sNativeLanguage;
1084             }
1085         }
1086
1087         ///////////
1088         // Region //
1089         ///////////
1090
1091         // region name (eg US)
1092         internal String SREGIONNAME
1093         {
1094             get
1095             {
1096                 if (this.sRegionName == null)
1097                 {
1098                     this.sRegionName = DoGetLocaleInfo(LOCALE_SISO3166CTRYNAME);
1099                 }
1100                 return this.sRegionName;
1101             }
1102         }
1103
1104         // (user can override) country code (RegionInfo)
1105         internal int ICOUNTRY
1106         {
1107             get
1108             {
1109                 return DoGetLocaleInfoInt(LOCALE_ICOUNTRY);
1110             }
1111         }
1112
1113         // GeoId
1114         internal int IGEOID
1115         {
1116             get
1117             {
1118                 if (this.iGeoId == undef)
1119                 {
1120                     this.iGeoId = DoGetLocaleInfoInt(LOCALE_IGEOID);
1121                 }
1122                 return this.iGeoId;
1123             }
1124         }
1125
1126         // localized name for the country
1127         internal string SLOCALIZEDCOUNTRY
1128         {
1129             get
1130             {
1131                 if (this.sLocalizedCountry == null)
1132                 {
1133                     // If it hasn't been found (Windows 8 and up), fallback to the system
1134                     if (String.IsNullOrEmpty(this.sLocalizedCountry))
1135                     {
1136                         // We have to make the neutral distinction in case the OS returns a specific name
1137                         if (CultureInfo.UserDefaultUICulture.Name.Equals(Thread.CurrentThread.CurrentUICulture.Name))
1138                         {
1139                             this.sLocalizedCountry = DoGetLocaleInfo(LOCALE_SLOCALIZEDCOUNTRYNAME);
1140                         }
1141                         if (String.IsNullOrEmpty(this.sLocalizedDisplayName))
1142                         {
1143                             this.sLocalizedCountry = SNATIVECOUNTRY;
1144                         }
1145                     }
1146                 }
1147                 return this.sLocalizedCountry;
1148             }
1149         }
1150
1151         // english country name (RegionInfo) ie: Germany
1152         internal String SENGCOUNTRY
1153         {
1154             get
1155             {
1156                 if (this.sEnglishCountry == null)
1157                 {
1158                     this.sEnglishCountry = DoGetLocaleInfo(LOCALE_SENGLISHCOUNTRYNAME);
1159                 }
1160                 return this.sEnglishCountry;
1161             }
1162         }
1163
1164         // native country name (RegionInfo) ie: Deutschland
1165         internal String SNATIVECOUNTRY
1166         {
1167             get
1168             {
1169                 if (this.sNativeCountry == null)
1170                 {
1171                     this.sNativeCountry = DoGetLocaleInfo(LOCALE_SNATIVECOUNTRYNAME);
1172                 }
1173                 return this.sNativeCountry;
1174             }
1175         }
1176
1177         // ISO 3166 Country Name
1178         internal String SISO3166CTRYNAME
1179         {
1180             get
1181             {
1182                 if (this.sISO3166CountryName == null)
1183                 {
1184                     this.sISO3166CountryName = DoGetLocaleInfo(LOCALE_SISO3166CTRYNAME);
1185                 }
1186                 return this.sISO3166CountryName;
1187             }
1188         }
1189
1190         // ISO 3166 Country Name
1191         internal String SISO3166CTRYNAME2
1192         {
1193             get
1194             {
1195                 if (this.sISO3166CountryName2 == null)
1196                 {
1197                     this.sISO3166CountryName2 = DoGetLocaleInfo(LOCALE_SISO3166CTRYNAME2);
1198                 }
1199                 return this.sISO3166CountryName2;
1200             }
1201         }
1202
1203         // abbreviated Country Name (windows version, non-standard, avoid)
1204         internal String SABBREVCTRYNAME
1205         {
1206             get
1207             {
1208                 if (this.sAbbrevCountry == null)
1209                 {
1210                     this.sAbbrevCountry = DoGetLocaleInfo(LOCALE_SABBREVCTRYNAME);
1211                 }
1212                 return this.sAbbrevCountry;
1213             }
1214         }
1215
1216         // Default Country
1217         private int IDEFAULTCOUNTRY
1218         {
1219             get
1220             {
1221                 return DoGetLocaleInfoInt(LOCALE_IDEFAULTCOUNTRY);
1222             }
1223         }
1224
1225         // Console fallback name (ie: locale to use for console apps for unicode-only locales)
1226         internal int IINPUTLANGUAGEHANDLE
1227         {
1228             get
1229             {
1230                 if (this.iInputLanguageHandle == undef)
1231                 {
1232                     if (IsSupplementalCustomCulture)
1233                     {
1234                         this.iInputLanguageHandle = 0x0409;
1235                     }
1236                     else
1237                     {
1238                         // Input Language is same as LCID for built-in cultures
1239                         this.iInputLanguageHandle = this.ILANGUAGE;
1240                     }
1241                 }
1242                 return this.iInputLanguageHandle;
1243             }
1244         }
1245
1246         // Console fallback name (ie: locale to use for console apps for unicode-only locales)
1247         internal String SCONSOLEFALLBACKNAME
1248         {
1249             get
1250             {
1251                 if (this.sConsoleFallbackName == null)
1252                 {
1253                     string consoleFallbackName = DoGetLocaleInfo(LOCALE_SCONSOLEFALLBACKNAME);
1254                     if (consoleFallbackName == "es-ES_tradnl")
1255                     {
1256                         consoleFallbackName = "es-ES";
1257                     }
1258                     this.sConsoleFallbackName = consoleFallbackName;
1259                 }
1260                 return this.sConsoleFallbackName;
1261             }
1262         }
1263
1264         /////////////
1265         // Numbers //
1266         ////////////
1267
1268         //                internal String sPositiveSign            ; // (user can override) positive sign
1269         //                internal String sNegativeSign            ; // (user can override) negative sign
1270         //                internal String[] saNativeDigits         ; // (user can override) native characters for digits 0-9
1271         //                internal int iDigitSubstitution       ; // (user can override) Digit substitution 0=context, 1=none/arabic, 2=Native/national (2 seems to be unused) (Windows Only)
1272         //                internal int iDigits                  ; // (user can override) number of fractional digits
1273         //                internal int iNegativeNumber          ; // (user can override) negative number format
1274
1275         // Leading zeroes
1276         private bool ILEADINGZEROS
1277         {
1278             get
1279             {
1280                 return (DoGetLocaleInfoInt(LOCALE_ILZERO) == 1);
1281             }
1282         }
1283
1284
1285         // (user can override) grouping of digits
1286         internal int[] WAGROUPING
1287         {
1288             get
1289             {
1290                 if (this.waGrouping == null || UseUserOverride)
1291                 {
1292                     this.waGrouping = ConvertWin32GroupString(DoGetLocaleInfo(LOCALE_SGROUPING));
1293                 }
1294                 return this.waGrouping;
1295             }
1296         }
1297
1298
1299         //                internal String sDecimalSeparator        ; // (user can override) decimal separator
1300         //                internal String sThousandSeparator       ; // (user can override) thousands separator
1301
1302         // Not a Number
1303         internal String SNAN
1304         {
1305             get
1306             {
1307                 if (this.sNaN == null)
1308                 {
1309                     this.sNaN = DoGetLocaleInfo(LOCALE_SNAN);
1310                 }
1311                 return this.sNaN;
1312             }
1313         }
1314
1315         // + Infinity
1316         internal String SPOSINFINITY
1317         {
1318             get
1319             {
1320                 if (this.sPositiveInfinity == null)
1321                 {
1322                     this.sPositiveInfinity = DoGetLocaleInfo(LOCALE_SPOSINFINITY);
1323                 }
1324                 return this.sPositiveInfinity;
1325             }
1326         }
1327
1328         // - Infinity
1329         internal String SNEGINFINITY
1330         {
1331             get
1332             {
1333                 if (this.sNegativeInfinity == null)
1334                 {
1335                     this.sNegativeInfinity = DoGetLocaleInfo(LOCALE_SNEGINFINITY);
1336                 }
1337                 return this.sNegativeInfinity;
1338             }
1339         }
1340
1341
1342         ////////////
1343         // Percent //
1344         ///////////
1345
1346         // Negative Percent (0-3)
1347         internal int INEGATIVEPERCENT
1348         {
1349             get
1350             {
1351                 if (this.iNegativePercent == undef)
1352                 {
1353                     // Note that <= Windows Vista this is synthesized by native code
1354                     this.iNegativePercent = DoGetLocaleInfoInt(LOCALE_INEGATIVEPERCENT);
1355                 }
1356                 return this.iNegativePercent;
1357             }
1358         }
1359
1360         // Positive Percent (0-11)
1361         internal int IPOSITIVEPERCENT
1362         {
1363             get
1364             {
1365                 if (this.iPositivePercent == undef)
1366                 {
1367                     // Note that <= Windows Vista this is synthesized by native code
1368                     this.iPositivePercent = DoGetLocaleInfoInt(LOCALE_IPOSITIVEPERCENT);
1369                 }
1370                 return this.iPositivePercent;
1371             }
1372         }
1373
1374         // Percent (%) symbol
1375         internal String SPERCENT
1376         {
1377             get
1378             {
1379                 if (this.sPercent == null)
1380                 {
1381                     // Note that <= Windows Vista this is synthesized by native code
1382                     this.sPercent = DoGetLocaleInfo(LOCALE_SPERCENT);
1383                 }
1384                 return this.sPercent;
1385             }
1386         }
1387
1388         // PerMille (‰) symbol
1389         internal String SPERMILLE
1390         {
1391             get
1392             {
1393                 if (this.sPerMille == null)
1394                 {
1395                     // Note that <= Windows Vista this is synthesized by native code
1396                     this.sPerMille = DoGetLocaleInfo(LOCALE_SPERMILLE);
1397                 }
1398                 return this.sPerMille;
1399             }
1400         }
1401
1402         /////////////
1403         // Currency //
1404         /////////////
1405
1406         // (user can override) local monetary symbol, eg: $
1407         internal String SCURRENCY
1408         {
1409             get
1410             {
1411                 if (this.sCurrency == null || UseUserOverride)
1412                 {
1413                     this.sCurrency = DoGetLocaleInfo(LOCALE_SCURRENCY);
1414                 }
1415                 return this.sCurrency;
1416             }
1417         }
1418
1419         // international monetary symbol (RegionInfo), eg: USD
1420         internal String SINTLSYMBOL
1421         {
1422             get
1423             {
1424                 if (this.sIntlMonetarySymbol == null)
1425                 {
1426                     this.sIntlMonetarySymbol = DoGetLocaleInfo(LOCALE_SINTLSYMBOL);
1427                 }
1428                 return this.sIntlMonetarySymbol;
1429             }
1430         }
1431
1432         // English name for this currency (RegionInfo), eg: US Dollar
1433         internal String SENGLISHCURRENCY
1434         {
1435             get
1436             {
1437                 if (this.sEnglishCurrency == null)
1438                 {
1439                     this.sEnglishCurrency = DoGetLocaleInfo(LOCALE_SENGCURRNAME);
1440                 }
1441                 return this.sEnglishCurrency;
1442             }
1443         }
1444
1445         // Native name for this currency (RegionInfo), eg: Schweiz Frank
1446         internal String SNATIVECURRENCY
1447         {
1448             get
1449             {
1450                 if (this.sNativeCurrency == null)
1451                 {
1452                     this.sNativeCurrency = DoGetLocaleInfo(LOCALE_SNATIVECURRNAME);
1453                 }
1454                 return this.sNativeCurrency;
1455             }
1456         }
1457
1458         //                internal int iCurrencyDigits          ; // (user can override) # local monetary fractional digits
1459         //                internal int iCurrency                ; // (user can override) positive currency format
1460         //                internal int iNegativeCurrency        ; // (user can override) negative currency format
1461
1462         // (user can override) monetary grouping of digits
1463         internal int[] WAMONGROUPING
1464         {
1465             get
1466             {
1467                 if (this.waMonetaryGrouping == null || UseUserOverride)
1468                 {
1469                     this.waMonetaryGrouping = ConvertWin32GroupString(DoGetLocaleInfo(LOCALE_SMONGROUPING));
1470                 }
1471                 return this.waMonetaryGrouping;
1472             }
1473         }
1474
1475         //                internal String sMonetaryDecimal         ; // (user can override) monetary decimal separator
1476         //                internal String sMonetaryThousand        ; // (user can override) monetary thousands separator
1477
1478         /////////
1479         // Misc //
1480         /////////
1481
1482         // (user can override) system of measurement 0=metric, 1=US (RegionInfo)
1483         internal int IMEASURE
1484         {
1485             get
1486             {
1487                 if (this.iMeasure == undef || UseUserOverride)
1488                 {
1489                     this.iMeasure = DoGetLocaleInfoInt(LOCALE_IMEASURE);
1490                 }
1491                 return this.iMeasure;
1492             }
1493         }
1494
1495         // (user can override) list Separator
1496         internal String SLIST
1497         {
1498             get
1499             {
1500                 if (this.sListSeparator == null || UseUserOverride)
1501                 {
1502                     this.sListSeparator = DoGetLocaleInfo(LOCALE_SLIST);
1503                 }
1504                 return this.sListSeparator;
1505             }
1506         }
1507
1508         // Paper size
1509         private int IPAPERSIZE
1510         {
1511             get
1512             {
1513                 return DoGetLocaleInfoInt(LOCALE_IPAPERSIZE);
1514             }
1515         }
1516
1517         ////////////////////////////
1518         // Calendar/Time (Gregorian) //
1519         ////////////////////////////
1520
1521         // (user can override) AM designator
1522         internal String SAM1159
1523         {
1524             get
1525             {
1526                 if (this.sAM1159 == null || UseUserOverride)
1527                 {
1528                     this.sAM1159 = DoGetLocaleInfo(LOCALE_S1159);
1529                 }
1530                 return this.sAM1159;
1531             }
1532         }
1533
1534         // (user can override) PM designator
1535         internal String SPM2359
1536         {
1537             get
1538             {
1539                 if (this.sPM2359 == null || UseUserOverride)
1540                 {
1541                     this.sPM2359 = DoGetLocaleInfo(LOCALE_S2359);
1542                 }
1543                 return this.sPM2359;
1544             }
1545         }
1546
1547         // (user can override) time format
1548         internal String[] LongTimes
1549         {
1550             get
1551             {
1552                 if (this.saLongTimes == null || UseUserOverride)
1553                 {
1554                     String[] longTimes = DoEnumTimeFormats();
1555                     if (longTimes == null || longTimes.Length == 0)
1556                     {
1557                         this.saLongTimes = Invariant.saLongTimes;
1558                     }
1559                     else
1560                     {
1561                         this.saLongTimes = longTimes;
1562                     }
1563                 }
1564                 return this.saLongTimes;
1565             }
1566         }
1567
1568         // short time format
1569         // Short times (derived from long times format)
1570         internal String[] ShortTimes
1571         {
1572             get
1573             {
1574                 if (this.saShortTimes == null || UseUserOverride)
1575                 {
1576                     // Try to get the short times from the OS/culture.dll
1577                     String[] shortTimes = DoEnumShortTimeFormats();
1578
1579                     if (shortTimes == null || shortTimes.Length == 0)
1580                     {
1581                         //
1582                         // If we couldn't find short times, then compute them from long times
1583                         // (eg: CORECLR on < Win7 OS & fallback for missing culture.dll)
1584                         //
1585                         shortTimes = DeriveShortTimesFromLong();
1586                     }
1587
1588                     // Found short times, use them
1589                     this.saShortTimes = shortTimes;
1590                 }
1591                 return this.saShortTimes;
1592             }
1593         }
1594
1595         private string[] DeriveShortTimesFromLong()
1596         {
1597             // Our logic is to look for h,H,m,s,t.  If we find an s, then we check the string
1598             // between it and the previous marker, if any.  If its a short, unescaped separator,
1599             // then we don't retain that part.
1600             // We then check after the ss and remove anything before the next h,H,m,t...
1601             string[] shortTimes = new string[LongTimes.Length];
1602
1603             for (int i = 0; i < LongTimes.Length; i++)
1604             {
1605                 shortTimes[i] = StripSecondsFromPattern(LongTimes[i]);
1606             }
1607             return shortTimes;
1608         }
1609
1610         private static string StripSecondsFromPattern(string time)
1611         {
1612             bool bEscape = false;
1613             int iLastToken = -1;
1614
1615             // Find the seconds
1616             for (int j = 0; j < time.Length; j++)
1617             {
1618                 // Change escape mode?
1619                 if (time[j] == '\'')
1620                 {
1621                     // Continue
1622                     bEscape = !bEscape;
1623                     continue;
1624                 }
1625
1626                 // See if there was a single \
1627                 if (time[j] == '\\')
1628                 {
1629                     // Skip next char
1630                     j++;
1631                     continue;
1632                 }
1633
1634                 if (bEscape)
1635                 {
1636                     continue;
1637                 }
1638
1639                 switch (time[j])
1640                 {
1641                     // Check for seconds
1642                     case 's':
1643                         // Found seconds, see if there was something unescaped and short between
1644                         // the last marker and the seconds.  Windows says separator can be a
1645                         // maximum of three characters (without null)
1646                         // If 1st or last characters were ', then ignore it
1647                         if ((j - iLastToken) <= 4 && (j - iLastToken) > 1 &&
1648                             (time[iLastToken + 1] != '\'') &&
1649                             (time[j - 1] != '\''))
1650                         {
1651                             // There was something there we want to remember
1652                             if (iLastToken >= 0)
1653                             {
1654                                 j = iLastToken + 1;
1655                             }
1656                         }
1657
1658                         bool containsSpace;
1659                         int endIndex = GetIndexOfNextTokenAfterSeconds(time, j, out containsSpace);
1660                         StringBuilder sb = new StringBuilder(time.Substring(0, j));
1661                         if (containsSpace)
1662                         {
1663                             sb.Append(' ');
1664                         }
1665                         sb.Append(time.Substring(endIndex));
1666                         time = sb.ToString();
1667                         break;
1668                     case 'm':
1669                     case 'H':
1670                     case 'h':
1671                         iLastToken = j;
1672                         break;
1673                 }
1674             }
1675             return time;
1676         }
1677
1678         private static int GetIndexOfNextTokenAfterSeconds(string time, int index, out bool containsSpace)
1679         {
1680             bool bEscape = false;
1681             containsSpace = false;
1682             for (; index < time.Length; index++)
1683             {
1684                 switch (time[index])
1685                 {
1686                     case '\'':
1687                         bEscape = !bEscape;
1688                         continue;
1689                     case '\\':
1690                         index++;
1691                         if (time[index] == ' ')
1692                         {
1693                             containsSpace = true;
1694                         }
1695                         continue;
1696                     case ' ':
1697                         containsSpace = true;
1698                         break;
1699                     case 't':
1700                     case 'm':
1701                     case 'H':
1702                     case 'h':
1703                         if (bEscape)
1704                         {
1705                             continue;
1706                         }
1707                         return index;
1708                 }
1709             }
1710             containsSpace = false;
1711             return index;
1712         }
1713
1714         // time duration format
1715         internal String[] SADURATION
1716         {
1717             get
1718             {
1719                 if (this.saDurationFormats == null)
1720                 {
1721                     String durationFormat = DoGetLocaleInfo(LOCALE_SDURATION);
1722                     this.saDurationFormats = new String[] { ReescapeWin32String(durationFormat) };
1723                 }
1724                 return this.saDurationFormats;
1725             }
1726         }
1727
1728         // (user can override) first day of week
1729         internal int IFIRSTDAYOFWEEK
1730         {
1731             get
1732             {
1733                 if (this.iFirstDayOfWeek == undef || UseUserOverride)
1734                 {
1735                     // Have to convert it from windows to .Net formats
1736                     this.iFirstDayOfWeek = ConvertFirstDayOfWeekMonToSun(DoGetLocaleInfoInt(LOCALE_IFIRSTDAYOFWEEK));
1737                 }
1738                 return this.iFirstDayOfWeek;
1739             }
1740         }
1741
1742         // (user can override) first week of year
1743         internal int IFIRSTWEEKOFYEAR
1744         {
1745             get
1746             {
1747                 if (this.iFirstWeekOfYear == undef || UseUserOverride)
1748                 {
1749                     this.iFirstWeekOfYear = DoGetLocaleInfoInt(LOCALE_IFIRSTWEEKOFYEAR);
1750                 }
1751                 return this.iFirstWeekOfYear;
1752             }
1753         }
1754
1755         // (user can override default only) short date format
1756         internal String[] ShortDates(int calendarId)
1757         {
1758             return GetCalendar(calendarId).saShortDates;
1759         }
1760
1761         // (user can override default only) long date format
1762         internal String[] LongDates(int calendarId)
1763         {
1764             return GetCalendar(calendarId).saLongDates;
1765         }
1766
1767         // (user can override) date year/month format.
1768         internal String[] YearMonths(int calendarId)
1769         {
1770             return GetCalendar(calendarId).saYearMonths;
1771         }
1772
1773         // day names
1774         internal string[] DayNames(int calendarId)
1775         {
1776             return GetCalendar(calendarId).saDayNames;
1777         }
1778
1779         // abbreviated day names
1780         internal string[] AbbreviatedDayNames(int calendarId)
1781         {
1782             // Get abbreviated day names for this calendar from the OS if necessary
1783             return GetCalendar(calendarId).saAbbrevDayNames;
1784         }
1785
1786         // The super short day names
1787         internal string[] SuperShortDayNames(int calendarId)
1788         {
1789             return GetCalendar(calendarId).saSuperShortDayNames;
1790         }
1791
1792         // month names
1793         internal string[] MonthNames(int calendarId)
1794         {
1795             return GetCalendar(calendarId).saMonthNames;
1796         }
1797
1798         // Genitive month names
1799         internal string[] GenitiveMonthNames(int calendarId)
1800         {
1801             return GetCalendar(calendarId).saMonthGenitiveNames;
1802         }
1803
1804         // month names
1805         internal string[] AbbreviatedMonthNames(int calendarId)
1806         {
1807             return GetCalendar(calendarId).saAbbrevMonthNames;
1808         }
1809
1810         // Genitive month names
1811         internal string[] AbbreviatedGenitiveMonthNames(int calendarId)
1812         {
1813             return GetCalendar(calendarId).saAbbrevMonthGenitiveNames;
1814         }
1815
1816         // Leap year month names
1817         // Note: This only applies to Hebrew, and it basically adds a "1" to the 6th month name
1818         // the non-leap names skip the 7th name in the normal month name array
1819         internal string[] LeapYearMonthNames(int calendarId)
1820         {
1821             return GetCalendar(calendarId).saLeapYearMonthNames;
1822         }
1823
1824         // month/day format (single string, no override)
1825         internal String MonthDay(int calendarId)
1826         {
1827             return GetCalendar(calendarId).sMonthDay;
1828         }
1829
1830
1831
1832         /////////////
1833         // Calendars //
1834         /////////////
1835
1836         // all available calendar type(s), The first one is the default calendar.
1837         internal int[] CalendarIds
1838         {
1839             get
1840             {
1841                 if (this.waCalendars == null)
1842                 {
1843                     // We pass in an array of ints, and native side fills it up with count calendars.
1844                     // We then have to copy that list to a new array of the right size.
1845                     // Default calendar should be first
1846                     int[] calendarInts = new int[23];
1847                     Contract.Assert(this.sWindowsName != null, "[CultureData.CalendarIds] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
1848                     int count = CalendarData.nativeGetCalendars(this.sWindowsName, this.bUseOverrides, calendarInts);
1849
1850                     // See if we had a calendar to add.
1851                     if (count == 0)
1852                     {
1853                         // Failed for some reason, just grab Gregorian from Invariant
1854                         this.waCalendars = Invariant.waCalendars;
1855                     }
1856                     else
1857                     {
1858                         // The OS may not return calendar 4 for zh-TW, but we've always allowed it.
1859                         if (this.sWindowsName == "zh-TW")
1860                         {
1861                             bool found = false;
1862
1863                             // Do we need to insert calendar 4?
1864                             for (int i = 0; i < count; i++)
1865                             {
1866                                 // Stop if we found calendar four
1867                                 if (calendarInts[i] == Calendar.CAL_TAIWAN)
1868                                 {
1869                                     found = true;
1870                                     break;
1871                                 }
1872                             }
1873
1874                             // If not found then insert it
1875                             if (!found)
1876                             {
1877                                 // Insert it as the 2nd calendar
1878                                 count++;
1879                                 // Copy them from the 2nd position to the end, -1 for skipping 1st, -1 for one being added.
1880                                 Array.Copy(calendarInts, 1, calendarInts, 2, 23 - 1 - 1);
1881                                 calendarInts[1] = Calendar.CAL_TAIWAN;
1882                             }
1883                         }
1884
1885                         // It worked, remember the list
1886                         int[] temp = new int[count];
1887                         Array.Copy(calendarInts, temp, count);
1888
1889                         // Want 1st calendar to be default
1890                         // Prior to Vista the enumeration didn't have default calendar first
1891                         // Only a coreclr concern, culture.dll does the right thing.
1892                         if (temp.Length > 1)
1893                         {
1894                             int i = DoGetLocaleInfoInt(LOCALE_ICALENDARTYPE);
1895                             if (temp[1] == i)
1896                             {
1897                                 temp[1] = temp[0];
1898                                 temp[0] = i;
1899                             }
1900                         }
1901
1902                         this.waCalendars = temp;
1903                     }
1904                 }
1905
1906                 return this.waCalendars;
1907             }
1908         }
1909
1910         // Native calendar names.  index of optional calendar - 1, empty if no optional calendar at that number
1911         internal String CalendarName(int calendarId)
1912         {
1913             // Get the calendar
1914             return GetCalendar(calendarId).sNativeName;
1915         }
1916
1917         internal CalendarData GetCalendar(int calendarId)
1918         {
1919             Contract.Assert(calendarId > 0 && calendarId <= CalendarData.MAX_CALENDARS,
1920                 "[CultureData.GetCalendar] Expect calendarId to be in a valid range");
1921
1922             // arrays are 0 based, calendarIds are 1 based
1923             int calendarIndex = calendarId - 1;
1924
1925             // Have to have calendars
1926             if (calendars == null)
1927             {
1928                 calendars = new CalendarData[CalendarData.MAX_CALENDARS];
1929             }
1930
1931             // we need the following local variable to avoid returning null
1932             // when another thread creates a new array of CalendarData (above)
1933             // right after we insert the newly created CalendarData (below)
1934             CalendarData calendarData = calendars[calendarIndex];
1935             // Make sure that calendar has data
1936             if (calendarData == null || UseUserOverride)
1937             {
1938                 Contract.Assert(this.sWindowsName != null, "[CultureData.GetCalendar] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
1939                 calendarData = new CalendarData(this.sWindowsName, calendarId, this.UseUserOverride);
1940                 calendars[calendarIndex] = calendarData;
1941             }
1942
1943             return calendarData;
1944         }
1945
1946         internal int CurrentEra(int calendarId)
1947         {
1948             return GetCalendar(calendarId).iCurrentEra;
1949         }
1950
1951         ///////////////////
1952         // Text Information //
1953         ///////////////////
1954
1955         // IsRightToLeft
1956         internal bool IsRightToLeft
1957         {
1958             get
1959             {
1960                 // Returns one of the following 4 reading layout values:
1961                 // 0 - Left to right (eg en-US)
1962                 // 1 - Right to left (eg arabic locales)
1963                 // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
1964                 // 3 - Vertical top to bottom with columns proceeding to the right
1965                 return (this.IREADINGLAYOUT == 1);
1966             }
1967         }
1968
1969         // IREADINGLAYOUT
1970         // Returns one of the following 4 reading layout values:
1971         // 0 - Left to right (eg en-US)
1972         // 1 - Right to left (eg arabic locales)
1973         // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
1974         // 3 - Vertical top to bottom with columns proceeding to the right
1975         //
1976         // If exposed as a public API, we'd have an enum with those 4 values
1977         private int IREADINGLAYOUT
1978         {
1979             get
1980             {
1981                 if (this.iReadingLayout == undef)
1982                 {
1983                     Contract.Assert(this.sRealName != null, "[CultureData.IsRightToLeft] Expected this.sRealName to be populated by COMNlsInfo::nativeInitCultureData already");
1984                     this.iReadingLayout = DoGetLocaleInfoInt(LOCALE_IREADINGLAYOUT);
1985                 }
1986
1987                 return (this.iReadingLayout);
1988             }
1989         }
1990
1991         // The TextInfo name never includes that alternate sort and is always specific
1992         // For customs, it uses the SortLocale (since the textinfo is not exposed in Win7)
1993         // en -> en-US
1994         // en-US -> en-US
1995         // fj (custom neutral) -> en-US (assuming that en-US is the sort locale for fj)
1996         // fj_FJ (custom specific) -> en-US (assuming that en-US is the sort locale for fj-FJ)
1997         // es-ES_tradnl -> es-ES
1998         internal String STEXTINFO               // Text info name to use for text information
1999         {
2000             get
2001             {
2002                 if (this.sTextInfo == null)
2003                 {
2004                     // LOCALE_SSORTLOCALE is broken in Win7 for Alt sorts.
2005                     // It is also not supported downlevel without culture.dll.
2006                     if (IsNeutralCulture || IsSupplementalCustomCulture)
2007                     {
2008                         string sortLocale = DoGetLocaleInfo(LOCALE_SSORTLOCALE);
2009                         this.sTextInfo = GetCultureData(sortLocale, bUseOverrides).SNAME;
2010                     }
2011
2012                     if (this.sTextInfo == null)
2013                     {
2014                         this.sTextInfo = this.SNAME; // removes alternate sort
2015                     }
2016                 }
2017
2018                 return this.sTextInfo;
2019             }
2020         }
2021
2022         // Compare info name (including sorting key) to use if custom
2023         internal String SCOMPAREINFO
2024         {
2025             get
2026             {
2027                 if (this.sCompareInfo == null)
2028                 {
2029                     // LOCALE_SSORTLOCALE is broken in Win7 for Alt sorts.
2030                     // It is also not supported downlevel without culture.dll.
2031                     // We really only need it for the custom locale case though
2032                     // since for all other cases, it is the same as sWindowsName
2033                     if (IsSupplementalCustomCulture)
2034                     {
2035                         this.sCompareInfo = DoGetLocaleInfo(LOCALE_SSORTLOCALE);
2036                     }
2037
2038                     if (this.sCompareInfo == null)
2039                     {
2040                         this.sCompareInfo = this.sWindowsName;
2041                     }
2042                 }
2043
2044                 return this.sCompareInfo;
2045             }
2046         }
2047
2048         internal bool IsSupplementalCustomCulture
2049         {
2050             get
2051             {
2052                 return IsCustomCultureId(this.ILANGUAGE);
2053             }
2054         }
2055
2056         // Typical Scripts for this locale (latn;cyrl; etc)
2057
2058         private String SSCRIPTS
2059         {
2060             get
2061             {
2062                 if (this.sScripts == null)
2063                 {
2064                     this.sScripts = DoGetLocaleInfo(LOCALE_SSCRIPTS);
2065                 }
2066                 return this.sScripts;
2067             }
2068         }
2069
2070         private String SOPENTYPELANGUAGETAG
2071         {
2072             get
2073             {
2074                 return DoGetLocaleInfo(LOCALE_SOPENTYPELANGUAGETAG);
2075             }
2076         }
2077
2078         private String FONTSIGNATURE
2079         {
2080             get
2081             {
2082                 if (this.fontSignature == null)
2083                 {
2084                     this.fontSignature = DoGetLocaleInfo(LOCALE_FONTSIGNATURE);
2085                 }
2086                 return this.fontSignature;
2087             }
2088         }
2089
2090         private String SKEYBOARDSTOINSTALL
2091         {
2092             get
2093             {
2094                 return DoGetLocaleInfo(LOCALE_SKEYBOARDSTOINSTALL);
2095             }
2096         }
2097
2098
2099         internal int IDEFAULTANSICODEPAGE   // default ansi code page ID (ACP)
2100         {
2101             get
2102             {
2103                 if (this.iDefaultAnsiCodePage == undef)
2104                 {
2105                     this.iDefaultAnsiCodePage = DoGetLocaleInfoInt(LOCALE_IDEFAULTANSICODEPAGE);
2106                 }
2107                 return this.iDefaultAnsiCodePage;
2108             }
2109         }
2110
2111         internal int IDEFAULTOEMCODEPAGE   // default oem code page ID (OCP or OEM)
2112         {
2113             get
2114             {
2115                 if (this.iDefaultOemCodePage == undef)
2116                 {
2117                     this.iDefaultOemCodePage = DoGetLocaleInfoInt(LOCALE_IDEFAULTCODEPAGE);
2118                 }
2119                 return this.iDefaultOemCodePage;
2120             }
2121         }
2122
2123         internal int IDEFAULTMACCODEPAGE   // default macintosh code page
2124         {
2125             get
2126             {
2127                 if (this.iDefaultMacCodePage == undef)
2128                 {
2129                     this.iDefaultMacCodePage = DoGetLocaleInfoInt(LOCALE_IDEFAULTMACCODEPAGE);
2130                 }
2131                 return this.iDefaultMacCodePage;
2132             }
2133         }
2134
2135         internal int IDEFAULTEBCDICCODEPAGE   // default EBCDIC code page
2136         {
2137             get
2138             {
2139                 if (this.iDefaultEbcdicCodePage == undef)
2140                 {
2141                     this.iDefaultEbcdicCodePage = DoGetLocaleInfoInt(LOCALE_IDEFAULTEBCDICCODEPAGE);
2142                 }
2143                 return this.iDefaultEbcdicCodePage;
2144             }
2145         }
2146
2147         // Obtain locale name from LCID
2148         // NOTE: This will get neutral names, unlike the OS API
2149         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2150         internal static extern int LocaleNameToLCID(String localeName);
2151
2152         // These are desktop only, not coreclr
2153         // locale ID (0409), including sort information
2154         internal int ILANGUAGE
2155         {
2156             get
2157             {
2158                 if (this.iLanguage == 0)
2159                 {
2160                     Contract.Assert(this.sRealName != null, "[CultureData.ILANGUAGE] Expected this.sRealName to be populated by COMNlsInfo::nativeInitCultureData already");
2161                     this.iLanguage = LocaleNameToLCID(this.sRealName);
2162                 }
2163                 return this.iLanguage;
2164             }
2165         }
2166
2167         internal bool IsWin32Installed
2168         {
2169             get { return this.bWin32Installed; }
2170         }
2171
2172         internal bool IsFramework
2173         {
2174             get { return this.bFramework; }
2175         }
2176
2177         ////////////////////
2178         // Derived properties //
2179         ////////////////////
2180
2181         internal bool IsNeutralCulture
2182         {
2183             get
2184             {
2185                 // NlsInfo::nativeInitCultureData told us if we're neutral or not
2186                 return this.bNeutral;
2187             }
2188         }
2189
2190         internal bool IsInvariantCulture
2191         {
2192             get
2193             {
2194                 return String.IsNullOrEmpty(this.SNAME);
2195             }
2196         }
2197
2198         // Get an instance of our default calendar
2199         internal Calendar DefaultCalendar
2200         {
2201             get
2202             {
2203                 int defaultCalId = DoGetLocaleInfoInt(LOCALE_ICALENDARTYPE);
2204                 if (defaultCalId == 0)
2205                 {
2206                     defaultCalId = this.CalendarIds[0];
2207                 }
2208
2209                 return CultureInfo.GetCalendarInstance(defaultCalId);
2210             }
2211         }
2212
2213         // All of our era names
2214         internal String[] EraNames(int calendarId)
2215         {
2216             Contract.Assert(calendarId > 0, "[CultureData.saEraNames] Expected Calendar.ID > 0");
2217
2218             return this.GetCalendar(calendarId).saEraNames;
2219         }
2220
2221         internal String[] AbbrevEraNames(int calendarId)
2222         {
2223             Contract.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
2224
2225             return this.GetCalendar(calendarId).saAbbrevEraNames;
2226         }
2227
2228         internal String[] AbbreviatedEnglishEraNames(int calendarId)
2229         {
2230             Contract.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
2231
2232             return this.GetCalendar(calendarId).saAbbrevEnglishEraNames;
2233         }
2234
2235         // String array DEFAULTS
2236         // Note: GetDTFIOverrideValues does the user overrides for these, so we don't have to.
2237
2238
2239         // Time separator (derived from time format)
2240         internal String TimeSeparator
2241         {
2242             get
2243             {
2244                 if (sTimeSeparator == null || UseUserOverride)
2245                 {
2246                     string longTimeFormat = ReescapeWin32String(DoGetLocaleInfo(LOCALE_STIMEFORMAT));
2247                     if (String.IsNullOrEmpty(longTimeFormat))
2248                     {
2249                         longTimeFormat = LongTimes[0];
2250                     }
2251
2252                     // Compute STIME from time format
2253                     sTimeSeparator = GetTimeSeparator(longTimeFormat);
2254                 }
2255                 return sTimeSeparator;
2256             }
2257         }
2258
2259         // Date separator (derived from short date format)
2260         internal String DateSeparator(int calendarId)
2261         {
2262             return GetDateSeparator(ShortDates(calendarId)[0]);
2263         }
2264
2265         //////////////////////////////////////
2266         // Helper Functions to get derived properties //
2267         //////////////////////////////////////
2268
2269         ////////////////////////////////////////////////////////////////////////////
2270         //
2271         // Unescape a NLS style quote string
2272         //
2273         // This removes single quotes:
2274         //      'fred' -> fred
2275         //      'fred -> fred
2276         //      fred' -> fred
2277         //      fred's -> freds
2278         //
2279         // This removes the first \ of escaped characters:
2280         //      fred\'s -> fred's
2281         //      a\\b -> a\b
2282         //      a\b -> ab
2283         //
2284         // We don't build the stringbuilder unless we find a ' or a \.  If we find a ' or a \, we
2285         // always build a stringbuilder because we need to remove the ' or \.
2286         //
2287         ////////////////////////////////////////////////////////////////////////////
2288         static private String UnescapeNlsString(String str, int start, int end)
2289         {
2290             Contract.Requires(str != null);
2291             Contract.Requires(start >= 0);
2292             Contract.Requires(end >= 0);
2293             StringBuilder result = null;
2294
2295             for (int i = start; i < str.Length && i <= end; i++)
2296             {
2297                 switch (str[i])
2298                 {
2299                     case '\'':
2300                         if (result == null)
2301                         {
2302                             result = new StringBuilder(str, start, i - start, str.Length);
2303                         }
2304                         break;
2305                     case '\\':
2306                         if (result == null)
2307                         {
2308                             result = new StringBuilder(str, start, i - start, str.Length);
2309                         }
2310                         ++i;
2311                         if (i < str.Length)
2312                         {
2313                             result.Append(str[i]);
2314                         }
2315                         break;
2316                     default:
2317                         if (result != null)
2318                         {
2319                             result.Append(str[i]);
2320                         }
2321                         break;
2322                 }
2323             }
2324
2325             if (result == null)
2326                 return (str.Substring(start, end - start + 1));
2327
2328             return (result.ToString());
2329         }
2330
2331         ////////////////////////////////////////////////////////////////////////////
2332         //
2333         // Reescape a Win32 style quote string as a NLS+ style quoted string
2334         //
2335         // This is also the escaping style used by custom culture data files
2336         //
2337         // NLS+ uses \ to escape the next character, whether in a quoted string or
2338         // not, so we always have to change \ to \\.
2339         //
2340         // NLS+ uses \' to escape a quote inside a quoted string so we have to change
2341         // '' to \' (if inside a quoted string)
2342         //
2343         // We don't build the stringbuilder unless we find something to change
2344         ////////////////////////////////////////////////////////////////////////////
2345         static internal String ReescapeWin32String(String str)
2346         {
2347             // If we don't have data, then don't try anything
2348             if (str == null)
2349                 return null;
2350
2351             StringBuilder result = null;
2352
2353             bool inQuote = false;
2354             for (int i = 0; i < str.Length; i++)
2355             {
2356                 // Look for quote
2357                 if (str[i] == '\'')
2358                 {
2359                     // Already in quote?
2360                     if (inQuote)
2361                     {
2362                         // See another single quote.  Is this '' of 'fred''s' or '''', or is it an ending quote?
2363                         if (i + 1 < str.Length && str[i + 1] == '\'')
2364                         {
2365                             // Found another ', so we have ''.  Need to add \' instead.
2366                             // 1st make sure we have our stringbuilder
2367                             if (result == null)
2368                                 result = new StringBuilder(str, 0, i, str.Length * 2);
2369
2370                             // Append a \' and keep going (so we don't turn off quote mode)
2371                             result.Append("\\'");
2372                             i++;
2373                             continue;
2374                         }
2375
2376                         // Turning off quote mode, fall through to add it
2377                         inQuote = false;
2378                     }
2379                     else
2380                     {
2381                         // Found beginning quote, fall through to add it
2382                         inQuote = true;
2383                     }
2384                 }
2385                 // Is there a single \ character?
2386                 else if (str[i] == '\\')
2387                 {
2388                     // Found a \, need to change it to \\
2389                     // 1st make sure we have our stringbuilder
2390                     if (result == null)
2391                         result = new StringBuilder(str, 0, i, str.Length * 2);
2392
2393                     // Append our \\ to the string & continue
2394                     result.Append("\\\\");
2395                     continue;
2396                 }
2397
2398                 // If we have a builder we need to add our character
2399                 if (result != null)
2400                     result.Append(str[i]);
2401             }
2402
2403             // Unchanged string? , just return input string
2404             if (result == null)
2405                 return str;
2406
2407             // String changed, need to use the builder
2408             return result.ToString();
2409         }
2410
2411         static internal String[] ReescapeWin32Strings(String[] array)
2412         {
2413             if (array != null)
2414             {
2415                 for (int i = 0; i < array.Length; i++)
2416                 {
2417                     array[i] = ReescapeWin32String(array[i]);
2418                 }
2419             }
2420
2421             return array;
2422         }
2423
2424         // NOTE: this method is used through reflection by System.Globalization.CultureXmlParser.ReadDateElement()
2425         // and breaking changes here will not show up at build time, only at run time.
2426         static private String GetTimeSeparator(String format)
2427         {
2428             // Time format separator (ie: : in 12:39:00)
2429             //
2430             // We calculate this from the provided time format
2431             //
2432
2433             //
2434             //  Find the time separator so that we can pretend we know STIME.
2435             //
2436             return GetSeparator(format, "Hhms");
2437         }
2438
2439         // NOTE: this method is used through reflection by System.Globalization.CultureXmlParser.ReadDateElement()
2440         // and breaking changes here will not show up at build time, only at run time.
2441         static private String GetDateSeparator(String format)
2442         {
2443             // Date format separator (ie: / in 9/1/03)
2444             //
2445             // We calculate this from the provided short date
2446             //
2447
2448             //
2449             //  Find the date separator so that we can pretend we know SDATE.
2450             //
2451             return GetSeparator(format, "dyM");
2452         }
2453
2454         private static string GetSeparator(string format, string timeParts)
2455         {
2456             int index = IndexOfTimePart(format, 0, timeParts);
2457
2458             if (index != -1)
2459             {
2460                 // Found a time part, find out when it changes
2461                 char cTimePart = format[index];
2462
2463                 do
2464                 {
2465                     index++;
2466                 } while (index < format.Length && format[index] == cTimePart);
2467
2468                 int separatorStart = index;
2469
2470                 // Now we need to find the end of the separator
2471                 if (separatorStart < format.Length)
2472                 {
2473                     int separatorEnd = IndexOfTimePart(format, separatorStart, timeParts);
2474                     if (separatorEnd != -1)
2475                     {
2476                         // From [separatorStart, count) is our string, except we need to unescape
2477                         return UnescapeNlsString(format, separatorStart, separatorEnd - 1);
2478                     }
2479                 }
2480             }
2481
2482             return String.Empty;
2483         }
2484
2485         private static int IndexOfTimePart(string format, int startIndex, string timeParts)
2486         {
2487             Contract.Assert(startIndex >= 0, "startIndex cannot be negative");
2488             Contract.Assert(timeParts.IndexOfAny(new char[] { '\'', '\\' }) == -1, "timeParts cannot include quote characters");
2489             bool inQuote = false;
2490             for (int i = startIndex; i < format.Length; ++i)
2491             {
2492                 // See if we have a time Part
2493                 if (!inQuote && timeParts.IndexOf(format[i]) != -1)
2494                 {
2495                     return i;
2496                 }
2497                 switch (format[i])
2498                 {
2499                     case '\\':
2500                         if (i + 1 < format.Length)
2501                         {
2502                             ++i;
2503                             switch (format[i])
2504                             {
2505                                 case '\'':
2506                                 case '\\':
2507                                     break;
2508                                 default:
2509                                     --i; //backup since we will move over this next
2510                                     break;
2511                             }
2512                         }
2513                         break;
2514                     case '\'':
2515                         inQuote = !inQuote;
2516                         break;
2517                 }
2518             }
2519
2520             return -1;
2521         }
2522
2523         string DoGetLocaleInfo(uint lctype)
2524         {
2525             Contract.Assert(this.sWindowsName != null, "[CultureData.DoGetLocaleInfo] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
2526             return DoGetLocaleInfo(this.sWindowsName, lctype);
2527         }
2528
2529         // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the
2530         // "windows" name, which can be specific for downlevel (< windows 7) os's.
2531         string DoGetLocaleInfo(string localeName, uint lctype)
2532         {
2533             // Fix lctype if we don't want overrides
2534             if (!UseUserOverride)
2535             {
2536                 lctype |= LOCALE_NOUSEROVERRIDE;
2537             }
2538
2539             // Ask OS for data
2540             Contract.Assert(localeName != null, "[CultureData.DoGetLocaleInfo] Expected localeName to be not be null");
2541             string result = CultureInfo.nativeGetLocaleInfoEx(localeName, lctype);
2542             if (result == null)
2543             {
2544                 // Failed, just use empty string
2545                 result = String.Empty;
2546             }
2547
2548             return result;
2549         }
2550
2551         int DoGetLocaleInfoInt(uint lctype)
2552         {
2553             // Fix lctype if we don't want overrides
2554             if (!UseUserOverride)
2555             {
2556                 lctype |= LOCALE_NOUSEROVERRIDE;
2557             }
2558
2559             // Ask OS for data, note that we presume it returns success, so we have to know that
2560             // sWindowsName is valid before calling.
2561             Contract.Assert(this.sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
2562             int result = CultureInfo.nativeGetLocaleInfoExInt(this.sWindowsName, lctype);
2563
2564             return result;
2565         }
2566
2567         String[] DoEnumTimeFormats()
2568         {
2569             // Note that this gets overrides for us all the time
2570             Contract.Assert(this.sWindowsName != null, "[CultureData.DoEnumTimeFormats] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
2571             String[] result = ReescapeWin32Strings(nativeEnumTimeFormats(this.sWindowsName, 0, UseUserOverride));
2572
2573             return result;
2574         }
2575
2576         String[] DoEnumShortTimeFormats()
2577         {
2578             // Note that this gets overrides for us all the time
2579             Contract.Assert(this.sWindowsName != null, "[CultureData.DoEnumShortTimeFormats] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
2580             String[] result = ReescapeWin32Strings(nativeEnumTimeFormats(this.sWindowsName, TIME_NOSECONDS, UseUserOverride));
2581
2582             return result;
2583         }
2584
2585         /////////////////
2586         // Static Helpers //
2587         ////////////////
2588         internal static bool IsCustomCultureId(int cultureId)
2589         {
2590             if (cultureId == CultureInfo.LOCALE_CUSTOM_DEFAULT || cultureId == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED)
2591                 return true;
2592
2593             return false;
2594         }
2595
2596         ////////////////////////////////////////////////////////////////////////////
2597         //
2598         // Parameters:
2599         //      calendarValueOnly   Retrieve the values which are affected by the calendar change of DTFI.
2600         //                          This will cause values like longTimePattern not be retrieved since it is
2601         //                          not affected by the Calendar property in DTFI.
2602         //
2603         ////////////////////////////////////////////////////////////////////////////
2604         internal void GetNFIValues(NumberFormatInfo nfi)
2605         {
2606             if (this.IsInvariantCulture)
2607             {
2608                 nfi.positiveSign = this.sPositiveSign;
2609                 nfi.negativeSign = this.sNegativeSign;
2610
2611                 nfi.nativeDigits = this.saNativeDigits;
2612                 nfi.digitSubstitution = this.iDigitSubstitution;
2613
2614                 nfi.numberGroupSeparator = this.sThousandSeparator;
2615                 nfi.numberDecimalSeparator = this.sDecimalSeparator;
2616                 nfi.numberDecimalDigits = this.iDigits;
2617                 nfi.numberNegativePattern = this.iNegativeNumber;
2618
2619                 nfi.currencySymbol = this.sCurrency;
2620                 nfi.currencyGroupSeparator = this.sMonetaryThousand;
2621                 nfi.currencyDecimalSeparator = this.sMonetaryDecimal;
2622                 nfi.currencyDecimalDigits = this.iCurrencyDigits;
2623                 nfi.currencyNegativePattern = this.iNegativeCurrency;
2624                 nfi.currencyPositivePattern = this.iCurrency;
2625             }
2626             else
2627             {
2628                 //
2629                 // We don't have information for the following four.  All cultures use
2630                 // the same value of the number formatting values.
2631                 //
2632                 // PercentDecimalDigits
2633                 // PercentDecimalSeparator
2634                 // PercentGroupSize
2635                 // PercentGroupSeparator
2636                 //
2637
2638                 //
2639                 // Ask native side for our data.
2640                 //
2641                 Contract.Assert(this.sWindowsName != null, "[CultureData.GetNFIValues] Expected this.sWindowsName to be populated by COMNlsInfo::nativeInitCultureData already");
2642                 CultureData.nativeGetNumberFormatInfoValues(this.sWindowsName, nfi, UseUserOverride);
2643             }
2644
2645
2646             //
2647             // Gather additional data
2648             //
2649             nfi.numberGroupSizes = this.WAGROUPING;
2650             nfi.currencyGroupSizes = this.WAMONGROUPING;
2651
2652             // prefer the cached value since these do not have user overrides
2653             nfi.percentNegativePattern = this.INEGATIVEPERCENT;
2654             nfi.percentPositivePattern = this.IPOSITIVEPERCENT;
2655             nfi.percentSymbol = this.SPERCENT;
2656             nfi.perMilleSymbol = this.SPERMILLE;
2657
2658             nfi.negativeInfinitySymbol = this.SNEGINFINITY;
2659             nfi.positiveInfinitySymbol = this.SPOSINFINITY;
2660             nfi.nanSymbol = this.SNAN;
2661
2662             //
2663             // We don't have percent values, so use the number values
2664             //
2665             nfi.percentDecimalDigits = nfi.numberDecimalDigits;
2666             nfi.percentDecimalSeparator = nfi.numberDecimalSeparator;
2667             nfi.percentGroupSizes = nfi.numberGroupSizes;
2668             nfi.percentGroupSeparator = nfi.numberGroupSeparator;
2669
2670             //
2671             // Clean up a few odd values
2672             //
2673
2674             // Windows usually returns an empty positive sign, but we like it to be "+"
2675             if (nfi.positiveSign == null || nfi.positiveSign.Length == 0) nfi.positiveSign = "+";
2676
2677             //Special case for Italian.  The currency decimal separator in the control panel is the empty string. When the user
2678             //specifies C4 as the currency format, this results in the number apparently getting multiplied by 10000 because the
2679             //decimal point doesn't show up.  We'll just workaround this here because our default currency format will never use nfi.
2680             if (nfi.currencyDecimalSeparator == null || nfi.currencyDecimalSeparator.Length == 0)
2681             {
2682                 nfi.currencyDecimalSeparator = nfi.numberDecimalSeparator;
2683             }
2684         }
2685
2686         static private int ConvertFirstDayOfWeekMonToSun(int iTemp)
2687         {
2688             // Convert Mon-Sun to Sun-Sat format
2689             iTemp++;
2690             if (iTemp > 6)
2691             {
2692                 // Wrap Sunday and convert invalid data to Sunday
2693                 iTemp = 0;
2694             }
2695             return iTemp;
2696         }
2697
2698         // Helper
2699         // This is ONLY used for caching names and shouldn't be used for anything else
2700         internal static string AnsiToLower(string testString)
2701         {
2702             StringBuilder sb = new StringBuilder(testString.Length);
2703
2704             for (int ich = 0; ich < testString.Length; ich++)
2705             {
2706                 char ch = testString[ich];
2707                 sb.Append(ch <= 'Z' && ch >= 'A' ? (char)(ch - 'A' + 'a') : ch);
2708             }
2709
2710             return (sb.ToString());
2711         }
2712
2713         // If we get a group from windows, then its in 3;0 format with the 0 backwards
2714         // of how NLS+ uses it (ie: if the string has a 0, then the int[] shouldn't and vice versa)
2715         // EXCEPT in the case where the list only contains 0 in which NLS and NLS+ have the same meaning.
2716         static private int[] ConvertWin32GroupString(String win32Str)
2717         {
2718             // None of these cases make any sense
2719             if (win32Str == null || win32Str.Length == 0)
2720             {
2721                 return (new int[] { 3 });
2722             }
2723
2724             if (win32Str[0] == '0')
2725             {
2726                 return (new int[] { 0 });
2727             }
2728
2729             // Since its in n;n;n;n;n format, we can always get the length quickly
2730             int[] values;
2731             if (win32Str[win32Str.Length - 1] == '0')
2732             {
2733                 // Trailing 0 gets dropped. 1;0 -> 1
2734                 values = new int[(win32Str.Length / 2)];
2735             }
2736             else
2737             {
2738                 // Need extra space for trailing zero 1 -> 1;0
2739                 values = new int[(win32Str.Length / 2) + 2];
2740                 values[values.Length - 1] = 0;
2741             }
2742
2743             int i;
2744             int j;
2745             for (i = 0, j = 0; i < win32Str.Length && j < values.Length; i += 2, j++)
2746             {
2747                 // Note that this # shouldn't ever be zero, 'cause 0 is only at end
2748                 // But we'll test because its registry that could be anything
2749                 if (win32Str[i] < '1' || win32Str[i] > '9')
2750                     return new int[] { 3 };
2751
2752                 values[j] = (int)(win32Str[i] - '0');
2753             }
2754
2755             return (values);
2756         }
2757
2758         // LCTYPES for GetLocaleInfo
2759         private const uint LOCALE_NOUSEROVERRIDE = 0x80000000;   // do not use user overrides
2760         private const uint LOCALE_RETURN_NUMBER = 0x20000000;   // return number instead of string
2761
2762         // Modifier for genitive names
2763         private const uint LOCALE_RETURN_GENITIVE_NAMES = 0x10000000;   //Flag to return the Genitive forms of month names
2764
2765         //
2766         //  The following LCTypes are mutually exclusive in that they may NOT
2767         //  be used in combination with each other.
2768         //
2769
2770         //
2771         // These are the various forms of the name of the locale:
2772         //
2773         private const uint LOCALE_SLOCALIZEDDISPLAYNAME = 0x00000002;   // localized name of locale, eg "German (Germany)" in UI language
2774         private const uint LOCALE_SENGLISHDISPLAYNAME = 0x00000072;   // Display name (language + country usually) in English, eg "German (Germany)"
2775         private const uint LOCALE_SNATIVEDISPLAYNAME = 0x00000073;   // Display name in native locale language, eg "Deutsch (Deutschland)
2776
2777         private const uint LOCALE_SLOCALIZEDLANGUAGENAME = 0x0000006f;   // Language Display Name for a language, eg "German" in UI language
2778         private const uint LOCALE_SENGLISHLANGUAGENAME = 0x00001001;   // English name of language, eg "German"
2779         private const uint LOCALE_SNATIVELANGUAGENAME = 0x00000004;   // native name of language, eg "Deutsch"
2780
2781         private const uint LOCALE_SLOCALIZEDCOUNTRYNAME = 0x00000006;   // localized name of country, eg "Germany" in UI language
2782         private const uint LOCALE_SENGLISHCOUNTRYNAME = 0x00001002;   // English name of country, eg "Germany"
2783         private const uint LOCALE_SNATIVECOUNTRYNAME = 0x00000008;   // native name of country, eg "Deutschland"
2784
2785
2786         //        private const uint LOCALE_ILANGUAGE              =0x00000001;   // language id // Don't use, use NewApis::LocaleNameToLCID instead (GetLocaleInfo doesn't return neutrals)
2787
2788         //        private const uint LOCALE_SLANGUAGE              =LOCALE_SLOCALIZEDDISPLAYNAME;   // localized name of language (use LOCALE_SLOCALIZEDDISPLAYNAME instead)
2789         //        private const uint LOCALE_SENGLANGUAGE           =LOCALE_SENGLISHLANGUAGENAME;   // English name of language (use LOCALE_SENGLISHLANGUAGENAME instead)
2790         private const uint LOCALE_SABBREVLANGNAME = 0x00000003;   // abbreviated language name
2791         //        private const uint LOCALE_SNATIVELANGNAME        =LOCALE_SNATIVELANGUAGENAME;   // native name of language (use LOCALE_SNATIVELANGUAGENAME instead)
2792
2793         private const uint LOCALE_ICOUNTRY = 0x00000005;   // country code
2794         //        private const uint LOCALE_SCOUNTRY               =LOCALE_SLOCALIZEDCOUNTRYNAME;   // localized name of country (use LOCALE_SLOCALIZEDCOUNTRYNAME instead)
2795         //        private const uint LOCALE_SENGCOUNTRY            =LOCALE_SENGLISHCOUNTRYNAME;   // English name of country (use LOCALE_SENGLISHCOUNTRYNAME instead)
2796         private const uint LOCALE_SABBREVCTRYNAME = 0x00000007;   // abbreviated country name
2797         //        private const uint LOCALE_SNATIVECTRYNAME        =LOCALE_SNATIVECOUNTRYNAME;   // native name of country ( use LOCALE_SNATIVECOUNTRYNAME instead)
2798         private const uint LOCALE_IGEOID = 0x0000005B;   // geographical location id
2799
2800         private const uint LOCALE_IDEFAULTLANGUAGE = 0x00000009;   // default language id
2801         private const uint LOCALE_IDEFAULTCOUNTRY = 0x0000000A;   // default country code
2802         private const uint LOCALE_IDEFAULTCODEPAGE = 0x0000000B;   // default oem code page
2803         private const uint LOCALE_IDEFAULTANSICODEPAGE = 0x00001004;   // default ansi code page
2804         private const uint LOCALE_IDEFAULTMACCODEPAGE = 0x00001011;   // default mac code page
2805
2806         private const uint LOCALE_SLIST = 0x0000000C;   // list item separator
2807         private const uint LOCALE_IMEASURE = 0x0000000D;   // 0 = metric, 1 = US
2808
2809         private const uint LOCALE_SDECIMAL = 0x0000000E;   // decimal separator
2810         private const uint LOCALE_STHOUSAND = 0x0000000F;   // thousand separator
2811         private const uint LOCALE_SGROUPING = 0x00000010;   // digit grouping
2812         private const uint LOCALE_IDIGITS = 0x00000011;   // number of fractional digits
2813         private const uint LOCALE_ILZERO = 0x00000012;   // leading zeros for decimal
2814         private const uint LOCALE_INEGNUMBER = 0x00001010;   // negative number mode
2815         private const uint LOCALE_SNATIVEDIGITS = 0x00000013;   // native digits for 0-9
2816
2817         private const uint LOCALE_SCURRENCY = 0x00000014;   // local monetary symbol
2818         private const uint LOCALE_SINTLSYMBOL = 0x00000015;   // uintl monetary symbol
2819         private const uint LOCALE_SMONDECIMALSEP = 0x00000016;   // monetary decimal separator
2820         private const uint LOCALE_SMONTHOUSANDSEP = 0x00000017;   // monetary thousand separator
2821         private const uint LOCALE_SMONGROUPING = 0x00000018;   // monetary grouping
2822         private const uint LOCALE_ICURRDIGITS = 0x00000019;   // # local monetary digits
2823         private const uint LOCALE_IINTLCURRDIGITS = 0x0000001A;   // # uintl monetary digits
2824         private const uint LOCALE_ICURRENCY = 0x0000001B;   // positive currency mode
2825         private const uint LOCALE_INEGCURR = 0x0000001C;   // negative currency mode
2826
2827         private const uint LOCALE_SDATE = 0x0000001D;   // date separator (derived from LOCALE_SSHORTDATE, use that instead)
2828         private const uint LOCALE_STIME = 0x0000001E;   // time separator (derived from LOCALE_STIMEFORMAT, use that instead)
2829         private const uint LOCALE_SSHORTDATE = 0x0000001F;   // short date format string
2830         private const uint LOCALE_SLONGDATE = 0x00000020;   // long date format string
2831         private const uint LOCALE_STIMEFORMAT = 0x00001003;   // time format string
2832         private const uint LOCALE_IDATE = 0x00000021;   // short date format ordering (derived from LOCALE_SSHORTDATE, use that instead)
2833         private const uint LOCALE_ILDATE = 0x00000022;   // long date format ordering (derived from LOCALE_SLONGDATE, use that instead)
2834         private const uint LOCALE_ITIME = 0x00000023;   // time format specifier (derived from LOCALE_STIMEFORMAT, use that instead)
2835         private const uint LOCALE_ITIMEMARKPOSN = 0x00001005;   // time marker position (derived from LOCALE_STIMEFORMAT, use that instead)
2836         private const uint LOCALE_ICENTURY = 0x00000024;   // century format specifier (short date, LOCALE_SSHORTDATE is preferred)
2837         private const uint LOCALE_ITLZERO = 0x00000025;   // leading zeros in time field (derived from LOCALE_STIMEFORMAT, use that instead)
2838         private const uint LOCALE_IDAYLZERO = 0x00000026;   // leading zeros in day field (short date, LOCALE_SSHORTDATE is preferred)
2839         private const uint LOCALE_IMONLZERO = 0x00000027;   // leading zeros in month field (short date, LOCALE_SSHORTDATE is preferred)
2840         private const uint LOCALE_S1159 = 0x00000028;   // AM designator
2841         private const uint LOCALE_S2359 = 0x00000029;   // PM designator
2842
2843         private const uint LOCALE_ICALENDARTYPE = 0x00001009;   // type of calendar specifier
2844         private const uint LOCALE_IOPTIONALCALENDAR = 0x0000100B;   // additional calendar types specifier
2845         private const uint LOCALE_IFIRSTDAYOFWEEK = 0x0000100C;   // first day of week specifier
2846         private const uint LOCALE_IFIRSTWEEKOFYEAR = 0x0000100D;   // first week of year specifier
2847
2848         private const uint LOCALE_SDAYNAME1 = 0x0000002A;   // long name for Monday
2849         private const uint LOCALE_SDAYNAME2 = 0x0000002B;   // long name for Tuesday
2850         private const uint LOCALE_SDAYNAME3 = 0x0000002C;   // long name for Wednesday
2851         private const uint LOCALE_SDAYNAME4 = 0x0000002D;   // long name for Thursday
2852         private const uint LOCALE_SDAYNAME5 = 0x0000002E;   // long name for Friday
2853         private const uint LOCALE_SDAYNAME6 = 0x0000002F;   // long name for Saturday
2854         private const uint LOCALE_SDAYNAME7 = 0x00000030;   // long name for Sunday
2855         private const uint LOCALE_SABBREVDAYNAME1 = 0x00000031;   // abbreviated name for Monday
2856         private const uint LOCALE_SABBREVDAYNAME2 = 0x00000032;   // abbreviated name for Tuesday
2857         private const uint LOCALE_SABBREVDAYNAME3 = 0x00000033;   // abbreviated name for Wednesday
2858         private const uint LOCALE_SABBREVDAYNAME4 = 0x00000034;   // abbreviated name for Thursday
2859         private const uint LOCALE_SABBREVDAYNAME5 = 0x00000035;   // abbreviated name for Friday
2860         private const uint LOCALE_SABBREVDAYNAME6 = 0x00000036;   // abbreviated name for Saturday
2861         private const uint LOCALE_SABBREVDAYNAME7 = 0x00000037;   // abbreviated name for Sunday
2862         private const uint LOCALE_SMONTHNAME1 = 0x00000038;   // long name for January
2863         private const uint LOCALE_SMONTHNAME2 = 0x00000039;   // long name for February
2864         private const uint LOCALE_SMONTHNAME3 = 0x0000003A;   // long name for March
2865         private const uint LOCALE_SMONTHNAME4 = 0x0000003B;   // long name for April
2866         private const uint LOCALE_SMONTHNAME5 = 0x0000003C;   // long name for May
2867         private const uint LOCALE_SMONTHNAME6 = 0x0000003D;   // long name for June
2868         private const uint LOCALE_SMONTHNAME7 = 0x0000003E;   // long name for July
2869         private const uint LOCALE_SMONTHNAME8 = 0x0000003F;   // long name for August
2870         private const uint LOCALE_SMONTHNAME9 = 0x00000040;   // long name for September
2871         private const uint LOCALE_SMONTHNAME10 = 0x00000041;   // long name for October
2872         private const uint LOCALE_SMONTHNAME11 = 0x00000042;   // long name for November
2873         private const uint LOCALE_SMONTHNAME12 = 0x00000043;   // long name for December
2874         private const uint LOCALE_SMONTHNAME13 = 0x0000100E;   // long name for 13th month (if exists)
2875         private const uint LOCALE_SABBREVMONTHNAME1 = 0x00000044;   // abbreviated name for January
2876         private const uint LOCALE_SABBREVMONTHNAME2 = 0x00000045;   // abbreviated name for February
2877         private const uint LOCALE_SABBREVMONTHNAME3 = 0x00000046;   // abbreviated name for March
2878         private const uint LOCALE_SABBREVMONTHNAME4 = 0x00000047;   // abbreviated name for April
2879         private const uint LOCALE_SABBREVMONTHNAME5 = 0x00000048;   // abbreviated name for May
2880         private const uint LOCALE_SABBREVMONTHNAME6 = 0x00000049;   // abbreviated name for June
2881         private const uint LOCALE_SABBREVMONTHNAME7 = 0x0000004A;   // abbreviated name for July
2882         private const uint LOCALE_SABBREVMONTHNAME8 = 0x0000004B;   // abbreviated name for August
2883         private const uint LOCALE_SABBREVMONTHNAME9 = 0x0000004C;   // abbreviated name for September
2884         private const uint LOCALE_SABBREVMONTHNAME10 = 0x0000004D;   // abbreviated name for October
2885         private const uint LOCALE_SABBREVMONTHNAME11 = 0x0000004E;   // abbreviated name for November
2886         private const uint LOCALE_SABBREVMONTHNAME12 = 0x0000004F;   // abbreviated name for December
2887         private const uint LOCALE_SABBREVMONTHNAME13 = 0x0000100F;   // abbreviated name for 13th month (if exists)
2888
2889         private const uint LOCALE_SPOSITIVESIGN = 0x00000050;   // positive sign
2890         private const uint LOCALE_SNEGATIVESIGN = 0x00000051;   // negative sign
2891         private const uint LOCALE_IPOSSIGNPOSN = 0x00000052;   // positive sign position (derived from INEGCURR)
2892         private const uint LOCALE_INEGSIGNPOSN = 0x00000053;   // negative sign position (derived from INEGCURR)
2893         private const uint LOCALE_IPOSSYMPRECEDES = 0x00000054;   // mon sym precedes pos amt (derived from ICURRENCY)
2894         private const uint LOCALE_IPOSSEPBYSPACE = 0x00000055;   // mon sym sep by space from pos amt (derived from ICURRENCY)
2895         private const uint LOCALE_INEGSYMPRECEDES = 0x00000056;   // mon sym precedes neg amt (derived from INEGCURR)
2896         private const uint LOCALE_INEGSEPBYSPACE = 0x00000057;   // mon sym sep by space from neg amt (derived from INEGCURR)
2897
2898         private const uint LOCALE_FONTSIGNATURE = 0x00000058;   // font signature
2899         private const uint LOCALE_SISO639LANGNAME = 0x00000059;   // ISO abbreviated language name
2900         private const uint LOCALE_SISO3166CTRYNAME = 0x0000005A;   // ISO abbreviated country name
2901
2902         private const uint LOCALE_IDEFAULTEBCDICCODEPAGE = 0x00001012;   // default ebcdic code page
2903         private const uint LOCALE_IPAPERSIZE = 0x0000100A;   // 1 = letter, 5 = legal, 8 = a3, 9 = a4
2904         private const uint LOCALE_SENGCURRNAME = 0x00001007;   // english name of currency
2905         private const uint LOCALE_SNATIVECURRNAME = 0x00001008;   // native name of currency
2906         private const uint LOCALE_SYEARMONTH = 0x00001006;   // year month format string
2907         private const uint LOCALE_SSORTNAME = 0x00001013;   // sort name
2908         private const uint LOCALE_IDIGITSUBSTITUTION = 0x00001014;   // 0 = context, 1 = none, 2 = national
2909
2910         private const uint LOCALE_SNAME = 0x0000005c;   // locale name (with sort info) (ie: de-DE_phoneb)
2911         private const uint LOCALE_SDURATION = 0x0000005d;   // time duration format
2912         private const uint LOCALE_SKEYBOARDSTOINSTALL = 0x0000005e;   // (windows only) keyboards to install
2913         private const uint LOCALE_SSHORTESTDAYNAME1 = 0x00000060;   // Shortest day name for Monday
2914         private const uint LOCALE_SSHORTESTDAYNAME2 = 0x00000061;   // Shortest day name for Tuesday
2915         private const uint LOCALE_SSHORTESTDAYNAME3 = 0x00000062;   // Shortest day name for Wednesday
2916         private const uint LOCALE_SSHORTESTDAYNAME4 = 0x00000063;   // Shortest day name for Thursday
2917         private const uint LOCALE_SSHORTESTDAYNAME5 = 0x00000064;   // Shortest day name for Friday
2918         private const uint LOCALE_SSHORTESTDAYNAME6 = 0x00000065;   // Shortest day name for Saturday
2919         private const uint LOCALE_SSHORTESTDAYNAME7 = 0x00000066;   // Shortest day name for Sunday
2920         private const uint LOCALE_SISO639LANGNAME2 = 0x00000067;   // 3 character ISO abbreviated language name
2921         private const uint LOCALE_SISO3166CTRYNAME2 = 0x00000068;   // 3 character ISO country name
2922         private const uint LOCALE_SNAN = 0x00000069;   // Not a Number
2923         private const uint LOCALE_SPOSINFINITY = 0x0000006a;   // + Infinity
2924         private const uint LOCALE_SNEGINFINITY = 0x0000006b;   // - Infinity
2925         private const uint LOCALE_SSCRIPTS = 0x0000006c;   // Typical scripts in the locale
2926         private const uint LOCALE_SPARENT = 0x0000006d;   // Fallback name for resources
2927         private const uint LOCALE_SCONSOLEFALLBACKNAME = 0x0000006e;   // Fallback name for within the console
2928         //        private const uint LOCALE_SLANGDISPLAYNAME       =LOCALE_SLOCALIZEDLANGUAGENAME;   // Language Display Name for a language (use LOCALE_SLOCALIZEDLANGUAGENAME instead)
2929
2930         // Windows 7 LCTYPES
2931         private const uint LOCALE_IREADINGLAYOUT = 0x00000070;   // Returns one of the following 4 reading layout values:
2932         // 0 - Left to right (eg en-US)
2933         // 1 - Right to left (eg arabic locales)
2934         // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
2935         // 3 - Vertical top to bottom with columns proceeding to the right
2936         private const uint LOCALE_INEUTRAL = 0x00000071;   // Returns 0 for specific cultures, 1 for neutral cultures.
2937         private const uint LOCALE_INEGATIVEPERCENT = 0x00000074;   // Returns 0-11 for the negative percent format
2938         private const uint LOCALE_IPOSITIVEPERCENT = 0x00000075;   // Returns 0-3 for the positive percent formatIPOSITIVEPERCENT
2939         private const uint LOCALE_SPERCENT = 0x00000076;   // Returns the percent symbol
2940         private const uint LOCALE_SPERMILLE = 0x00000077;   // Returns the permille (U+2030) symbol
2941         private const uint LOCALE_SMONTHDAY = 0x00000078;   // Returns the preferred month/day format
2942         private const uint LOCALE_SSHORTTIME = 0x00000079;   // Returns the preferred short time format (ie: no seconds, just h:mm)
2943         private const uint LOCALE_SOPENTYPELANGUAGETAG = 0x0000007a;   // Open type language tag, eg: "latn" or "dflt"
2944         private const uint LOCALE_SSORTLOCALE = 0x0000007b;   // Name of locale to use for sorting/collation/casing behavior.
2945
2946         // Time formats enumerations
2947         internal const uint TIME_NOSECONDS = 0x00000002;   // Don't use seconds (get short time format for enumtimeformats on win7+)
2948
2949         // Get our initial minimal culture data (name, parent, etc.)
2950         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2951         internal static extern bool nativeInitCultureData(CultureData cultureData);
2952
2953         // Grab the NumberFormatInfo data
2954         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2955         internal static extern bool nativeGetNumberFormatInfoValues(String localeName, NumberFormatInfo nfi, bool useUserOverride);
2956
2957         [MethodImplAttribute(MethodImplOptions.InternalCall)]
2958         private static extern String[] nativeEnumTimeFormats(String localeName, uint dwFlags, bool useUserOverride);
2959
2960         [SuppressUnmanagedCodeSecurityAttribute()]
2961         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
2962         internal static extern int nativeEnumCultureNames(int cultureTypes, ObjectHandleOnStack retStringArray);
2963     }
2964 }