CultureData.cs 101 KB

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