CultureData.cs 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563
  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. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Text;
  7. using System.Threading;
  8. namespace System.Globalization
  9. {
  10. #if CORERT
  11. #pragma warning restore nullable
  12. using StringStringDictionary = LowLevelDictionary<string, string>;
  13. using StringCultureDataDictionary = LowLevelDictionary<string, CultureData>;
  14. using LcidToCultureNameDictionary = LowLevelDictionary<int, string>;
  15. #else
  16. using StringStringDictionary = Dictionary<string, string>;
  17. using StringCultureDataDictionary = Dictionary<string, CultureData>;
  18. using LcidToCultureNameDictionary = Dictionary<int, string>;
  19. #endif
  20. /// <summary>
  21. /// List of culture data
  22. /// Note the we cache overrides.
  23. /// Note that localized names (resource names) aren't available from here.
  24. /// </summary>
  25. /// <remarks>
  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. /// </remarks>
  50. internal partial class CultureData
  51. {
  52. private const int LocaleNameMaxLength = 85;
  53. private const int undef = -1;
  54. // Override flag
  55. private string _sRealName = null!; // Name you passed in (ie: en-US, en, or de-DE_phoneb). Initialized by helper called during initialization.
  56. private string? _sWindowsName; // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
  57. // Identity
  58. private string? _sName; // locale name (ie: en-us, NO sort info, but could be neutral)
  59. private string? _sParent; // Parent name (which may be a custom locale/culture)
  60. private string? _sLocalizedDisplayName; // Localized pretty name for this locale
  61. private string? _sEnglishDisplayName; // English pretty name for this locale
  62. private string? _sNativeDisplayName; // Native pretty name for this locale
  63. private string? _sSpecificCulture; // The culture name to be used in CultureInfo.CreateSpecificCulture(), en-US form if neutral, sort name if sort
  64. // Language
  65. private string? _sISO639Language; // ISO 639 Language Name
  66. private string? _sISO639Language2; // ISO 639 Language Name
  67. private string? _sLocalizedLanguage; // Localized name for this language
  68. private string? _sEnglishLanguage; // English name for this language
  69. private string? _sNativeLanguage; // Native name of this language
  70. private string? _sAbbrevLang; // abbreviated language name (Windows Language Name) ex: ENU
  71. private string? _sConsoleFallbackName; // The culture name for the console fallback UI culture
  72. private int _iInputLanguageHandle=undef;// input language handle
  73. // Region
  74. private string? _sRegionName; // (RegionInfo)
  75. private string? _sLocalizedCountry; // localized country name
  76. private string? _sEnglishCountry; // english country name (RegionInfo)
  77. private string? _sNativeCountry; // native country name
  78. private string? _sISO3166CountryName; // ISO 3166 (RegionInfo), ie: US
  79. private string? _sISO3166CountryName2; // 3 char ISO 3166 country name 2 2(RegionInfo) ex: USA (ISO)
  80. private int _iGeoId = undef; // GeoId
  81. // Numbers
  82. private string? _sPositiveSign; // (user can override) positive sign
  83. private string? _sNegativeSign; // (user can override) negative sign
  84. // (nfi populates these 5, don't have to be = undef)
  85. private int _iDigits; // (user can override) number of fractional digits
  86. private int _iNegativeNumber; // (user can override) negative number format
  87. private int[]? _waGrouping; // (user can override) grouping of digits
  88. private string? _sDecimalSeparator; // (user can override) decimal separator
  89. private string? _sThousandSeparator; // (user can override) thousands separator
  90. private string? _sNaN; // Not a Number
  91. private string? _sPositiveInfinity; // + Infinity
  92. private string? _sNegativeInfinity; // - Infinity
  93. // Percent
  94. private int _iNegativePercent = undef; // Negative Percent (0-3)
  95. private int _iPositivePercent = undef; // Positive Percent (0-11)
  96. private string? _sPercent; // Percent (%) symbol
  97. private string? _sPerMille; // PerMille symbol
  98. // Currency
  99. private string? _sCurrency; // (user can override) local monetary symbol
  100. private string? _sIntlMonetarySymbol; // international monetary symbol (RegionInfo)
  101. private string? _sEnglishCurrency; // English name for this currency
  102. private string? _sNativeCurrency; // Native name for this currency
  103. // (nfi populates these 4, don't have to be = undef)
  104. private int _iCurrencyDigits; // (user can override) # local monetary fractional digits
  105. private int _iCurrency; // (user can override) positive currency format
  106. private int _iNegativeCurrency; // (user can override) negative currency format
  107. private int[]? _waMonetaryGrouping; // (user can override) monetary grouping of digits
  108. private string? _sMonetaryDecimal; // (user can override) monetary decimal separator
  109. private string? _sMonetaryThousand; // (user can override) monetary thousands separator
  110. // Misc
  111. private int _iMeasure = undef; // (user can override) system of measurement 0=metric, 1=US (RegionInfo)
  112. private string? _sListSeparator; // (user can override) list separator
  113. // Time
  114. private string? _sAM1159; // (user can override) AM designator
  115. private string? _sPM2359; // (user can override) PM designator
  116. private string? _sTimeSeparator;
  117. private volatile string[]? _saLongTimes; // (user can override) time format
  118. private volatile string[]? _saShortTimes; // short time format
  119. private volatile string[]? _saDurationFormats; // time duration format
  120. // Calendar specific data
  121. private int _iFirstDayOfWeek = undef; // (user can override) first day of week (gregorian really)
  122. private int _iFirstWeekOfYear = undef; // (user can override) first week of year (gregorian really)
  123. private volatile CalendarId[]? _waCalendars; // all available calendar type(s). The first one is the default calendar
  124. // Store for specific data about each calendar
  125. private CalendarData?[]? _calendars; // Store for specific calendar data
  126. // Text information
  127. private int _iReadingLayout = undef; // Reading layout data
  128. // 0 - Left to right (eg en-US)
  129. // 1 - Right to left (eg arabic locales)
  130. // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  131. // 3 - Vertical top to bottom with columns proceeding to the right
  132. // CoreCLR depends on this even though its not exposed publicly.
  133. private int _iDefaultAnsiCodePage = undef; // default ansi code page ID (ACP)
  134. private int _iDefaultOemCodePage = undef; // default oem code page ID (OCP or OEM)
  135. private int _iDefaultMacCodePage = undef; // default macintosh code page
  136. private int _iDefaultEbcdicCodePage = undef; // default EBCDIC code page
  137. private int _iLanguage; // locale ID (0409) - NO sort information
  138. private bool _bUseOverrides; // use user overrides?
  139. private bool _bNeutral; // Flags for the culture (ie: neutral or not right now)
  140. /// <summary>
  141. /// Region Name to Culture Name mapping table
  142. /// </summary>
  143. /// <remarks>
  144. /// Using a property so we avoid creating the dictionary until we need it
  145. /// </remarks>
  146. private static StringStringDictionary RegionNames
  147. {
  148. get
  149. {
  150. if (s_regionNames == null)
  151. {
  152. StringStringDictionary regionNames = new StringStringDictionary(211 /* prime */);
  153. regionNames.Add("029", "en-029");
  154. regionNames.Add("AE", "ar-AE");
  155. regionNames.Add("AF", "prs-AF");
  156. regionNames.Add("AL", "sq-AL");
  157. regionNames.Add("AM", "hy-AM");
  158. regionNames.Add("AR", "es-AR");
  159. regionNames.Add("AT", "de-AT");
  160. regionNames.Add("AU", "en-AU");
  161. regionNames.Add("AZ", "az-Cyrl-AZ");
  162. regionNames.Add("BA", "bs-Latn-BA");
  163. regionNames.Add("BD", "bn-BD");
  164. regionNames.Add("BE", "nl-BE");
  165. regionNames.Add("BG", "bg-BG");
  166. regionNames.Add("BH", "ar-BH");
  167. regionNames.Add("BN", "ms-BN");
  168. regionNames.Add("BO", "es-BO");
  169. regionNames.Add("BR", "pt-BR");
  170. regionNames.Add("BY", "be-BY");
  171. regionNames.Add("BZ", "en-BZ");
  172. regionNames.Add("CA", "en-CA");
  173. regionNames.Add("CH", "it-CH");
  174. regionNames.Add("CL", "es-CL");
  175. regionNames.Add("CN", "zh-CN");
  176. regionNames.Add("CO", "es-CO");
  177. regionNames.Add("CR", "es-CR");
  178. regionNames.Add("CS", "sr-Cyrl-CS");
  179. regionNames.Add("CZ", "cs-CZ");
  180. regionNames.Add("DE", "de-DE");
  181. regionNames.Add("DK", "da-DK");
  182. regionNames.Add("DO", "es-DO");
  183. regionNames.Add("DZ", "ar-DZ");
  184. regionNames.Add("EC", "es-EC");
  185. regionNames.Add("EE", "et-EE");
  186. regionNames.Add("EG", "ar-EG");
  187. regionNames.Add("ES", "es-ES");
  188. regionNames.Add("ET", "am-ET");
  189. regionNames.Add("FI", "fi-FI");
  190. regionNames.Add("FO", "fo-FO");
  191. regionNames.Add("FR", "fr-FR");
  192. regionNames.Add("GB", "en-GB");
  193. regionNames.Add("GE", "ka-GE");
  194. regionNames.Add("GL", "kl-GL");
  195. regionNames.Add("GR", "el-GR");
  196. regionNames.Add("GT", "es-GT");
  197. regionNames.Add("HK", "zh-HK");
  198. regionNames.Add("HN", "es-HN");
  199. regionNames.Add("HR", "hr-HR");
  200. regionNames.Add("HU", "hu-HU");
  201. regionNames.Add("ID", "id-ID");
  202. regionNames.Add("IE", "en-IE");
  203. regionNames.Add("IL", "he-IL");
  204. regionNames.Add("IN", "hi-IN");
  205. regionNames.Add("IQ", "ar-IQ");
  206. regionNames.Add("IR", "fa-IR");
  207. regionNames.Add("IS", "is-IS");
  208. regionNames.Add("IT", "it-IT");
  209. regionNames.Add("IV", "");
  210. regionNames.Add("JM", "en-JM");
  211. regionNames.Add("JO", "ar-JO");
  212. regionNames.Add("JP", "ja-JP");
  213. regionNames.Add("KE", "sw-KE");
  214. regionNames.Add("KG", "ky-KG");
  215. regionNames.Add("KH", "km-KH");
  216. regionNames.Add("KR", "ko-KR");
  217. regionNames.Add("KW", "ar-KW");
  218. regionNames.Add("KZ", "kk-KZ");
  219. regionNames.Add("LA", "lo-LA");
  220. regionNames.Add("LB", "ar-LB");
  221. regionNames.Add("LI", "de-LI");
  222. regionNames.Add("LK", "si-LK");
  223. regionNames.Add("LT", "lt-LT");
  224. regionNames.Add("LU", "lb-LU");
  225. regionNames.Add("LV", "lv-LV");
  226. regionNames.Add("LY", "ar-LY");
  227. regionNames.Add("MA", "ar-MA");
  228. regionNames.Add("MC", "fr-MC");
  229. regionNames.Add("ME", "sr-Latn-ME");
  230. regionNames.Add("MK", "mk-MK");
  231. regionNames.Add("MN", "mn-MN");
  232. regionNames.Add("MO", "zh-MO");
  233. regionNames.Add("MT", "mt-MT");
  234. regionNames.Add("MV", "dv-MV");
  235. regionNames.Add("MX", "es-MX");
  236. regionNames.Add("MY", "ms-MY");
  237. regionNames.Add("NG", "ig-NG");
  238. regionNames.Add("NI", "es-NI");
  239. regionNames.Add("NL", "nl-NL");
  240. regionNames.Add("NO", "nn-NO");
  241. regionNames.Add("NP", "ne-NP");
  242. regionNames.Add("NZ", "en-NZ");
  243. regionNames.Add("OM", "ar-OM");
  244. regionNames.Add("PA", "es-PA");
  245. regionNames.Add("PE", "es-PE");
  246. regionNames.Add("PH", "en-PH");
  247. regionNames.Add("PK", "ur-PK");
  248. regionNames.Add("PL", "pl-PL");
  249. regionNames.Add("PR", "es-PR");
  250. regionNames.Add("PT", "pt-PT");
  251. regionNames.Add("PY", "es-PY");
  252. regionNames.Add("QA", "ar-QA");
  253. regionNames.Add("RO", "ro-RO");
  254. regionNames.Add("RS", "sr-Latn-RS");
  255. regionNames.Add("RU", "ru-RU");
  256. regionNames.Add("RW", "rw-RW");
  257. regionNames.Add("SA", "ar-SA");
  258. regionNames.Add("SE", "sv-SE");
  259. regionNames.Add("SG", "zh-SG");
  260. regionNames.Add("SI", "sl-SI");
  261. regionNames.Add("SK", "sk-SK");
  262. regionNames.Add("SN", "wo-SN");
  263. regionNames.Add("SV", "es-SV");
  264. regionNames.Add("SY", "ar-SY");
  265. regionNames.Add("TH", "th-TH");
  266. regionNames.Add("TJ", "tg-Cyrl-TJ");
  267. regionNames.Add("TM", "tk-TM");
  268. regionNames.Add("TN", "ar-TN");
  269. regionNames.Add("TR", "tr-TR");
  270. regionNames.Add("TT", "en-TT");
  271. regionNames.Add("TW", "zh-TW");
  272. regionNames.Add("UA", "uk-UA");
  273. regionNames.Add("US", "en-US");
  274. regionNames.Add("UY", "es-UY");
  275. regionNames.Add("UZ", "uz-Cyrl-UZ");
  276. regionNames.Add("VE", "es-VE");
  277. regionNames.Add("VN", "vi-VN");
  278. regionNames.Add("YE", "ar-YE");
  279. regionNames.Add("ZA", "af-ZA");
  280. regionNames.Add("ZW", "en-ZW");
  281. s_regionNames = regionNames;
  282. }
  283. return s_regionNames!;
  284. }
  285. }
  286. // Cache of regions we've already looked up
  287. private static volatile StringCultureDataDictionary? s_cachedRegions;
  288. private static volatile StringStringDictionary? s_regionNames;
  289. internal static CultureData? GetCultureDataForRegion(string? cultureName, bool useUserOverride)
  290. {
  291. // First do a shortcut for Invariant
  292. if (string.IsNullOrEmpty(cultureName))
  293. {
  294. return CultureData.Invariant;
  295. }
  296. // First check if GetCultureData() can find it (ie: its a real culture)
  297. CultureData? retVal = GetCultureData(cultureName, useUserOverride);
  298. if (retVal != null && !retVal.IsNeutralCulture)
  299. {
  300. return retVal;
  301. }
  302. // Not a specific culture, perhaps it's region-only name
  303. // (Remember this isn't a core clr path where that's not supported)
  304. // If it was neutral remember that so that RegionInfo() can throw the right exception
  305. CultureData? neutral = retVal;
  306. // Try the hash table next
  307. string hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
  308. StringCultureDataDictionary? tempHashTable = s_cachedRegions;
  309. if (tempHashTable == null)
  310. {
  311. // No table yet, make a new one
  312. tempHashTable = new StringCultureDataDictionary();
  313. }
  314. else
  315. {
  316. // Check the hash table
  317. lock (s_lock)
  318. {
  319. tempHashTable.TryGetValue(hashName, out retVal);
  320. }
  321. if (retVal != null)
  322. {
  323. return retVal;
  324. }
  325. }
  326. // Not found in the hash table, look it up the hard way
  327. // If not a valid mapping from the registry we'll have to try the hard coded table
  328. if (retVal == null || (retVal.IsNeutralCulture == true))
  329. {
  330. // Not a valid mapping, try the hard coded table
  331. string? name;
  332. if (RegionNames.TryGetValue(cultureName, out name))
  333. {
  334. // Make sure we can get culture data for it
  335. retVal = GetCultureData(name, useUserOverride);
  336. }
  337. }
  338. // If not found in the hard coded table we'll have to find a culture that works for us
  339. if (!GlobalizationMode.Invariant && (retVal == null || (retVal.IsNeutralCulture == true)))
  340. {
  341. retVal = GetCultureDataFromRegionName(cultureName);
  342. }
  343. // If we found one we can use, then cache it for next time
  344. if (retVal != null && (retVal.IsNeutralCulture == false))
  345. {
  346. // first add it to the cache
  347. lock (s_lock)
  348. {
  349. tempHashTable[hashName] = retVal;
  350. }
  351. // Copy the hashtable to the corresponding member variables. This will potentially overwrite
  352. // new tables simultaneously created by a new thread, but maximizes thread safety.
  353. s_cachedRegions = tempHashTable;
  354. }
  355. else
  356. {
  357. // Unable to find a matching culture/region, return null or neutral
  358. // (regionInfo throws a more specific exception on neutrals)
  359. retVal = neutral;
  360. }
  361. // Return the found culture to use, null, or the neutral culture.
  362. return retVal;
  363. }
  364. // Clear our internal caches
  365. internal static void ClearCachedData()
  366. {
  367. s_cachedCultures = null;
  368. s_cachedRegions = null;
  369. }
  370. internal static CultureInfo[] GetCultures(CultureTypes types)
  371. {
  372. // Disable warning 618: System.Globalization.CultureTypes.FrameworkCultures' is obsolete
  373. #pragma warning disable 618
  374. // Validate flags
  375. if ((int)types <= 0 || ((int)types & (int)~(CultureTypes.NeutralCultures | CultureTypes.SpecificCultures |
  376. CultureTypes.InstalledWin32Cultures | CultureTypes.UserCustomCulture |
  377. CultureTypes.ReplacementCultures | CultureTypes.WindowsOnlyCultures |
  378. CultureTypes.FrameworkCultures)) != 0)
  379. {
  380. throw new ArgumentOutOfRangeException(nameof(types),
  381. SR.Format(SR.ArgumentOutOfRange_Range, CultureTypes.NeutralCultures, CultureTypes.FrameworkCultures));
  382. }
  383. // We have deprecated CultureTypes.FrameworkCultures.
  384. // When this enum is used, we will enumerate Whidbey framework cultures (for compatibility).
  385. // We have deprecated CultureTypes.WindowsOnlyCultures.
  386. // When this enum is used, we will return an empty array for this enum.
  387. if ((types & CultureTypes.WindowsOnlyCultures) != 0)
  388. {
  389. // Remove the enum as it is an no-op.
  390. types &= (~CultureTypes.WindowsOnlyCultures);
  391. }
  392. if (GlobalizationMode.Invariant)
  393. {
  394. // in invariant mode we always return invariant culture only from the enumeration
  395. return new CultureInfo[] { new CultureInfo("") };
  396. }
  397. #pragma warning restore 618
  398. return EnumCultures(types);
  399. }
  400. private static CultureData CreateCultureWithInvariantData()
  401. {
  402. // Make a new culturedata
  403. CultureData invariant = new CultureData();
  404. // Basics
  405. // Note that we override the resources since this IS NOT supposed to change (by definition)
  406. invariant._bUseOverrides = false;
  407. invariant._sRealName = ""; // Name you passed in (ie: en-US, en, or de-DE_phoneb)
  408. invariant._sWindowsName = ""; // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
  409. // Identity
  410. invariant._sName = ""; // locale name (ie: en-us)
  411. invariant._sParent = ""; // Parent name (which may be a custom locale/culture)
  412. invariant._bNeutral = false; // Flags for the culture (ie: neutral or not right now)
  413. invariant._sEnglishDisplayName = "Invariant Language (Invariant Country)"; // English pretty name for this locale
  414. invariant._sNativeDisplayName = "Invariant Language (Invariant Country)"; // Native pretty name for this locale
  415. invariant._sSpecificCulture = ""; // The culture name to be used in CultureInfo.CreateSpecificCulture()
  416. // Language
  417. invariant._sISO639Language = "iv"; // ISO 639 Language Name
  418. invariant._sISO639Language2 = "ivl"; // 3 char ISO 639 lang name 2
  419. invariant._sLocalizedLanguage = "Invariant Language"; // Display name for this Language
  420. invariant._sEnglishLanguage = "Invariant Language"; // English name for this language
  421. invariant._sNativeLanguage = "Invariant Language"; // Native name of this language
  422. invariant._sAbbrevLang = "IVL"; // abbreviated language name (Windows Language Name)
  423. invariant._sConsoleFallbackName = ""; // The culture name for the console fallback UI culture
  424. invariant._iInputLanguageHandle = 0x07F; // input language handle
  425. // Region
  426. invariant._sRegionName = "IV"; // (RegionInfo)
  427. invariant._sEnglishCountry = "Invariant Country"; // english country name (RegionInfo)
  428. invariant._sNativeCountry = "Invariant Country"; // native country name (Windows Only)
  429. invariant._sISO3166CountryName = "IV"; // (RegionInfo), ie: US
  430. invariant._sISO3166CountryName2 = "ivc"; // 3 char ISO 3166 country name 2 2(RegionInfo)
  431. invariant._iGeoId = 244; // GeoId (Windows Only)
  432. // Numbers
  433. invariant._sPositiveSign = "+"; // positive sign
  434. invariant._sNegativeSign = "-"; // negative sign
  435. invariant._iDigits = 2; // number of fractional digits
  436. invariant._iNegativeNumber = 1; // negative number format
  437. invariant._waGrouping = new int[] { 3 }; // grouping of digits
  438. invariant._sDecimalSeparator = "."; // decimal separator
  439. invariant._sThousandSeparator = ","; // thousands separator
  440. invariant._sNaN = "NaN"; // Not a Number
  441. invariant._sPositiveInfinity = "Infinity"; // + Infinity
  442. invariant._sNegativeInfinity = "-Infinity"; // - Infinity
  443. // Percent
  444. invariant._iNegativePercent = 0; // Negative Percent (0-3)
  445. invariant._iPositivePercent = 0; // Positive Percent (0-11)
  446. invariant._sPercent = "%"; // Percent (%) symbol
  447. invariant._sPerMille = "\x2030"; // PerMille symbol
  448. // Currency
  449. invariant._sCurrency = "\x00a4"; // local monetary symbol: for international monetary symbol
  450. invariant._sIntlMonetarySymbol = "XDR"; // international monetary symbol (RegionInfo)
  451. invariant._sEnglishCurrency = "International Monetary Fund"; // English name for this currency (Windows Only)
  452. invariant._sNativeCurrency = "International Monetary Fund"; // Native name for this currency (Windows Only)
  453. invariant._iCurrencyDigits = 2; // # local monetary fractional digits
  454. invariant._iCurrency = 0; // positive currency format
  455. invariant._iNegativeCurrency = 0; // negative currency format
  456. invariant._waMonetaryGrouping = new int[] { 3 }; // monetary grouping of digits
  457. invariant._sMonetaryDecimal = "."; // monetary decimal separator
  458. invariant._sMonetaryThousand = ","; // monetary thousands separator
  459. // Misc
  460. invariant._iMeasure = 0; // system of measurement 0=metric, 1=US (RegionInfo)
  461. invariant._sListSeparator = ","; // list separator
  462. // Time
  463. invariant._sTimeSeparator = ":";
  464. invariant._sAM1159 = "AM"; // AM designator
  465. invariant._sPM2359 = "PM"; // PM designator
  466. invariant._saLongTimes = new string[] { "HH:mm:ss" }; // time format
  467. invariant._saShortTimes = new string[] { "HH:mm", "hh:mm tt", "H:mm", "h:mm tt" }; // short time format
  468. invariant._saDurationFormats = new string[] { "HH:mm:ss" }; // time duration format
  469. // Calendar specific data
  470. invariant._iFirstDayOfWeek = 0; // first day of week
  471. invariant._iFirstWeekOfYear = 0; // first week of year
  472. invariant._waCalendars = new CalendarId[] { CalendarId.GREGORIAN }; // all available calendar type(s). The first one is the default calendar
  473. // Store for specific data about each calendar
  474. invariant._calendars = new CalendarData[CalendarData.MAX_CALENDARS];
  475. invariant._calendars[0] = CalendarData.Invariant;
  476. // Text information
  477. invariant._iReadingLayout = 0;
  478. // These are desktop only, not coreclr
  479. invariant._iLanguage = CultureInfo.LOCALE_INVARIANT; // locale ID (0409) - NO sort information
  480. invariant._iDefaultAnsiCodePage = 1252; // default ansi code page ID (ACP)
  481. invariant._iDefaultOemCodePage = 437; // default oem code page ID (OCP or OEM)
  482. invariant._iDefaultMacCodePage = 10000; // default macintosh code page
  483. invariant._iDefaultEbcdicCodePage = 037; // default EBCDIC code page
  484. if (GlobalizationMode.Invariant)
  485. {
  486. invariant._sLocalizedDisplayName = invariant._sNativeDisplayName;
  487. invariant._sLocalizedCountry = invariant._sNativeCountry;
  488. }
  489. return invariant;
  490. }
  491. /// <summary>
  492. /// Build our invariant information
  493. /// We need an invariant instance, which we build hard-coded
  494. /// </summary>
  495. internal static CultureData Invariant
  496. {
  497. get
  498. {
  499. if (s_Invariant == null)
  500. {
  501. // Remember it
  502. s_Invariant = CreateCultureWithInvariantData();
  503. }
  504. return s_Invariant;
  505. }
  506. }
  507. private volatile static CultureData? s_Invariant;
  508. // Cache of cultures we've already looked up
  509. private static volatile StringCultureDataDictionary? s_cachedCultures;
  510. private static readonly object s_lock = new object();
  511. internal static CultureData? GetCultureData(string? cultureName, bool useUserOverride)
  512. {
  513. // First do a shortcut for Invariant
  514. if (string.IsNullOrEmpty(cultureName))
  515. {
  516. return CultureData.Invariant;
  517. }
  518. // Try the hash table first
  519. string hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
  520. StringCultureDataDictionary? tempHashTable = s_cachedCultures;
  521. if (tempHashTable == null)
  522. {
  523. // No table yet, make a new one
  524. tempHashTable = new StringCultureDataDictionary();
  525. }
  526. else
  527. {
  528. // Check the hash table
  529. bool ret;
  530. CultureData? retVal;
  531. lock (s_lock)
  532. {
  533. ret = tempHashTable.TryGetValue(hashName, out retVal);
  534. }
  535. if (ret && retVal != null)
  536. {
  537. return retVal;
  538. }
  539. }
  540. // Not found in the hash table, need to see if we can build one that works for us
  541. CultureData? culture = CreateCultureData(cultureName, useUserOverride);
  542. if (culture == null)
  543. {
  544. return null;
  545. }
  546. // Found one, add it to the cache
  547. lock (s_lock)
  548. {
  549. tempHashTable[hashName] = culture;
  550. }
  551. // Copy the hashtable to the corresponding member variables. This will potentially overwrite
  552. // new tables simultaneously created by a new thread, but maximizes thread safety.
  553. s_cachedCultures = tempHashTable;
  554. return culture;
  555. }
  556. private static string NormalizeCultureName(string name, out bool isNeutralName)
  557. {
  558. isNeutralName = true;
  559. int i = 0;
  560. if (name.Length > LocaleNameMaxLength)
  561. {
  562. // Theoretically we shouldn't hit this exception.
  563. throw new ArgumentException(SR.Format(SR.Argument_InvalidId, nameof(name)));
  564. }
  565. Span<char> normalizedName = stackalloc char[name.Length];
  566. bool changed = false;
  567. while (i < name.Length && name[i] != '-' && name[i] != '_')
  568. {
  569. if (name[i] >= 'A' && name[i] <= 'Z')
  570. {
  571. // lowercase characters before '-'
  572. normalizedName[i] = (char) (((int)name[i]) + 0x20);
  573. changed = true;
  574. }
  575. else
  576. {
  577. normalizedName[i] = name[i];
  578. }
  579. i++;
  580. }
  581. if (i < name.Length)
  582. {
  583. // this is not perfect to detect the non neutral cultures but it is good enough when we are running in invariant mode
  584. isNeutralName = false;
  585. }
  586. while (i < name.Length)
  587. {
  588. if (name[i] >= 'a' && name[i] <= 'z')
  589. {
  590. normalizedName[i] = (char) (((int)name[i]) - 0x20);
  591. changed = true;
  592. }
  593. else
  594. {
  595. normalizedName[i] = name[i];
  596. }
  597. i++;
  598. }
  599. if (changed)
  600. {
  601. return new string(normalizedName);
  602. }
  603. return name;
  604. }
  605. private static CultureData? CreateCultureData(string cultureName, bool useUserOverride)
  606. {
  607. if (GlobalizationMode.Invariant)
  608. {
  609. if (cultureName.Length > LocaleNameMaxLength || !CultureInfo.VerifyCultureName(cultureName, false))
  610. {
  611. return null;
  612. }
  613. CultureData cd = CreateCultureWithInvariantData();
  614. cd._bUseOverrides = useUserOverride;
  615. cd._sName = NormalizeCultureName(cultureName, out cd._bNeutral);
  616. cd._sRealName = cd._sName;
  617. cd._sWindowsName = cd._sName;
  618. cd._iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
  619. return cd;
  620. }
  621. if (cultureName.Length == 1 && (cultureName[0] == 'C' || cultureName[0] == 'c'))
  622. {
  623. // Always map the "C" locale to Invariant to avoid mapping it to en_US_POSIX on Linux because POSIX
  624. // locale collation doesn't support case insensitive comparisons.
  625. // We do the same mapping on Windows for the sake of consistency.
  626. return CultureData.Invariant;
  627. }
  628. CultureData culture = new CultureData();
  629. culture._bUseOverrides = useUserOverride;
  630. culture._sRealName = cultureName;
  631. // Ask native code if that one's real
  632. if (!culture.InitCultureData() && !culture.InitCompatibilityCultureData())
  633. {
  634. return null;
  635. }
  636. return culture;
  637. }
  638. private bool InitCompatibilityCultureData()
  639. {
  640. // for compatibility handle the deprecated ids: zh-chs, zh-cht
  641. string cultureName = _sRealName!;
  642. string fallbackCultureName;
  643. string realCultureName;
  644. switch (AnsiToLower(cultureName))
  645. {
  646. case "zh-chs":
  647. fallbackCultureName = "zh-Hans";
  648. realCultureName = "zh-CHS";
  649. break;
  650. case "zh-cht":
  651. fallbackCultureName = "zh-Hant";
  652. realCultureName = "zh-CHT";
  653. break;
  654. default:
  655. return false;
  656. }
  657. _sRealName = fallbackCultureName;
  658. if (!InitCultureData())
  659. {
  660. return false;
  661. }
  662. // fixup our data
  663. _sName = realCultureName; // the name that goes back to the user
  664. _sParent = fallbackCultureName;
  665. return true;
  666. }
  667. /// We'd rather people use the named version since this doesn't allow custom locales
  668. internal static CultureData GetCultureData(int culture, bool bUseUserOverride)
  669. {
  670. string? localeName = null;
  671. CultureData? retVal = null;
  672. if (culture == CultureInfo.LOCALE_INVARIANT)
  673. {
  674. return Invariant;
  675. }
  676. if (GlobalizationMode.Invariant)
  677. {
  678. // LCID is not supported in the InvariantMode
  679. throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
  680. }
  681. // Convert the lcid to a name, then use that
  682. // Note that this will return neutral names (unlike Vista native API)
  683. localeName = LCIDToLocaleName(culture);
  684. if (!string.IsNullOrEmpty(localeName))
  685. {
  686. // Valid name, use it
  687. retVal = GetCultureData(localeName, bUseUserOverride);
  688. }
  689. // If not successful, throw
  690. if (retVal == null)
  691. {
  692. throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
  693. }
  694. // Return the one we found
  695. return retVal;
  696. }
  697. /// <summary>
  698. /// The real name used to construct the locale (ie: de-DE_phoneb)
  699. /// </summary>
  700. internal string CultureName
  701. {
  702. get
  703. {
  704. Debug.Assert(_sRealName != null, "[CultureData.CultureName] Expected _sRealName to be populated by already");
  705. // since windows doesn't know about zh-CHS and zh-CHT,
  706. // we leave sRealName == zh-Hanx but we still need to
  707. // pretend that it was zh-CHX.
  708. switch (_sName)
  709. {
  710. case "zh-CHS":
  711. case "zh-CHT":
  712. return _sName;
  713. }
  714. return _sRealName;
  715. }
  716. }
  717. /// <summary>
  718. /// Are overrides enabled?
  719. /// </summary>
  720. internal bool UseUserOverride => _bUseOverrides;
  721. /// <summary>
  722. /// locale name (ie: de-DE, NO sort information)
  723. /// </summary>
  724. internal string Name => _sName ?? string.Empty;
  725. // Parent name (which may be a custom locale/culture)
  726. internal string ParentName
  727. {
  728. get
  729. {
  730. if (_sParent == null)
  731. {
  732. // Ask using the real name, so that we get parents of neutrals
  733. _sParent = GetLocaleInfo(_sRealName!, LocaleStringData.ParentName);
  734. }
  735. return _sParent;
  736. }
  737. }
  738. // Localized pretty name for this locale (ie: Inglis (estados Unitos))
  739. internal string DisplayName
  740. {
  741. get
  742. {
  743. if (_sLocalizedDisplayName == null)
  744. {
  745. if (IsSupplementalCustomCulture)
  746. {
  747. if (IsNeutralCulture)
  748. {
  749. _sLocalizedDisplayName = NativeLanguageName;
  750. }
  751. else
  752. {
  753. _sLocalizedDisplayName = NativeName;
  754. }
  755. }
  756. else
  757. {
  758. try
  759. {
  760. const string ZH_CHT = "zh-CHT";
  761. const string ZH_CHS = "zh-CHS";
  762. if (Name.Equals(ZH_CHT, StringComparison.OrdinalIgnoreCase))
  763. {
  764. _sLocalizedDisplayName = GetLanguageDisplayName("zh-Hant");
  765. }
  766. else if (Name.Equals(ZH_CHS, StringComparison.OrdinalIgnoreCase))
  767. {
  768. _sLocalizedDisplayName = GetLanguageDisplayName("zh-Hans");
  769. }
  770. else
  771. {
  772. _sLocalizedDisplayName = GetLanguageDisplayName(Name);
  773. }
  774. }
  775. catch (Exception)
  776. {
  777. // do nothing
  778. }
  779. }
  780. // If it hasn't been found (Windows 8 and up), fallback to the system
  781. if (string.IsNullOrEmpty(_sLocalizedDisplayName))
  782. {
  783. // If its neutral use the language name
  784. if (IsNeutralCulture)
  785. {
  786. _sLocalizedDisplayName = LocalizedLanguageName;
  787. }
  788. else
  789. {
  790. // Usually the UI culture shouldn't be different than what we got from WinRT except
  791. // if DefaultThreadCurrentUICulture was set
  792. CultureInfo ci;
  793. if (CultureInfo.DefaultThreadCurrentUICulture != null &&
  794. ((ci = GetUserDefaultCulture()) != null) &&
  795. !CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
  796. {
  797. _sLocalizedDisplayName = NativeName;
  798. }
  799. else
  800. {
  801. _sLocalizedDisplayName = GetLocaleInfo(LocaleStringData.LocalizedDisplayName);
  802. }
  803. }
  804. }
  805. }
  806. return _sLocalizedDisplayName;
  807. }
  808. }
  809. /// <summary>
  810. /// English pretty name for this locale (ie: English (United States))
  811. /// </summary>
  812. internal string EnglishName
  813. {
  814. get
  815. {
  816. if (_sEnglishDisplayName == null)
  817. {
  818. // If its neutral use the language name
  819. if (IsNeutralCulture)
  820. {
  821. _sEnglishDisplayName = EnglishLanguageName;
  822. // differentiate the legacy display names
  823. switch (_sName)
  824. {
  825. case "zh-CHS":
  826. case "zh-CHT":
  827. _sEnglishDisplayName += " Legacy";
  828. break;
  829. }
  830. }
  831. else
  832. {
  833. _sEnglishDisplayName = GetLocaleInfo(LocaleStringData.EnglishDisplayName);
  834. // if it isn't found build one:
  835. if (string.IsNullOrEmpty(_sEnglishDisplayName))
  836. {
  837. // Our existing names mostly look like:
  838. // "English" + "United States" -> "English (United States)"
  839. // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
  840. if (EnglishLanguageName[EnglishLanguageName.Length - 1] == ')')
  841. {
  842. // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
  843. _sEnglishDisplayName = string.Concat(
  844. EnglishLanguageName.AsSpan(0, _sEnglishLanguage!.Length - 1),
  845. ", ",
  846. EnglishCountryName,
  847. ")");
  848. }
  849. else
  850. {
  851. // "English" + "United States" -> "English (United States)"
  852. _sEnglishDisplayName = EnglishLanguageName + " (" + EnglishCountryName + ")";
  853. }
  854. }
  855. }
  856. }
  857. return _sEnglishDisplayName;
  858. }
  859. }
  860. /// <summary>
  861. /// Native pretty name for this locale (ie: Deutsch (Deutschland))
  862. /// </summary>
  863. internal string NativeName
  864. {
  865. get
  866. {
  867. if (_sNativeDisplayName == null)
  868. {
  869. // If its neutral use the language name
  870. if (IsNeutralCulture)
  871. {
  872. _sNativeDisplayName = NativeLanguageName;
  873. // differentiate the legacy display names
  874. switch (_sName)
  875. {
  876. case "zh-CHS":
  877. _sNativeDisplayName += " \u65E7\u7248";
  878. break;
  879. case "zh-CHT":
  880. _sNativeDisplayName += " \u820A\u7248";
  881. break;
  882. }
  883. }
  884. else
  885. {
  886. _sNativeDisplayName = GetLocaleInfo(LocaleStringData.NativeDisplayName);
  887. // if it isn't found build one:
  888. if (string.IsNullOrEmpty(_sNativeDisplayName))
  889. {
  890. // These should primarily be "Deutsch (Deutschland)" type names
  891. _sNativeDisplayName = NativeLanguageName + " (" + NativeCountryName + ")";
  892. }
  893. }
  894. }
  895. return _sNativeDisplayName;
  896. }
  897. }
  898. /// <summary>
  899. /// The culture name to be used in CultureInfo.CreateSpecificCulture()
  900. /// </summary>
  901. internal string SpecificCultureName
  902. {
  903. get
  904. {
  905. // This got populated during the culture initialization
  906. Debug.Assert(_sSpecificCulture != null, "[CultureData.SpecificCultureName] Expected this.sSpecificCulture to be populated by culture data initialization already");
  907. return _sSpecificCulture;
  908. }
  909. }
  910. /// <summary>
  911. /// iso 639 language name, ie: en
  912. /// </summary>
  913. internal string TwoLetterISOLanguageName
  914. {
  915. get
  916. {
  917. if (_sISO639Language == null)
  918. {
  919. _sISO639Language = GetLocaleInfo(LocaleStringData.Iso639LanguageTwoLetterName);
  920. }
  921. return _sISO639Language;
  922. }
  923. }
  924. /// <summary>
  925. /// iso 639 language name, ie: eng
  926. /// </summary>
  927. internal string ThreeLetterISOLanguageName
  928. {
  929. get
  930. {
  931. if (_sISO639Language2 == null)
  932. {
  933. _sISO639Language2 = GetLocaleInfo(LocaleStringData.Iso639LanguageThreeLetterName);
  934. }
  935. return _sISO639Language2;
  936. }
  937. }
  938. /// <summary>
  939. /// abbreviated windows language name (ie: enu) (non-standard, avoid this)
  940. /// </summary>
  941. internal string ThreeLetterWindowsLanguageName
  942. {
  943. get
  944. {
  945. if (_sAbbrevLang == null)
  946. {
  947. _sAbbrevLang = GetThreeLetterWindowsLanguageName(_sRealName!);
  948. }
  949. return _sAbbrevLang;
  950. }
  951. }
  952. /// <summary>
  953. /// Localized name for this language (Windows Only) ie: Inglis
  954. /// This is only valid for Windows 8 and higher neutrals:
  955. /// </summary>
  956. private string LocalizedLanguageName
  957. {
  958. get
  959. {
  960. if (_sLocalizedLanguage == null)
  961. {
  962. // Usually the UI culture shouldn't be different than what we got from WinRT except
  963. // if DefaultThreadCurrentUICulture was set
  964. CultureInfo ci;
  965. if (CultureInfo.DefaultThreadCurrentUICulture != null &&
  966. ((ci = GetUserDefaultCulture()) != null) &&
  967. !CultureInfo.DefaultThreadCurrentUICulture!.Name.Equals(ci.Name))
  968. {
  969. _sLocalizedLanguage = NativeLanguageName;
  970. }
  971. else
  972. {
  973. _sLocalizedLanguage = GetLocaleInfo(LocaleStringData.LocalizedLanguageName);
  974. }
  975. }
  976. return _sLocalizedLanguage;
  977. }
  978. }
  979. /// <summary>
  980. /// English name for this language (Windows Only) ie: German
  981. /// </summary>
  982. private string EnglishLanguageName
  983. {
  984. get
  985. {
  986. if (_sEnglishLanguage == null)
  987. {
  988. _sEnglishLanguage = GetLocaleInfo(LocaleStringData.EnglishLanguageName);
  989. }
  990. return _sEnglishLanguage;
  991. }
  992. }
  993. /// <summary>
  994. /// Native name of this language (Windows Only) ie: Deutsch
  995. /// </summary>
  996. private string NativeLanguageName
  997. {
  998. get
  999. {
  1000. if (_sNativeLanguage == null)
  1001. {
  1002. _sNativeLanguage = GetLocaleInfo(LocaleStringData.NativeLanguageName);
  1003. }
  1004. return _sNativeLanguage;
  1005. }
  1006. }
  1007. /// <summary>
  1008. /// region name (eg US)
  1009. /// </summary>
  1010. internal string RegionName
  1011. {
  1012. get
  1013. {
  1014. if (_sRegionName == null)
  1015. {
  1016. _sRegionName = GetLocaleInfo(LocaleStringData.Iso3166CountryName);
  1017. }
  1018. return _sRegionName;
  1019. }
  1020. }
  1021. internal int GeoId
  1022. {
  1023. get
  1024. {
  1025. if (_iGeoId == undef)
  1026. {
  1027. _iGeoId = GetGeoId(_sRealName!);
  1028. }
  1029. return _iGeoId;
  1030. }
  1031. }
  1032. /// <summary>
  1033. /// localized name for the country
  1034. /// </summary>
  1035. internal string LocalizedCountryName
  1036. {
  1037. get
  1038. {
  1039. if (_sLocalizedCountry == null)
  1040. {
  1041. try
  1042. {
  1043. _sLocalizedCountry = GetRegionDisplayName(TwoLetterISOCountryName);
  1044. }
  1045. catch (Exception)
  1046. {
  1047. // do nothing. we'll fallback
  1048. }
  1049. if (_sLocalizedCountry == null)
  1050. {
  1051. _sLocalizedCountry = NativeCountryName;
  1052. }
  1053. }
  1054. return _sLocalizedCountry;
  1055. }
  1056. }
  1057. /// <summary>
  1058. /// english country name (RegionInfo) ie: Germany
  1059. /// </summary>
  1060. internal string EnglishCountryName
  1061. {
  1062. get
  1063. {
  1064. if (_sEnglishCountry == null)
  1065. {
  1066. _sEnglishCountry = GetLocaleInfo(LocaleStringData.EnglishCountryName);
  1067. }
  1068. return _sEnglishCountry;
  1069. }
  1070. }
  1071. /// <summary>
  1072. /// native country name (RegionInfo) ie: Deutschland
  1073. /// </summary>
  1074. internal string NativeCountryName
  1075. {
  1076. get
  1077. {
  1078. if (_sNativeCountry == null)
  1079. {
  1080. _sNativeCountry = GetLocaleInfo(LocaleStringData.NativeCountryName);
  1081. }
  1082. return _sNativeCountry;
  1083. }
  1084. }
  1085. /// <summary>
  1086. /// ISO 3166 Country Name
  1087. /// </summary>
  1088. internal string TwoLetterISOCountryName
  1089. {
  1090. get
  1091. {
  1092. if (_sISO3166CountryName == null)
  1093. {
  1094. _sISO3166CountryName = GetLocaleInfo(LocaleStringData.Iso3166CountryName);
  1095. }
  1096. return _sISO3166CountryName;
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 3 letter ISO 3166 country code
  1101. /// </summary>
  1102. internal string ThreeLetterISOCountryName
  1103. {
  1104. get
  1105. {
  1106. if (_sISO3166CountryName2 == null)
  1107. {
  1108. _sISO3166CountryName2 = GetLocaleInfo(LocaleStringData.Iso3166CountryName2);
  1109. }
  1110. return _sISO3166CountryName2;
  1111. }
  1112. }
  1113. internal int KeyboardLayoutId
  1114. {
  1115. get
  1116. {
  1117. if (_iInputLanguageHandle == undef)
  1118. {
  1119. if (IsSupplementalCustomCulture)
  1120. {
  1121. _iInputLanguageHandle = 0x0409;
  1122. }
  1123. else
  1124. {
  1125. // Input Language is same as LCID for built-in cultures
  1126. _iInputLanguageHandle = LCID;
  1127. }
  1128. }
  1129. return _iInputLanguageHandle;
  1130. }
  1131. }
  1132. /// <summary>
  1133. /// Console fallback name (ie: locale to use for console apps for unicode-only locales)
  1134. /// </summary>
  1135. internal string SCONSOLEFALLBACKNAME
  1136. {
  1137. get
  1138. {
  1139. if (_sConsoleFallbackName == null)
  1140. {
  1141. _sConsoleFallbackName = GetConsoleFallbackName(_sRealName!);
  1142. }
  1143. return _sConsoleFallbackName;
  1144. }
  1145. }
  1146. /// <summary>
  1147. /// (user can override) grouping of digits
  1148. /// </summary>
  1149. internal int[] NumberGroupSizes
  1150. {
  1151. get
  1152. {
  1153. if (_waGrouping == null)
  1154. {
  1155. _waGrouping = GetLocaleInfo(LocaleGroupingData.Digit);
  1156. }
  1157. return _waGrouping;
  1158. }
  1159. }
  1160. /// <summary>
  1161. /// Not a Number
  1162. /// </summary>
  1163. private string NaNSymbol
  1164. {
  1165. get
  1166. {
  1167. if (_sNaN == null)
  1168. {
  1169. _sNaN = GetLocaleInfo(LocaleStringData.NaNSymbol);
  1170. }
  1171. return _sNaN;
  1172. }
  1173. }
  1174. /// <summary>
  1175. /// + Infinity
  1176. /// </summary>
  1177. private string PositiveInfinitySymbol
  1178. {
  1179. get
  1180. {
  1181. if (_sPositiveInfinity == null)
  1182. {
  1183. _sPositiveInfinity = GetLocaleInfo(LocaleStringData.PositiveInfinitySymbol);
  1184. }
  1185. return _sPositiveInfinity;
  1186. }
  1187. }
  1188. /// <summary>
  1189. /// - Infinity
  1190. /// </summary>
  1191. private string NegativeInfinitySymbol
  1192. {
  1193. get
  1194. {
  1195. if (_sNegativeInfinity == null)
  1196. {
  1197. _sNegativeInfinity = GetLocaleInfo(LocaleStringData.NegativeInfinitySymbol);
  1198. }
  1199. return _sNegativeInfinity;
  1200. }
  1201. }
  1202. /// <summary>
  1203. /// Negative Percent (0-3)
  1204. /// </summary>
  1205. private int PercentNegativePattern
  1206. {
  1207. get
  1208. {
  1209. if (_iNegativePercent == undef)
  1210. {
  1211. // Note that <= Windows Vista this is synthesized by native code
  1212. _iNegativePercent = GetLocaleInfo(LocaleNumberData.NegativePercentFormat);
  1213. }
  1214. return _iNegativePercent;
  1215. }
  1216. }
  1217. /// <summary>
  1218. /// Positive Percent (0-11)
  1219. /// </summary>
  1220. private int PercentPositivePattern
  1221. {
  1222. get
  1223. {
  1224. if (_iPositivePercent == undef)
  1225. {
  1226. // Note that <= Windows Vista this is synthesized by native code
  1227. _iPositivePercent = GetLocaleInfo(LocaleNumberData.PositivePercentFormat);
  1228. }
  1229. return _iPositivePercent;
  1230. }
  1231. }
  1232. /// <summary>
  1233. /// Percent (%) symbol
  1234. /// </summary>
  1235. private string PercentSymbol
  1236. {
  1237. get
  1238. {
  1239. if (_sPercent == null)
  1240. {
  1241. _sPercent = GetLocaleInfo(LocaleStringData.PercentSymbol);
  1242. }
  1243. return _sPercent;
  1244. }
  1245. }
  1246. /// <summary>
  1247. /// PerMille symbol
  1248. /// </summary>
  1249. private string PerMilleSymbol
  1250. {
  1251. get
  1252. {
  1253. if (_sPerMille == null)
  1254. {
  1255. _sPerMille = GetLocaleInfo(LocaleStringData.PerMilleSymbol);
  1256. }
  1257. return _sPerMille;
  1258. }
  1259. }
  1260. /// <summary>
  1261. /// (user can override) local monetary symbol, eg: $
  1262. /// </summary>
  1263. internal string CurrencySymbol
  1264. {
  1265. get
  1266. {
  1267. if (_sCurrency == null)
  1268. {
  1269. _sCurrency = GetLocaleInfo(LocaleStringData.MonetarySymbol);
  1270. }
  1271. return _sCurrency;
  1272. }
  1273. }
  1274. /// <summary>
  1275. /// international monetary symbol (RegionInfo), eg: USD
  1276. /// </summary>
  1277. internal string ISOCurrencySymbol
  1278. {
  1279. get
  1280. {
  1281. if (_sIntlMonetarySymbol == null)
  1282. {
  1283. _sIntlMonetarySymbol = GetLocaleInfo(LocaleStringData.Iso4217MonetarySymbol);
  1284. }
  1285. return _sIntlMonetarySymbol;
  1286. }
  1287. }
  1288. /// <summary>
  1289. /// English name for this currency (RegionInfo), eg: US Dollar
  1290. /// </summary>
  1291. internal string CurrencyEnglishName
  1292. {
  1293. get
  1294. {
  1295. if (_sEnglishCurrency == null)
  1296. {
  1297. _sEnglishCurrency = GetLocaleInfo(LocaleStringData.CurrencyEnglishName);
  1298. }
  1299. return _sEnglishCurrency;
  1300. }
  1301. }
  1302. /// <summary>
  1303. /// Native name for this currency (RegionInfo), eg: Schweiz Frank
  1304. /// </summary>
  1305. internal string CurrencyNativeName
  1306. {
  1307. get
  1308. {
  1309. if (_sNativeCurrency == null)
  1310. {
  1311. _sNativeCurrency = GetLocaleInfo(LocaleStringData.CurrencyNativeName);
  1312. }
  1313. return _sNativeCurrency;
  1314. }
  1315. }
  1316. /// <summary>
  1317. /// (user can override) monetary grouping of digits
  1318. /// </summary>
  1319. internal int[] CurrencyGroupSizes
  1320. {
  1321. get
  1322. {
  1323. if (_waMonetaryGrouping == null)
  1324. {
  1325. _waMonetaryGrouping = GetLocaleInfo(LocaleGroupingData.Monetary);
  1326. }
  1327. return _waMonetaryGrouping;
  1328. }
  1329. }
  1330. /// <summary>
  1331. /// (user can override) system of measurement 0=metric, 1=US (RegionInfo)
  1332. /// </summary>
  1333. internal int MeasurementSystem
  1334. {
  1335. get
  1336. {
  1337. if (_iMeasure == undef)
  1338. {
  1339. _iMeasure = GetLocaleInfo(LocaleNumberData.MeasurementSystem);
  1340. }
  1341. return _iMeasure;
  1342. }
  1343. }
  1344. /// <summary>
  1345. /// (user can override) list Separator
  1346. /// </summary>
  1347. internal string ListSeparator
  1348. {
  1349. get
  1350. {
  1351. if (_sListSeparator == null)
  1352. {
  1353. _sListSeparator = GetLocaleInfo(LocaleStringData.ListSeparator);
  1354. }
  1355. return _sListSeparator;
  1356. }
  1357. }
  1358. /// <summary>
  1359. /// (user can override) AM designator
  1360. /// </summary>
  1361. internal string AMDesignator
  1362. {
  1363. get
  1364. {
  1365. if (_sAM1159 == null)
  1366. {
  1367. _sAM1159 = GetLocaleInfo(LocaleStringData.AMDesignator);
  1368. }
  1369. return _sAM1159;
  1370. }
  1371. }
  1372. /// <summary>
  1373. /// (user can override) PM designator
  1374. /// </summary>
  1375. internal string PMDesignator
  1376. {
  1377. get
  1378. {
  1379. if (_sPM2359 == null)
  1380. {
  1381. _sPM2359 = GetLocaleInfo(LocaleStringData.PMDesignator);
  1382. }
  1383. return _sPM2359;
  1384. }
  1385. }
  1386. /// <summary>
  1387. /// (user can override) time format
  1388. /// </summary>
  1389. internal string[] LongTimes
  1390. {
  1391. get
  1392. {
  1393. if (_saLongTimes == null)
  1394. {
  1395. Debug.Assert(!GlobalizationMode.Invariant);
  1396. string[]? longTimes = GetTimeFormats();
  1397. if (longTimes == null || longTimes.Length == 0)
  1398. {
  1399. _saLongTimes = Invariant._saLongTimes!;
  1400. }
  1401. else
  1402. {
  1403. _saLongTimes = longTimes;
  1404. }
  1405. }
  1406. return _saLongTimes;
  1407. }
  1408. }
  1409. /// <summary>
  1410. /// short time format
  1411. /// Short times (derived from long times format)
  1412. /// </summary>
  1413. internal string[] ShortTimes
  1414. {
  1415. get
  1416. {
  1417. if (_saShortTimes == null)
  1418. {
  1419. Debug.Assert(!GlobalizationMode.Invariant);
  1420. // Try to get the short times from the OS/culture.dll
  1421. string[]? shortTimes = GetShortTimeFormats();
  1422. if (shortTimes == null || shortTimes.Length == 0)
  1423. {
  1424. //
  1425. // If we couldn't find short times, then compute them from long times
  1426. // (eg: CORECLR on < Win7 OS & fallback for missing culture.dll)
  1427. //
  1428. shortTimes = DeriveShortTimesFromLong();
  1429. }
  1430. // Found short times, use them
  1431. _saShortTimes = shortTimes;
  1432. }
  1433. return _saShortTimes;
  1434. }
  1435. }
  1436. private string[] DeriveShortTimesFromLong()
  1437. {
  1438. // Our logic is to look for h,H,m,s,t. If we find an s, then we check the string
  1439. // between it and the previous marker, if any. If its a short, unescaped separator,
  1440. // then we don't retain that part.
  1441. // We then check after the ss and remove anything before the next h,H,m,t...
  1442. string[] longTimes = LongTimes;
  1443. string[] shortTimes = new string[longTimes.Length];
  1444. for (int i = 0; i < longTimes.Length; i++)
  1445. {
  1446. shortTimes[i] = StripSecondsFromPattern(longTimes[i]);
  1447. }
  1448. return shortTimes;
  1449. }
  1450. private static string StripSecondsFromPattern(string time)
  1451. {
  1452. bool bEscape = false;
  1453. int iLastToken = -1;
  1454. // Find the seconds
  1455. for (int j = 0; j < time.Length; j++)
  1456. {
  1457. // Change escape mode?
  1458. if (time[j] == '\'')
  1459. {
  1460. // Continue
  1461. bEscape = !bEscape;
  1462. continue;
  1463. }
  1464. // See if there was a single \
  1465. if (time[j] == '\\')
  1466. {
  1467. // Skip next char
  1468. j++;
  1469. continue;
  1470. }
  1471. if (bEscape)
  1472. {
  1473. continue;
  1474. }
  1475. switch (time[j])
  1476. {
  1477. // Check for seconds
  1478. case 's':
  1479. // Found seconds, see if there was something unescaped and short between
  1480. // the last marker and the seconds. Windows says separator can be a
  1481. // maximum of three characters (without null)
  1482. // If 1st or last characters were ', then ignore it
  1483. if ((j - iLastToken) <= 4 && (j - iLastToken) > 1 &&
  1484. (time[iLastToken + 1] != '\'') &&
  1485. (time[j - 1] != '\''))
  1486. {
  1487. // There was something there we want to remember
  1488. if (iLastToken >= 0)
  1489. {
  1490. j = iLastToken + 1;
  1491. }
  1492. }
  1493. bool containsSpace;
  1494. int endIndex = GetIndexOfNextTokenAfterSeconds(time, j, out containsSpace);
  1495. string sep;
  1496. if (containsSpace)
  1497. {
  1498. sep = " ";
  1499. }
  1500. else
  1501. {
  1502. sep = "";
  1503. }
  1504. time = string.Concat(time.AsSpan(0, j), sep, time.AsSpan(endIndex));
  1505. break;
  1506. case 'm':
  1507. case 'H':
  1508. case 'h':
  1509. iLastToken = j;
  1510. break;
  1511. }
  1512. }
  1513. return time;
  1514. }
  1515. private static int GetIndexOfNextTokenAfterSeconds(string time, int index, out bool containsSpace)
  1516. {
  1517. bool shouldEscape = false;
  1518. containsSpace = false;
  1519. for (; index < time.Length; index++)
  1520. {
  1521. switch (time[index])
  1522. {
  1523. case '\'':
  1524. shouldEscape = !shouldEscape;
  1525. continue;
  1526. case '\\':
  1527. index++;
  1528. if (time[index] == ' ')
  1529. {
  1530. containsSpace = true;
  1531. }
  1532. continue;
  1533. case ' ':
  1534. containsSpace = true;
  1535. break;
  1536. case 't':
  1537. case 'm':
  1538. case 'H':
  1539. case 'h':
  1540. if (shouldEscape)
  1541. {
  1542. continue;
  1543. }
  1544. return index;
  1545. }
  1546. }
  1547. containsSpace = false;
  1548. return index;
  1549. }
  1550. // (user can override) first day of week
  1551. internal int FirstDayOfWeek
  1552. {
  1553. get
  1554. {
  1555. if (_iFirstDayOfWeek == undef)
  1556. {
  1557. _iFirstDayOfWeek = GetFirstDayOfWeek();
  1558. }
  1559. return _iFirstDayOfWeek;
  1560. }
  1561. }
  1562. // (user can override) first week of year
  1563. internal int CalendarWeekRule
  1564. {
  1565. get
  1566. {
  1567. if (_iFirstWeekOfYear == undef)
  1568. {
  1569. _iFirstWeekOfYear = GetLocaleInfo(LocaleNumberData.FirstWeekOfYear);
  1570. }
  1571. return _iFirstWeekOfYear;
  1572. }
  1573. }
  1574. /// <summary>
  1575. /// (user can override default only) short date format
  1576. /// </summary>
  1577. internal string[] ShortDates(CalendarId calendarId)
  1578. {
  1579. return GetCalendar(calendarId).saShortDates;
  1580. }
  1581. /// <summary>
  1582. /// (user can override default only) long date format
  1583. /// </summary>
  1584. internal string[] LongDates(CalendarId calendarId)
  1585. {
  1586. return GetCalendar(calendarId).saLongDates;
  1587. }
  1588. /// <summary>
  1589. /// (user can override) date year/month format.
  1590. /// </summary>
  1591. internal string[] YearMonths(CalendarId calendarId)
  1592. {
  1593. return GetCalendar(calendarId).saYearMonths;
  1594. }
  1595. internal string[] DayNames(CalendarId calendarId)
  1596. {
  1597. return GetCalendar(calendarId).saDayNames;
  1598. }
  1599. internal string[] AbbreviatedDayNames(CalendarId calendarId)
  1600. {
  1601. return GetCalendar(calendarId).saAbbrevDayNames;
  1602. }
  1603. internal string[] SuperShortDayNames(CalendarId calendarId)
  1604. {
  1605. return GetCalendar(calendarId).saSuperShortDayNames;
  1606. }
  1607. internal string[] MonthNames(CalendarId calendarId)
  1608. {
  1609. return GetCalendar(calendarId).saMonthNames;
  1610. }
  1611. internal string[] GenitiveMonthNames(CalendarId calendarId)
  1612. {
  1613. return GetCalendar(calendarId).saMonthGenitiveNames;
  1614. }
  1615. internal string[] AbbreviatedMonthNames(CalendarId calendarId)
  1616. {
  1617. return GetCalendar(calendarId).saAbbrevMonthNames;
  1618. }
  1619. internal string[] AbbreviatedGenitiveMonthNames(CalendarId calendarId)
  1620. {
  1621. return GetCalendar(calendarId).saAbbrevMonthGenitiveNames;
  1622. }
  1623. /// <remarks>>
  1624. /// Note: This only applies to Hebrew, and it basically adds a "1" to the 6th month name
  1625. /// the non-leap names skip the 7th name in the normal month name array
  1626. /// </remarks>
  1627. internal string[] LeapYearMonthNames(CalendarId calendarId)
  1628. {
  1629. return GetCalendar(calendarId).saLeapYearMonthNames;
  1630. }
  1631. internal string MonthDay(CalendarId calendarId)
  1632. {
  1633. return GetCalendar(calendarId).sMonthDay;
  1634. }
  1635. /// <summary>
  1636. /// All available calendar type(s). The first one is the default calendar.
  1637. /// </summary>
  1638. internal CalendarId[] CalendarIds
  1639. {
  1640. get
  1641. {
  1642. if (_waCalendars == null)
  1643. {
  1644. // We pass in an array of ints, and native side fills it up with count calendars.
  1645. // We then have to copy that list to a new array of the right size.
  1646. // Default calendar should be first
  1647. CalendarId[] calendars = new CalendarId[23];
  1648. Debug.Assert(_sWindowsName != null, "[CultureData.CalendarIds] Expected _sWindowsName to be populated by already");
  1649. int count = CalendarData.GetCalendars(_sWindowsName, _bUseOverrides, calendars);
  1650. // See if we had a calendar to add.
  1651. if (count == 0)
  1652. {
  1653. // Failed for some reason, just grab Gregorian from Invariant
  1654. _waCalendars = Invariant._waCalendars!;
  1655. }
  1656. else
  1657. {
  1658. // The OS may not return calendar 4 for zh-TW, but we've always allowed it.
  1659. // TODO: Is this hack necessary long-term?
  1660. if (_sWindowsName == "zh-TW")
  1661. {
  1662. bool found = false;
  1663. // Do we need to insert calendar 4?
  1664. for (int i = 0; i < count; i++)
  1665. {
  1666. // Stop if we found calendar four
  1667. if (calendars[i] == CalendarId.TAIWAN)
  1668. {
  1669. found = true;
  1670. break;
  1671. }
  1672. }
  1673. // If not found then insert it
  1674. if (!found)
  1675. {
  1676. // Insert it as the 2nd calendar
  1677. count++;
  1678. // Copy them from the 2nd position to the end, -1 for skipping 1st, -1 for one being added.
  1679. Array.Copy(calendars, 1, calendars, 2, 23 - 1 - 1);
  1680. calendars[1] = CalendarId.TAIWAN;
  1681. }
  1682. }
  1683. // It worked, remember the list
  1684. CalendarId[] temp = new CalendarId[count];
  1685. Array.Copy(calendars, 0, temp, 0, count);
  1686. // Want 1st calendar to be default
  1687. // Prior to Vista the enumeration didn't have default calendar first
  1688. if (temp.Length > 1)
  1689. {
  1690. CalendarId i = (CalendarId)GetLocaleInfo(LocaleNumberData.CalendarType);
  1691. if (temp[1] == i)
  1692. {
  1693. temp[1] = temp[0];
  1694. temp[0] = i;
  1695. }
  1696. }
  1697. _waCalendars = temp;
  1698. }
  1699. }
  1700. return _waCalendars;
  1701. }
  1702. }
  1703. /// <summary>
  1704. /// Native calendar names. Index of optional calendar - 1, empty if
  1705. /// no optional calendar at that number
  1706. /// </summary>
  1707. internal string CalendarName(CalendarId calendarId)
  1708. {
  1709. return GetCalendar(calendarId).sNativeName;
  1710. }
  1711. internal CalendarData GetCalendar(CalendarId calendarId)
  1712. {
  1713. Debug.Assert(calendarId > 0 && calendarId <= CalendarId.LAST_CALENDAR,
  1714. "[CultureData.GetCalendar] Expect calendarId to be in a valid range");
  1715. // arrays are 0 based, calendarIds are 1 based
  1716. int calendarIndex = (int)calendarId - 1;
  1717. // Have to have calendars
  1718. if (_calendars == null)
  1719. {
  1720. _calendars = new CalendarData[CalendarData.MAX_CALENDARS];
  1721. }
  1722. // we need the following local variable to avoid returning null
  1723. // when another thread creates a new array of CalendarData (above)
  1724. // right after we insert the newly created CalendarData (below)
  1725. CalendarData? calendarData = _calendars[calendarIndex];
  1726. // Make sure that calendar has data
  1727. if (calendarData == null)
  1728. {
  1729. Debug.Assert(_sWindowsName != null, "[CultureData.GetCalendar] Expected _sWindowsName to be populated by already");
  1730. calendarData = new CalendarData(_sWindowsName, calendarId, UseUserOverride);
  1731. _calendars[calendarIndex] = calendarData;
  1732. }
  1733. return calendarData;
  1734. }
  1735. internal bool IsRightToLeft
  1736. {
  1737. get
  1738. {
  1739. // Returns one of the following 4 reading layout values:
  1740. // 0 - Left to right (eg en-US)
  1741. // 1 - Right to left (eg arabic locales)
  1742. // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  1743. // 3 - Vertical top to bottom with columns proceeding to the right
  1744. return ReadingLayout == 1;
  1745. }
  1746. }
  1747. /// <summary>
  1748. /// Returns one of the following 4 reading layout values:
  1749. /// 0 - Left to right (eg en-US)
  1750. /// 1 - Right to left (eg arabic locales)
  1751. /// 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  1752. /// 3 - Vertical top to bottom with columns proceeding to the right
  1753. /// </summary>
  1754. private int ReadingLayout
  1755. {
  1756. get
  1757. {
  1758. if (_iReadingLayout == undef)
  1759. {
  1760. Debug.Assert(_sRealName != null, "[CultureData.IsRightToLeft] Expected _sRealName to be populated by already");
  1761. _iReadingLayout = GetLocaleInfo(LocaleNumberData.ReadingLayout);
  1762. }
  1763. return (_iReadingLayout);
  1764. }
  1765. }
  1766. /// <summary>
  1767. /// // Text info name to use for text information
  1768. /// The TextInfo name never includes that alternate sort and is always specific
  1769. /// For customs, it uses the SortLocale (since the textinfo is not exposed in Win7)
  1770. /// en -> en-US
  1771. /// en-US -> en-US
  1772. /// fj (custom neutral) -> en-US (assuming that en-US is the sort locale for fj)
  1773. /// fj_FJ (custom specific) -> en-US (assuming that en-US is the sort locale for fj-FJ)
  1774. /// es-ES_tradnl -> es-ES
  1775. /// </summary>
  1776. internal string TextInfoName
  1777. {
  1778. get
  1779. {
  1780. // Note: Custom cultures might point at another culture's textinfo, however windows knows how
  1781. // to redirect it to the desired textinfo culture, so this is OK.
  1782. Debug.Assert(_sRealName != null, "[CultureData.TextInfoName] Expected _sRealName to be populated by already");
  1783. return _sRealName;
  1784. }
  1785. }
  1786. /// <summary>
  1787. /// Compare info name (including sorting key) to use if custom
  1788. /// </summary>
  1789. internal string SortName
  1790. {
  1791. get
  1792. {
  1793. Debug.Assert(_sRealName != null, "[CultureData.SortName] Expected _sRealName to be populated by already");
  1794. return _sRealName;
  1795. }
  1796. }
  1797. internal bool IsSupplementalCustomCulture => IsCustomCultureId(LCID);
  1798. /// <summary>
  1799. /// Default ansi code page ID (ACP)
  1800. /// </summary>
  1801. internal int ANSICodePage
  1802. {
  1803. get
  1804. {
  1805. if (_iDefaultAnsiCodePage == undef)
  1806. {
  1807. _iDefaultAnsiCodePage = GetAnsiCodePage(_sRealName!);
  1808. }
  1809. return _iDefaultAnsiCodePage;
  1810. }
  1811. }
  1812. /// <summary>
  1813. /// Default oem code page ID (OCP or OEM).
  1814. /// </summary>
  1815. internal int OEMCodePage
  1816. {
  1817. get
  1818. {
  1819. if (_iDefaultOemCodePage == undef)
  1820. {
  1821. _iDefaultOemCodePage = GetOemCodePage(_sRealName!);
  1822. }
  1823. return _iDefaultOemCodePage;
  1824. }
  1825. }
  1826. /// <summary>
  1827. /// Default macintosh code page.
  1828. /// </summary>
  1829. internal int MacCodePage
  1830. {
  1831. get
  1832. {
  1833. if (_iDefaultMacCodePage == undef)
  1834. {
  1835. _iDefaultMacCodePage = GetMacCodePage(_sRealName!);
  1836. }
  1837. return _iDefaultMacCodePage;
  1838. }
  1839. }
  1840. /// <summary>
  1841. /// Default EBCDIC code page.
  1842. /// </summary>
  1843. internal int EBCDICCodePage
  1844. {
  1845. get
  1846. {
  1847. if (_iDefaultEbcdicCodePage == undef)
  1848. {
  1849. _iDefaultEbcdicCodePage = GetEbcdicCodePage(_sRealName!);
  1850. }
  1851. return _iDefaultEbcdicCodePage;
  1852. }
  1853. }
  1854. internal int LCID
  1855. {
  1856. get
  1857. {
  1858. if (_iLanguage == 0)
  1859. {
  1860. Debug.Assert(_sRealName != null, "[CultureData.LCID] Expected this.sRealName to be populated already");
  1861. _iLanguage = LocaleNameToLCID(_sRealName);
  1862. }
  1863. return _iLanguage;
  1864. }
  1865. }
  1866. internal bool IsNeutralCulture
  1867. {
  1868. get
  1869. {
  1870. // InitCultureData told us if we're neutral or not
  1871. return _bNeutral;
  1872. }
  1873. }
  1874. internal bool IsInvariantCulture
  1875. {
  1876. get
  1877. {
  1878. return string.IsNullOrEmpty(Name);
  1879. }
  1880. }
  1881. /// <summary>
  1882. /// Get an instance of our default calendar
  1883. /// </summary>
  1884. internal Calendar DefaultCalendar
  1885. {
  1886. get
  1887. {
  1888. if (GlobalizationMode.Invariant)
  1889. {
  1890. return CultureInfo.GetCalendarInstance(CalendarIds[0]);
  1891. }
  1892. CalendarId defaultCalId = (CalendarId)GetLocaleInfo(LocaleNumberData.CalendarType);
  1893. if (defaultCalId == 0)
  1894. {
  1895. defaultCalId = CalendarIds[0];
  1896. }
  1897. return CultureInfo.GetCalendarInstance(defaultCalId);
  1898. }
  1899. }
  1900. /// <summary>
  1901. /// All of our era names
  1902. /// </summary>
  1903. internal string[] EraNames(CalendarId calendarId)
  1904. {
  1905. Debug.Assert(calendarId > 0, "[CultureData.saEraNames] Expected Calendar.ID > 0");
  1906. return GetCalendar(calendarId).saEraNames;
  1907. }
  1908. internal string[] AbbrevEraNames(CalendarId calendarId)
  1909. {
  1910. Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
  1911. return GetCalendar(calendarId).saAbbrevEraNames;
  1912. }
  1913. internal string[] AbbreviatedEnglishEraNames(CalendarId calendarId)
  1914. {
  1915. Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
  1916. return GetCalendar(calendarId).saAbbrevEnglishEraNames;
  1917. }
  1918. /// <summary>
  1919. /// Time separator (derived from time format)
  1920. /// </summary>
  1921. internal string TimeSeparator
  1922. {
  1923. get
  1924. {
  1925. if (_sTimeSeparator == null)
  1926. {
  1927. string? longTimeFormat = GetTimeFormatString();
  1928. if (string.IsNullOrEmpty(longTimeFormat))
  1929. {
  1930. longTimeFormat = LongTimes[0];
  1931. }
  1932. // Compute STIME from time format
  1933. _sTimeSeparator = GetTimeSeparator(longTimeFormat);
  1934. }
  1935. return _sTimeSeparator;
  1936. }
  1937. }
  1938. /// <summary>
  1939. /// Date separator (derived from short date format)
  1940. /// </summary>
  1941. internal string DateSeparator(CalendarId calendarId)
  1942. {
  1943. if (calendarId == CalendarId.JAPAN && !LocalAppContextSwitches.EnforceLegacyJapaneseDateParsing)
  1944. {
  1945. // The date separator is derived from the default short date pattern. So far this pattern is using
  1946. // '/' as date separator when using the Japanese calendar which make the formatting and parsing work fine.
  1947. // changing the default pattern is likely will happen in the near future which can easily break formatting
  1948. // and parsing.
  1949. // We are forcing here the date separator to '/' to ensure the parsing is not going to break when changing
  1950. // the default short date pattern. The application still can override this in the code by DateTimeFormatInfo.DateSeparartor.
  1951. return "/";
  1952. }
  1953. return GetDateSeparator(ShortDates(calendarId)[0]);
  1954. }
  1955. /// <summary>
  1956. /// Unescape a NLS style quote string
  1957. ///
  1958. /// This removes single quotes:
  1959. /// 'fred' -> fred
  1960. /// 'fred -> fred
  1961. /// fred' -> fred
  1962. /// fred's -> freds
  1963. ///
  1964. /// This removes the first \ of escaped characters:
  1965. /// fred\'s -> fred's
  1966. /// a\\b -> a\b
  1967. /// a\b -> ab
  1968. ///
  1969. /// We don't build the stringbuilder unless we find a ' or a \. If we find a ' or a \, we
  1970. /// always build a stringbuilder because we need to remove the ' or \.
  1971. /// </summary>
  1972. private static string UnescapeNlsString(string str, int start, int end)
  1973. {
  1974. Debug.Assert(str != null);
  1975. Debug.Assert(start >= 0);
  1976. Debug.Assert(end >= 0);
  1977. StringBuilder? result = null;
  1978. for (int i = start; i < str.Length && i <= end; i++)
  1979. {
  1980. switch (str[i])
  1981. {
  1982. case '\'':
  1983. if (result == null)
  1984. {
  1985. result = new StringBuilder(str, start, i - start, str.Length);
  1986. }
  1987. break;
  1988. case '\\':
  1989. if (result == null)
  1990. {
  1991. result = new StringBuilder(str, start, i - start, str.Length);
  1992. }
  1993. ++i;
  1994. if (i < str.Length)
  1995. {
  1996. result.Append(str[i]);
  1997. }
  1998. break;
  1999. default:
  2000. if (result != null)
  2001. {
  2002. result.Append(str[i]);
  2003. }
  2004. break;
  2005. }
  2006. }
  2007. if (result == null)
  2008. {
  2009. return str.Substring(start, end - start + 1);
  2010. }
  2011. return result.ToString();
  2012. }
  2013. /// <summary>
  2014. /// Time format separator (ie: : in 12:39:00)
  2015. /// We calculate this from the provided time format
  2016. /// </summary>
  2017. private static string GetTimeSeparator(string format)
  2018. {
  2019. // Find the time separator so that we can pretend we know TimeSeparator.
  2020. return GetSeparator(format, "Hhms");
  2021. }
  2022. /// <summary>
  2023. /// Date format separator (ie: / in 9/1/03)
  2024. /// We calculate this from the provided short date
  2025. /// </summary>
  2026. private static string GetDateSeparator(string format)
  2027. {
  2028. // Find the date separator so that we can pretend we know DateSeparator.
  2029. return GetSeparator(format, "dyM");
  2030. }
  2031. private static string GetSeparator(string format, string timeParts)
  2032. {
  2033. int index = IndexOfTimePart(format, 0, timeParts);
  2034. if (index != -1)
  2035. {
  2036. // Found a time part, find out when it changes
  2037. char cTimePart = format[index];
  2038. do
  2039. {
  2040. index++;
  2041. } while (index < format.Length && format[index] == cTimePart);
  2042. int separatorStart = index;
  2043. // Now we need to find the end of the separator
  2044. if (separatorStart < format.Length)
  2045. {
  2046. int separatorEnd = IndexOfTimePart(format, separatorStart, timeParts);
  2047. if (separatorEnd != -1)
  2048. {
  2049. // From [separatorStart, count) is our string, except we need to unescape
  2050. return UnescapeNlsString(format, separatorStart, separatorEnd - 1);
  2051. }
  2052. }
  2053. }
  2054. return string.Empty;
  2055. }
  2056. private static int IndexOfTimePart(string format, int startIndex, string timeParts)
  2057. {
  2058. Debug.Assert(startIndex >= 0, "startIndex cannot be negative");
  2059. Debug.Assert(timeParts.IndexOfAny(new char[] { '\'', '\\' }) == -1, "timeParts cannot include quote characters");
  2060. bool inQuote = false;
  2061. for (int i = startIndex; i < format.Length; ++i)
  2062. {
  2063. // See if we have a time Part
  2064. if (!inQuote && timeParts.Contains(format[i]))
  2065. {
  2066. return i;
  2067. }
  2068. switch (format[i])
  2069. {
  2070. case '\\':
  2071. if (i + 1 < format.Length)
  2072. {
  2073. ++i;
  2074. switch (format[i])
  2075. {
  2076. case '\'':
  2077. case '\\':
  2078. break;
  2079. default:
  2080. --i; //backup since we will move over this next
  2081. break;
  2082. }
  2083. }
  2084. break;
  2085. case '\'':
  2086. inQuote = !inQuote;
  2087. break;
  2088. }
  2089. }
  2090. return -1;
  2091. }
  2092. internal static bool IsCustomCultureId(int cultureId)
  2093. {
  2094. return cultureId == CultureInfo.LOCALE_CUSTOM_DEFAULT || cultureId == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
  2095. }
  2096. internal void GetNFIValues(NumberFormatInfo nfi)
  2097. {
  2098. if (GlobalizationMode.Invariant || IsInvariantCulture)
  2099. {
  2100. nfi._positiveSign = _sPositiveSign!;
  2101. nfi._negativeSign = _sNegativeSign!;
  2102. nfi._numberGroupSeparator = _sThousandSeparator!;
  2103. nfi._numberDecimalSeparator = _sDecimalSeparator!;
  2104. nfi._numberDecimalDigits = _iDigits;
  2105. nfi._numberNegativePattern = _iNegativeNumber;
  2106. nfi._currencySymbol = _sCurrency!;
  2107. nfi._currencyGroupSeparator = _sMonetaryThousand!;
  2108. nfi._currencyDecimalSeparator = _sMonetaryDecimal!;
  2109. nfi._currencyDecimalDigits = _iCurrencyDigits;
  2110. nfi._currencyNegativePattern = _iNegativeCurrency;
  2111. nfi._currencyPositivePattern = _iCurrency;
  2112. }
  2113. else
  2114. {
  2115. Debug.Assert(_sWindowsName != null, "[CultureData.GetNFIValues] Expected _sWindowsName to be populated by already");
  2116. // String values
  2117. nfi._positiveSign = GetLocaleInfo(LocaleStringData.PositiveSign);
  2118. nfi._negativeSign = GetLocaleInfo(LocaleStringData.NegativeSign);
  2119. nfi._numberDecimalSeparator = GetLocaleInfo(LocaleStringData.DecimalSeparator);
  2120. nfi._numberGroupSeparator = GetLocaleInfo(LocaleStringData.ThousandSeparator);
  2121. nfi._currencyGroupSeparator = GetLocaleInfo(LocaleStringData.MonetaryThousandSeparator);
  2122. nfi._currencyDecimalSeparator = GetLocaleInfo(LocaleStringData.MonetaryDecimalSeparator);
  2123. nfi._currencySymbol = GetLocaleInfo(LocaleStringData.MonetarySymbol);
  2124. // Numeric values
  2125. nfi._numberDecimalDigits = GetLocaleInfo(LocaleNumberData.FractionalDigitsCount);
  2126. nfi._currencyDecimalDigits = GetLocaleInfo(LocaleNumberData.MonetaryFractionalDigitsCount);
  2127. nfi._currencyPositivePattern = GetLocaleInfo(LocaleNumberData.PositiveMonetaryNumberFormat);
  2128. nfi._currencyNegativePattern = GetLocaleInfo(LocaleNumberData.NegativeMonetaryNumberFormat);
  2129. nfi._numberNegativePattern = GetLocaleInfo(LocaleNumberData.NegativeNumberFormat);
  2130. // LOCALE_SNATIVEDIGITS (array of 10 single character strings).
  2131. string digits = GetLocaleInfo(LocaleStringData.Digits);
  2132. nfi._nativeDigits = new string[10];
  2133. for (int i = 0; i < nfi._nativeDigits.Length; i++)
  2134. {
  2135. nfi._nativeDigits[i] = char.ToString(digits[i]);
  2136. }
  2137. Debug.Assert(_sRealName != null);
  2138. nfi._digitSubstitution = GetDigitSubstitution(_sRealName);
  2139. }
  2140. // Gather additional data
  2141. nfi._numberGroupSizes = NumberGroupSizes;
  2142. nfi._currencyGroupSizes = CurrencyGroupSizes;
  2143. // prefer the cached value since these do not have user overrides
  2144. nfi._percentNegativePattern = PercentNegativePattern;
  2145. nfi._percentPositivePattern = PercentPositivePattern;
  2146. nfi._percentSymbol = PercentSymbol;
  2147. nfi._perMilleSymbol = PerMilleSymbol;
  2148. nfi._negativeInfinitySymbol = NegativeInfinitySymbol;
  2149. nfi._positiveInfinitySymbol = PositiveInfinitySymbol;
  2150. nfi._nanSymbol = NaNSymbol;
  2151. // We don't have percent values, so use the number values
  2152. nfi._percentDecimalDigits = nfi._numberDecimalDigits;
  2153. nfi._percentDecimalSeparator = nfi._numberDecimalSeparator;
  2154. nfi._percentGroupSizes = nfi._numberGroupSizes;
  2155. nfi._percentGroupSeparator = nfi._numberGroupSeparator;
  2156. // Clean up a few odd values
  2157. // Windows usually returns an empty positive sign, but we like it to be "+"
  2158. if (nfi._positiveSign == null || nfi._positiveSign.Length == 0)
  2159. {
  2160. nfi._positiveSign = "+";
  2161. }
  2162. // Special case for Italian. The currency decimal separator in the control panel is the empty string. When the user
  2163. // specifies C4 as the currency format, this results in the number apparently getting multiplied by 10000 because the
  2164. // decimal point doesn't show up. We'll just hack this here because our default currency format will never use nfi.
  2165. if (nfi._currencyDecimalSeparator == null || nfi._currencyDecimalSeparator.Length == 0)
  2166. {
  2167. nfi._currencyDecimalSeparator = nfi._numberDecimalSeparator;
  2168. }
  2169. }
  2170. /// <remarks>
  2171. /// This is ONLY used for caching names and shouldn't be used for anything else
  2172. /// </remarks>
  2173. internal static string AnsiToLower(string testString) => TextInfo.ToLowerAsciiInvariant(testString);
  2174. /// <remarks>
  2175. /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
  2176. /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
  2177. /// </remarks>
  2178. private enum LocaleStringData : uint
  2179. {
  2180. /// <summary>localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME)</summary>
  2181. LocalizedDisplayName = 0x00000002,
  2182. /// <summary>Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME)</summary>
  2183. EnglishDisplayName = 0x00000072,
  2184. /// <summary>Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME)</summary>
  2185. NativeDisplayName = 0x00000073,
  2186. /// <summary>Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME)</summary>
  2187. LocalizedLanguageName = 0x0000006f,
  2188. /// <summary>English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME)</summary>
  2189. EnglishLanguageName = 0x00001001,
  2190. /// <summary>native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME)</summary>
  2191. NativeLanguageName = 0x00000004,
  2192. /// <summary>localized name of country, eg "Germany" in UI language (corresponds to LOCALE_SLOCALIZEDCOUNTRYNAME)</summary>
  2193. LocalizedCountryName = 0x00000006,
  2194. /// <summary>English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME)</summary>
  2195. EnglishCountryName = 0x00001002,
  2196. /// <summary>native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME)</summary>
  2197. NativeCountryName = 0x00000008,
  2198. /// <summary>abbreviated language name (corresponds to LOCALE_SABBREVLANGNAME)</summary>
  2199. AbbreviatedWindowsLanguageName = 0x00000003,
  2200. /// <summary>list item separator (corresponds to LOCALE_SLIST)</summary>
  2201. ListSeparator = 0x0000000C,
  2202. /// <summary>decimal separator (corresponds to LOCALE_SDECIMAL)</summary>
  2203. DecimalSeparator = 0x0000000E,
  2204. /// <summary>thousand separator (corresponds to LOCALE_STHOUSAND)</summary>
  2205. ThousandSeparator = 0x0000000F,
  2206. /// <summary>digit grouping (corresponds to LOCALE_SGROUPING)</summary>
  2207. Digits = 0x00000013,
  2208. /// <summary>local monetary symbol (corresponds to LOCALE_SCURRENCY)</summary>
  2209. MonetarySymbol = 0x00000014,
  2210. /// <summary>English currency name (corresponds to LOCALE_SENGCURRNAME)</summary>
  2211. CurrencyEnglishName = 0x00001007,
  2212. /// <summary>Native currency name (corresponds to LOCALE_SNATIVECURRNAME)</summary>
  2213. CurrencyNativeName = 0x00001008,
  2214. /// <summary>uintl monetary symbol (corresponds to LOCALE_SINTLSYMBOL)</summary>
  2215. Iso4217MonetarySymbol = 0x00000015,
  2216. /// <summary>monetary decimal separator (corresponds to LOCALE_SMONDECIMALSEP)</summary>
  2217. MonetaryDecimalSeparator = 0x00000016,
  2218. /// <summary>monetary thousand separator (corresponds to LOCALE_SMONTHOUSANDSEP)</summary>
  2219. MonetaryThousandSeparator = 0x00000017,
  2220. /// <summary>AM designator (corresponds to LOCALE_S1159)</summary>
  2221. AMDesignator = 0x00000028,
  2222. /// <summary>PM designator (corresponds to LOCALE_S2359)</summary>
  2223. PMDesignator = 0x00000029,
  2224. /// <summary>positive sign (corresponds to LOCALE_SPOSITIVESIGN)</summary>
  2225. PositiveSign = 0x00000050,
  2226. /// <summary>negative sign (corresponds to LOCALE_SNEGATIVESIGN)</summary>
  2227. NegativeSign = 0x00000051,
  2228. /// <summary>ISO abbreviated language name (corresponds to LOCALE_SISO639LANGNAME)</summary>
  2229. Iso639LanguageTwoLetterName = 0x00000059,
  2230. /// <summary>ISO abbreviated country name (corresponds to LOCALE_SISO639LANGNAME2)</summary>
  2231. Iso639LanguageThreeLetterName = 0x00000067,
  2232. /// <summary>ISO abbreviated language name (corresponds to LOCALE_SISO639LANGNAME)</summary>
  2233. Iso639LanguageName = 0x00000059,
  2234. /// <summary>ISO abbreviated country name (corresponds to LOCALE_SISO3166CTRYNAME)</summary>
  2235. Iso3166CountryName = 0x0000005A,
  2236. /// <summary>3 letter ISO country code (corresponds to LOCALE_SISO3166CTRYNAME2)</summary>
  2237. Iso3166CountryName2 = 0x00000068, // 3 character ISO country name
  2238. /// <summary>Not a Number (corresponds to LOCALE_SNAN)</summary>
  2239. NaNSymbol = 0x00000069,
  2240. /// <summary>+ Infinity (corresponds to LOCALE_SPOSINFINITY)</summary>
  2241. PositiveInfinitySymbol = 0x0000006a,
  2242. /// <summary>- Infinity (corresponds to LOCALE_SNEGINFINITY)</summary>
  2243. NegativeInfinitySymbol = 0x0000006b,
  2244. /// <summary>Fallback name for resources (corresponds to LOCALE_SPARENT)</summary>
  2245. ParentName = 0x0000006d,
  2246. /// <summary>Fallback name for within the console (corresponds to LOCALE_SCONSOLEFALLBACKNAME)</summary>
  2247. ConsoleFallbackName = 0x0000006e,
  2248. /// <summary>Returns the percent symbol (corresponds to LOCALE_SPERCENT)</summary>
  2249. PercentSymbol = 0x00000076,
  2250. /// <summary>Returns the permille (U+2030) symbol (corresponds to LOCALE_SPERMILLE)</summary>
  2251. PerMilleSymbol = 0x00000077
  2252. }
  2253. /// <remarks>
  2254. /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
  2255. /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
  2256. /// </remarks>
  2257. private enum LocaleGroupingData : uint
  2258. {
  2259. /// <summary>digit grouping (corresponds to LOCALE_SGROUPING)</summary>
  2260. Digit = 0x00000010,
  2261. /// <summary>monetary grouping (corresponds to LOCALE_SMONGROUPING)</summary>
  2262. Monetary = 0x00000018,
  2263. }
  2264. /// <remarks>
  2265. /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
  2266. /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
  2267. /// </remarks>
  2268. private enum LocaleNumberData : uint
  2269. {
  2270. /// <summary>language id (corresponds to LOCALE_ILANGUAGE)</summary>
  2271. LanguageId = 0x00000001,
  2272. /// <summary>geographical location id, (corresponds to LOCALE_IGEOID)</summary>
  2273. GeoId = 0x0000005B,
  2274. /// <summary>0 = context, 1 = none, 2 = national (corresponds to LOCALE_IDIGITSUBSTITUTION)</summary>
  2275. DigitSubstitution = 0x00001014,
  2276. /// <summary>0 = metric, 1 = US (corresponds to LOCALE_IMEASURE)</summary>
  2277. MeasurementSystem = 0x0000000D,
  2278. /// <summary>number of fractional digits (corresponds to LOCALE_IDIGITS)</summary>
  2279. FractionalDigitsCount = 0x00000011,
  2280. /// <summary>negative number mode (corresponds to LOCALE_INEGNUMBER)</summary>
  2281. NegativeNumberFormat = 0x00001010,
  2282. /// <summary># local monetary digits (corresponds to LOCALE_ICURRDIGITS)</summary>
  2283. MonetaryFractionalDigitsCount = 0x00000019,
  2284. /// <summary>positive currency mode (corresponds to LOCALE_ICURRENCY)</summary>
  2285. PositiveMonetaryNumberFormat = 0x0000001B,
  2286. /// <summary>negative currency mode (corresponds to LOCALE_INEGCURR)</summary>
  2287. NegativeMonetaryNumberFormat = 0x0000001C,
  2288. /// <summary>type of calendar specifier (corresponds to LOCALE_ICALENDARTYPE)</summary>
  2289. CalendarType = 0x00001009,
  2290. /// <summary>first day of week specifier (corresponds to LOCALE_IFIRSTDAYOFWEEK)</summary>
  2291. FirstDayOfWeek = 0x0000100C,
  2292. /// <summary>first week of year specifier (corresponds to LOCALE_IFIRSTWEEKOFYEAR)</summary>
  2293. FirstWeekOfYear = 0x0000100D,
  2294. /// <summary>
  2295. /// Returns one of the following 4 reading layout values:
  2296. /// 0 - Left to right (eg en-US)
  2297. /// 1 - Right to left (eg arabic locales)
  2298. /// 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  2299. /// 3 - Vertical top to bottom with columns proceeding to the right
  2300. /// (corresponds to LOCALE_IREADINGLAYOUT)
  2301. /// </summary>
  2302. ReadingLayout = 0x00000070,
  2303. /// <summary>Returns 0-11 for the negative percent format (corresponds to LOCALE_INEGATIVEPERCENT)</summary>
  2304. NegativePercentFormat = 0x00000074,
  2305. /// <summary>Returns 0-3 for the positive percent format (corresponds to LOCALE_IPOSITIVEPERCENT)</summary>
  2306. PositivePercentFormat = 0x00000075,
  2307. /// <summary>default ansi code page (corresponds to LOCALE_IDEFAULTCODEPAGE)</summary>
  2308. OemCodePage = 0x0000000B,
  2309. /// <summary>default ansi code page (corresponds to LOCALE_IDEFAULTANSICODEPAGE)</summary>
  2310. AnsiCodePage = 0x00001004,
  2311. /// <summary>default mac code page (corresponds to LOCALE_IDEFAULTMACCODEPAGE)</summary>
  2312. MacCodePage = 0x00001011,
  2313. /// <summary>default ebcdic code page (corresponds to LOCALE_IDEFAULTEBCDICCODEPAGE)</summary>
  2314. EbcdicCodePage = 0x00001012,
  2315. }
  2316. }
  2317. }