CultureData.cs 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  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 =
  855. this.SENGLISHLANGUAGE.Substring(0, _sEnglishLanguage.Length - 1) +
  856. ", " + this.SENGCOUNTRY + ")";
  857. }
  858. else
  859. {
  860. // "English" + "United States" -> "English (United States)"
  861. _sEnglishDisplayName = this.SENGLISHLANGUAGE + " (" + this.SENGCOUNTRY + ")";
  862. }
  863. }
  864. }
  865. }
  866. return _sEnglishDisplayName;
  867. }
  868. }
  869. // Native pretty name for this locale (ie: Deutsch (Deutschland))
  870. internal string SNATIVEDISPLAYNAME
  871. {
  872. get
  873. {
  874. if (_sNativeDisplayName == null)
  875. {
  876. // If its neutral use the language name
  877. if (this.IsNeutralCulture)
  878. {
  879. _sNativeDisplayName = this.SNATIVELANGUAGE;
  880. // differentiate the legacy display names
  881. switch (_sName)
  882. {
  883. case "zh-CHS":
  884. _sNativeDisplayName += " \u65E7\u7248";
  885. break;
  886. case "zh-CHT":
  887. _sNativeDisplayName += " \u820A\u7248";
  888. break;
  889. }
  890. }
  891. else
  892. {
  893. _sNativeDisplayName = GetLocaleInfo(LocaleStringData.NativeDisplayName);
  894. // if it isn't found build one:
  895. if (string.IsNullOrEmpty(_sNativeDisplayName))
  896. {
  897. // These should primarily be "Deutsch (Deutschland)" type names
  898. _sNativeDisplayName = this.SNATIVELANGUAGE + " (" + this.SNATIVECOUNTRY + ")";
  899. }
  900. }
  901. }
  902. return _sNativeDisplayName;
  903. }
  904. }
  905. // The culture name to be used in CultureInfo.CreateSpecificCulture()
  906. internal string SSPECIFICCULTURE
  907. {
  908. get
  909. {
  910. // This got populated during the culture initialization
  911. Debug.Assert(_sSpecificCulture != null, "[CultureData.SSPECIFICCULTURE] Expected this.sSpecificCulture to be populated by culture data initialization already");
  912. return _sSpecificCulture;
  913. }
  914. }
  915. /////////////
  916. // Language //
  917. /////////////
  918. // iso 639 language name, ie: en
  919. internal string SISO639LANGNAME
  920. {
  921. get
  922. {
  923. if (_sISO639Language == null)
  924. {
  925. _sISO639Language = GetLocaleInfo(LocaleStringData.Iso639LanguageTwoLetterName);
  926. }
  927. return _sISO639Language;
  928. }
  929. }
  930. // iso 639 language name, ie: eng
  931. internal string SISO639LANGNAME2
  932. {
  933. get
  934. {
  935. if (_sISO639Language2 == null)
  936. {
  937. _sISO639Language2 = GetLocaleInfo(LocaleStringData.Iso639LanguageThreeLetterName);
  938. }
  939. return _sISO639Language2;
  940. }
  941. }
  942. // abbreviated windows language name (ie: enu) (non-standard, avoid this)
  943. internal string SABBREVLANGNAME
  944. {
  945. get
  946. {
  947. if (_sAbbrevLang == null)
  948. {
  949. _sAbbrevLang = GetThreeLetterWindowsLanguageName(_sRealName);
  950. }
  951. return _sAbbrevLang;
  952. }
  953. }
  954. // Localized name for this language (Windows Only) ie: Inglis
  955. // This is only valid for Windows 8 and higher neutrals:
  956. internal string SLOCALIZEDLANGUAGE
  957. {
  958. get
  959. {
  960. if (_sLocalizedLanguage == null)
  961. {
  962. // Usually the UI culture shouldn't be different than what we got from WinRT except
  963. // if DefaultThreadCurrentUICulture was set
  964. CultureInfo ci;
  965. if (CultureInfo.DefaultThreadCurrentUICulture != null &&
  966. ((ci = GetUserDefaultCulture()) != null) &&
  967. !CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
  968. {
  969. _sLocalizedLanguage = SNATIVELANGUAGE;
  970. }
  971. else
  972. {
  973. _sLocalizedLanguage = GetLocaleInfo(LocaleStringData.LocalizedLanguageName);
  974. }
  975. }
  976. return _sLocalizedLanguage;
  977. }
  978. }
  979. // English name for this language (Windows Only) ie: German
  980. internal string SENGLISHLANGUAGE
  981. {
  982. get
  983. {
  984. if (_sEnglishLanguage == null)
  985. {
  986. _sEnglishLanguage = GetLocaleInfo(LocaleStringData.EnglishLanguageName);
  987. }
  988. return _sEnglishLanguage;
  989. }
  990. }
  991. // Native name of this language (Windows Only) ie: Deutsch
  992. internal string SNATIVELANGUAGE
  993. {
  994. get
  995. {
  996. if (_sNativeLanguage == null)
  997. {
  998. _sNativeLanguage = GetLocaleInfo(LocaleStringData.NativeLanguageName);
  999. }
  1000. return _sNativeLanguage;
  1001. }
  1002. }
  1003. ///////////
  1004. // Region //
  1005. ///////////
  1006. // region name (eg US)
  1007. internal string SREGIONNAME
  1008. {
  1009. get
  1010. {
  1011. if (_sRegionName == null)
  1012. {
  1013. _sRegionName = GetLocaleInfo(LocaleStringData.Iso3166CountryName);
  1014. }
  1015. return _sRegionName;
  1016. }
  1017. }
  1018. internal int IGEOID
  1019. {
  1020. get
  1021. {
  1022. if (_iGeoId == undef)
  1023. {
  1024. _iGeoId = GetGeoId(_sRealName);
  1025. }
  1026. return _iGeoId;
  1027. }
  1028. }
  1029. // localized name for the country
  1030. internal string SLOCALIZEDCOUNTRY
  1031. {
  1032. get
  1033. {
  1034. if (_sLocalizedCountry == null)
  1035. {
  1036. try
  1037. {
  1038. _sLocalizedCountry = GetRegionDisplayName(SISO3166CTRYNAME);
  1039. }
  1040. catch (Exception)
  1041. {
  1042. // do nothing. we'll fallback
  1043. }
  1044. if (_sLocalizedCountry == null)
  1045. {
  1046. _sLocalizedCountry = SNATIVECOUNTRY;
  1047. }
  1048. }
  1049. return _sLocalizedCountry;
  1050. }
  1051. }
  1052. // english country name (RegionInfo) ie: Germany
  1053. internal string SENGCOUNTRY
  1054. {
  1055. get
  1056. {
  1057. if (_sEnglishCountry == null)
  1058. {
  1059. _sEnglishCountry = GetLocaleInfo(LocaleStringData.EnglishCountryName);
  1060. }
  1061. return _sEnglishCountry;
  1062. }
  1063. }
  1064. // native country name (RegionInfo) ie: Deutschland
  1065. internal string SNATIVECOUNTRY
  1066. {
  1067. get
  1068. {
  1069. if (_sNativeCountry == null)
  1070. {
  1071. _sNativeCountry = GetLocaleInfo(LocaleStringData.NativeCountryName);
  1072. }
  1073. return _sNativeCountry;
  1074. }
  1075. }
  1076. // ISO 3166 Country Name
  1077. internal string SISO3166CTRYNAME
  1078. {
  1079. get
  1080. {
  1081. if (_sISO3166CountryName == null)
  1082. {
  1083. _sISO3166CountryName = GetLocaleInfo(LocaleStringData.Iso3166CountryName);
  1084. }
  1085. return _sISO3166CountryName;
  1086. }
  1087. }
  1088. // 3 letter ISO 3166 country code
  1089. internal string SISO3166CTRYNAME2
  1090. {
  1091. get
  1092. {
  1093. if (_sISO3166CountryName2 == null)
  1094. {
  1095. _sISO3166CountryName2 = GetLocaleInfo(LocaleStringData.Iso3166CountryName2);
  1096. }
  1097. return _sISO3166CountryName2;
  1098. }
  1099. }
  1100. internal int IINPUTLANGUAGEHANDLE
  1101. {
  1102. get
  1103. {
  1104. if (_iInputLanguageHandle == undef)
  1105. {
  1106. if (IsSupplementalCustomCulture)
  1107. {
  1108. _iInputLanguageHandle = 0x0409;
  1109. }
  1110. else
  1111. {
  1112. // Input Language is same as LCID for built-in cultures
  1113. _iInputLanguageHandle = this.ILANGUAGE;
  1114. }
  1115. }
  1116. return _iInputLanguageHandle;
  1117. }
  1118. }
  1119. // Console fallback name (ie: locale to use for console apps for unicode-only locales)
  1120. internal string SCONSOLEFALLBACKNAME
  1121. {
  1122. get
  1123. {
  1124. if (_sConsoleFallbackName == null)
  1125. {
  1126. _sConsoleFallbackName = GetConsoleFallbackName(_sRealName);
  1127. }
  1128. return _sConsoleFallbackName;
  1129. }
  1130. }
  1131. // (user can override) grouping of digits
  1132. internal int[] WAGROUPING
  1133. {
  1134. get
  1135. {
  1136. if (_waGrouping == null)
  1137. {
  1138. _waGrouping = GetLocaleInfo(LocaleGroupingData.Digit);
  1139. }
  1140. return _waGrouping;
  1141. }
  1142. }
  1143. // internal string _sDecimalSeparator ; // (user can override) decimal separator
  1144. // internal string _sThousandSeparator ; // (user can override) thousands separator
  1145. // Not a Number
  1146. internal string SNAN
  1147. {
  1148. get
  1149. {
  1150. if (_sNaN == null)
  1151. {
  1152. _sNaN = GetLocaleInfo(LocaleStringData.NaNSymbol);
  1153. }
  1154. return _sNaN;
  1155. }
  1156. }
  1157. // + Infinity
  1158. internal string SPOSINFINITY
  1159. {
  1160. get
  1161. {
  1162. if (_sPositiveInfinity == null)
  1163. {
  1164. _sPositiveInfinity = GetLocaleInfo(LocaleStringData.PositiveInfinitySymbol);
  1165. }
  1166. return _sPositiveInfinity;
  1167. }
  1168. }
  1169. // - Infinity
  1170. internal string SNEGINFINITY
  1171. {
  1172. get
  1173. {
  1174. if (_sNegativeInfinity == null)
  1175. {
  1176. _sNegativeInfinity = GetLocaleInfo(LocaleStringData.NegativeInfinitySymbol);
  1177. }
  1178. return _sNegativeInfinity;
  1179. }
  1180. }
  1181. ////////////
  1182. // Percent //
  1183. ///////////
  1184. // Negative Percent (0-3)
  1185. internal int INEGATIVEPERCENT
  1186. {
  1187. get
  1188. {
  1189. if (_iNegativePercent == undef)
  1190. {
  1191. // Note that <= Windows Vista this is synthesized by native code
  1192. _iNegativePercent = GetLocaleInfo(LocaleNumberData.NegativePercentFormat);
  1193. }
  1194. return _iNegativePercent;
  1195. }
  1196. }
  1197. // Positive Percent (0-11)
  1198. internal int IPOSITIVEPERCENT
  1199. {
  1200. get
  1201. {
  1202. if (_iPositivePercent == undef)
  1203. {
  1204. // Note that <= Windows Vista this is synthesized by native code
  1205. _iPositivePercent = GetLocaleInfo(LocaleNumberData.PositivePercentFormat);
  1206. }
  1207. return _iPositivePercent;
  1208. }
  1209. }
  1210. // Percent (%) symbol
  1211. internal string SPERCENT
  1212. {
  1213. get
  1214. {
  1215. if (_sPercent == null)
  1216. {
  1217. _sPercent = GetLocaleInfo(LocaleStringData.PercentSymbol);
  1218. }
  1219. return _sPercent;
  1220. }
  1221. }
  1222. // PerMille symbol
  1223. internal string SPERMILLE
  1224. {
  1225. get
  1226. {
  1227. if (_sPerMille == null)
  1228. {
  1229. _sPerMille = GetLocaleInfo(LocaleStringData.PerMilleSymbol);
  1230. }
  1231. return _sPerMille;
  1232. }
  1233. }
  1234. /////////////
  1235. // Currency //
  1236. /////////////
  1237. // (user can override) local monetary symbol, eg: $
  1238. internal string SCURRENCY
  1239. {
  1240. get
  1241. {
  1242. if (_sCurrency == null)
  1243. {
  1244. _sCurrency = GetLocaleInfo(LocaleStringData.MonetarySymbol);
  1245. }
  1246. return _sCurrency;
  1247. }
  1248. }
  1249. // international monetary symbol (RegionInfo), eg: USD
  1250. internal string SINTLSYMBOL
  1251. {
  1252. get
  1253. {
  1254. if (_sIntlMonetarySymbol == null)
  1255. {
  1256. _sIntlMonetarySymbol = GetLocaleInfo(LocaleStringData.Iso4217MonetarySymbol);
  1257. }
  1258. return _sIntlMonetarySymbol;
  1259. }
  1260. }
  1261. // English name for this currency (RegionInfo), eg: US Dollar
  1262. internal string SENGLISHCURRENCY
  1263. {
  1264. get
  1265. {
  1266. if (_sEnglishCurrency == null)
  1267. {
  1268. _sEnglishCurrency = GetLocaleInfo(LocaleStringData.CurrencyEnglishName);
  1269. }
  1270. return _sEnglishCurrency;
  1271. }
  1272. }
  1273. // Native name for this currency (RegionInfo), eg: Schweiz Frank
  1274. internal string SNATIVECURRENCY
  1275. {
  1276. get
  1277. {
  1278. if (_sNativeCurrency == null)
  1279. {
  1280. _sNativeCurrency = GetLocaleInfo(LocaleStringData.CurrencyNativeName);
  1281. }
  1282. return _sNativeCurrency;
  1283. }
  1284. }
  1285. // internal int iCurrencyDigits ; // (user can override) # local monetary fractional digits
  1286. // internal int iCurrency ; // (user can override) positive currency format
  1287. // internal int iNegativeCurrency ; // (user can override) negative currency format
  1288. // (user can override) monetary grouping of digits
  1289. internal int[] WAMONGROUPING
  1290. {
  1291. get
  1292. {
  1293. if (_waMonetaryGrouping == null)
  1294. {
  1295. _waMonetaryGrouping = GetLocaleInfo(LocaleGroupingData.Monetary);
  1296. }
  1297. return _waMonetaryGrouping;
  1298. }
  1299. }
  1300. // (user can override) system of measurement 0=metric, 1=US (RegionInfo)
  1301. internal int IMEASURE
  1302. {
  1303. get
  1304. {
  1305. if (_iMeasure == undef)
  1306. {
  1307. _iMeasure = GetLocaleInfo(LocaleNumberData.MeasurementSystem);
  1308. }
  1309. return _iMeasure;
  1310. }
  1311. }
  1312. // (user can override) list Separator
  1313. internal string SLIST
  1314. {
  1315. get
  1316. {
  1317. if (_sListSeparator == null)
  1318. {
  1319. _sListSeparator = GetLocaleInfo(LocaleStringData.ListSeparator);
  1320. }
  1321. return _sListSeparator;
  1322. }
  1323. }
  1324. ////////////////////////////
  1325. // Calendar/Time (Gregorian) //
  1326. ////////////////////////////
  1327. // (user can override) AM designator
  1328. internal string SAM1159
  1329. {
  1330. get
  1331. {
  1332. if (_sAM1159 == null)
  1333. {
  1334. _sAM1159 = GetLocaleInfo(LocaleStringData.AMDesignator);
  1335. }
  1336. return _sAM1159;
  1337. }
  1338. }
  1339. // (user can override) PM designator
  1340. internal string SPM2359
  1341. {
  1342. get
  1343. {
  1344. if (_sPM2359 == null)
  1345. {
  1346. _sPM2359 = GetLocaleInfo(LocaleStringData.PMDesignator);
  1347. }
  1348. return _sPM2359;
  1349. }
  1350. }
  1351. // (user can override) time format
  1352. internal string[] LongTimes
  1353. {
  1354. get
  1355. {
  1356. if (_saLongTimes == null)
  1357. {
  1358. Debug.Assert(!GlobalizationMode.Invariant);
  1359. string[] longTimes = GetTimeFormats();
  1360. if (longTimes == null || longTimes.Length == 0)
  1361. {
  1362. _saLongTimes = Invariant._saLongTimes;
  1363. }
  1364. else
  1365. {
  1366. _saLongTimes = longTimes;
  1367. }
  1368. }
  1369. return _saLongTimes;
  1370. }
  1371. }
  1372. // short time format
  1373. // Short times (derived from long times format)
  1374. // TODO: NLS Arrowhead - On Windows 7 we should have short times so this isn't necessary
  1375. internal string[] ShortTimes
  1376. {
  1377. get
  1378. {
  1379. if (_saShortTimes == null)
  1380. {
  1381. Debug.Assert(!GlobalizationMode.Invariant);
  1382. // Try to get the short times from the OS/culture.dll
  1383. string[] shortTimes = null;
  1384. shortTimes = GetShortTimeFormats();
  1385. if (shortTimes == null || shortTimes.Length == 0)
  1386. {
  1387. //
  1388. // If we couldn't find short times, then compute them from long times
  1389. // (eg: CORECLR on < Win7 OS & fallback for missing culture.dll)
  1390. //
  1391. shortTimes = DeriveShortTimesFromLong();
  1392. }
  1393. /* The above logic doesn't make sense on Mac, since the OS can provide us a "short time pattern".
  1394. * currently this is the 4th element in the array returned by LongTimes. We'll add this to our array
  1395. * if it doesn't exist.
  1396. */
  1397. shortTimes = AdjustShortTimesForMac(shortTimes);
  1398. // Found short times, use them
  1399. _saShortTimes = shortTimes;
  1400. }
  1401. return _saShortTimes;
  1402. }
  1403. }
  1404. private string[] AdjustShortTimesForMac(string[] shortTimes)
  1405. {
  1406. return shortTimes;
  1407. }
  1408. private string[] DeriveShortTimesFromLong()
  1409. {
  1410. // Our logic is to look for h,H,m,s,t. If we find an s, then we check the string
  1411. // between it and the previous marker, if any. If its a short, unescaped separator,
  1412. // then we don't retain that part.
  1413. // We then check after the ss and remove anything before the next h,H,m,t...
  1414. string[] longTimes = LongTimes;
  1415. string[] shortTimes = new string[longTimes.Length];
  1416. for (int i = 0; i < longTimes.Length; i++)
  1417. {
  1418. shortTimes[i] = StripSecondsFromPattern(longTimes[i]);
  1419. }
  1420. return shortTimes;
  1421. }
  1422. private static string StripSecondsFromPattern(string time)
  1423. {
  1424. bool bEscape = false;
  1425. int iLastToken = -1;
  1426. // Find the seconds
  1427. for (int j = 0; j < time.Length; j++)
  1428. {
  1429. // Change escape mode?
  1430. if (time[j] == '\'')
  1431. {
  1432. // Continue
  1433. bEscape = !bEscape;
  1434. continue;
  1435. }
  1436. // See if there was a single \
  1437. if (time[j] == '\\')
  1438. {
  1439. // Skip next char
  1440. j++;
  1441. continue;
  1442. }
  1443. if (bEscape)
  1444. {
  1445. continue;
  1446. }
  1447. switch (time[j])
  1448. {
  1449. // Check for seconds
  1450. case 's':
  1451. // Found seconds, see if there was something unescaped and short between
  1452. // the last marker and the seconds. Windows says separator can be a
  1453. // maximum of three characters (without null)
  1454. // If 1st or last characters were ', then ignore it
  1455. if ((j - iLastToken) <= 4 && (j - iLastToken) > 1 &&
  1456. (time[iLastToken + 1] != '\'') &&
  1457. (time[j - 1] != '\''))
  1458. {
  1459. // There was something there we want to remember
  1460. if (iLastToken >= 0)
  1461. {
  1462. j = iLastToken + 1;
  1463. }
  1464. }
  1465. bool containsSpace;
  1466. int endIndex = GetIndexOfNextTokenAfterSeconds(time, j, out containsSpace);
  1467. string sep;
  1468. if (containsSpace)
  1469. {
  1470. sep = " ";
  1471. }
  1472. else
  1473. {
  1474. sep = "";
  1475. }
  1476. time = time.Substring(0, j) + sep + time.Substring(endIndex);
  1477. break;
  1478. case 'm':
  1479. case 'H':
  1480. case 'h':
  1481. iLastToken = j;
  1482. break;
  1483. }
  1484. }
  1485. return time;
  1486. }
  1487. private static int GetIndexOfNextTokenAfterSeconds(string time, int index, out bool containsSpace)
  1488. {
  1489. bool bEscape = false;
  1490. containsSpace = false;
  1491. for (; index < time.Length; index++)
  1492. {
  1493. switch (time[index])
  1494. {
  1495. case '\'':
  1496. bEscape = !bEscape;
  1497. continue;
  1498. case '\\':
  1499. index++;
  1500. if (time[index] == ' ')
  1501. {
  1502. containsSpace = true;
  1503. }
  1504. continue;
  1505. case ' ':
  1506. containsSpace = true;
  1507. break;
  1508. case 't':
  1509. case 'm':
  1510. case 'H':
  1511. case 'h':
  1512. if (bEscape)
  1513. {
  1514. continue;
  1515. }
  1516. return index;
  1517. }
  1518. }
  1519. containsSpace = false;
  1520. return index;
  1521. }
  1522. // (user can override) first day of week
  1523. internal int IFIRSTDAYOFWEEK
  1524. {
  1525. get
  1526. {
  1527. if (_iFirstDayOfWeek == undef)
  1528. {
  1529. _iFirstDayOfWeek = GetFirstDayOfWeek();
  1530. }
  1531. return _iFirstDayOfWeek;
  1532. }
  1533. }
  1534. // (user can override) first week of year
  1535. internal int IFIRSTWEEKOFYEAR
  1536. {
  1537. get
  1538. {
  1539. if (_iFirstWeekOfYear == undef)
  1540. {
  1541. _iFirstWeekOfYear = GetLocaleInfo(LocaleNumberData.FirstWeekOfYear);
  1542. }
  1543. return _iFirstWeekOfYear;
  1544. }
  1545. }
  1546. // (user can override default only) short date format
  1547. internal string[] ShortDates(CalendarId calendarId)
  1548. {
  1549. return GetCalendar(calendarId).saShortDates;
  1550. }
  1551. // (user can override default only) long date format
  1552. internal string[] LongDates(CalendarId calendarId)
  1553. {
  1554. return GetCalendar(calendarId).saLongDates;
  1555. }
  1556. // (user can override) date year/month format.
  1557. internal string[] YearMonths(CalendarId calendarId)
  1558. {
  1559. return GetCalendar(calendarId).saYearMonths;
  1560. }
  1561. // day names
  1562. internal string[] DayNames(CalendarId calendarId)
  1563. {
  1564. return GetCalendar(calendarId).saDayNames;
  1565. }
  1566. // abbreviated day names
  1567. internal string[] AbbreviatedDayNames(CalendarId calendarId)
  1568. {
  1569. // Get abbreviated day names for this calendar from the OS if necessary
  1570. return GetCalendar(calendarId).saAbbrevDayNames;
  1571. }
  1572. // The super short day names
  1573. internal string[] SuperShortDayNames(CalendarId calendarId)
  1574. {
  1575. return GetCalendar(calendarId).saSuperShortDayNames;
  1576. }
  1577. // month names
  1578. internal string[] MonthNames(CalendarId calendarId)
  1579. {
  1580. return GetCalendar(calendarId).saMonthNames;
  1581. }
  1582. // Genitive month names
  1583. internal string[] GenitiveMonthNames(CalendarId calendarId)
  1584. {
  1585. return GetCalendar(calendarId).saMonthGenitiveNames;
  1586. }
  1587. // month names
  1588. internal string[] AbbreviatedMonthNames(CalendarId calendarId)
  1589. {
  1590. return GetCalendar(calendarId).saAbbrevMonthNames;
  1591. }
  1592. // Genitive month names
  1593. internal string[] AbbreviatedGenitiveMonthNames(CalendarId calendarId)
  1594. {
  1595. return GetCalendar(calendarId).saAbbrevMonthGenitiveNames;
  1596. }
  1597. // Leap year month names
  1598. // Note: This only applies to Hebrew, and it basically adds a "1" to the 6th month name
  1599. // the non-leap names skip the 7th name in the normal month name array
  1600. internal string[] LeapYearMonthNames(CalendarId calendarId)
  1601. {
  1602. return GetCalendar(calendarId).saLeapYearMonthNames;
  1603. }
  1604. // month/day format (single string, no override)
  1605. internal string MonthDay(CalendarId calendarId)
  1606. {
  1607. return GetCalendar(calendarId).sMonthDay;
  1608. }
  1609. /////////////
  1610. // Calendars //
  1611. /////////////
  1612. // all available calendar type(s), The first one is the default calendar.
  1613. internal CalendarId[] CalendarIds
  1614. {
  1615. get
  1616. {
  1617. if (_waCalendars == null)
  1618. {
  1619. // We pass in an array of ints, and native side fills it up with count calendars.
  1620. // We then have to copy that list to a new array of the right size.
  1621. // Default calendar should be first
  1622. CalendarId[] calendars = new CalendarId[23];
  1623. Debug.Assert(_sWindowsName != null, "[CultureData.CalendarIds] Expected _sWindowsName to be populated by already");
  1624. int count = CalendarData.GetCalendars(_sWindowsName, _bUseOverrides, calendars);
  1625. // See if we had a calendar to add.
  1626. if (count == 0)
  1627. {
  1628. // Failed for some reason, just grab Gregorian from Invariant
  1629. _waCalendars = Invariant._waCalendars;
  1630. }
  1631. else
  1632. {
  1633. // The OS may not return calendar 4 for zh-TW, but we've always allowed it.
  1634. // TODO: Is this hack necessary long-term?
  1635. if (_sWindowsName == "zh-TW")
  1636. {
  1637. bool found = false;
  1638. // Do we need to insert calendar 4?
  1639. for (int i = 0; i < count; i++)
  1640. {
  1641. // Stop if we found calendar four
  1642. if (calendars[i] == CalendarId.TAIWAN)
  1643. {
  1644. found = true;
  1645. break;
  1646. }
  1647. }
  1648. // If not found then insert it
  1649. if (!found)
  1650. {
  1651. // Insert it as the 2nd calendar
  1652. count++;
  1653. // Copy them from the 2nd position to the end, -1 for skipping 1st, -1 for one being added.
  1654. Array.Copy(calendars, 1, calendars, 2, 23 - 1 - 1);
  1655. calendars[1] = CalendarId.TAIWAN;
  1656. }
  1657. }
  1658. // It worked, remember the list
  1659. CalendarId[] temp = new CalendarId[count];
  1660. Array.Copy(calendars, temp, count);
  1661. // Want 1st calendar to be default
  1662. // Prior to Vista the enumeration didn't have default calendar first
  1663. if (temp.Length > 1)
  1664. {
  1665. CalendarId i = (CalendarId)GetLocaleInfo(LocaleNumberData.CalendarType);
  1666. if (temp[1] == i)
  1667. {
  1668. temp[1] = temp[0];
  1669. temp[0] = i;
  1670. }
  1671. }
  1672. _waCalendars = temp;
  1673. }
  1674. }
  1675. return _waCalendars;
  1676. }
  1677. }
  1678. // Native calendar names. index of optional calendar - 1, empty if no optional calendar at that number
  1679. internal string CalendarName(CalendarId calendarId)
  1680. {
  1681. // Get the calendar
  1682. return GetCalendar(calendarId).sNativeName;
  1683. }
  1684. internal CalendarData GetCalendar(CalendarId calendarId)
  1685. {
  1686. Debug.Assert(calendarId > 0 && calendarId <= CalendarId.LAST_CALENDAR,
  1687. "[CultureData.GetCalendar] Expect calendarId to be in a valid range");
  1688. // arrays are 0 based, calendarIds are 1 based
  1689. int calendarIndex = (int)calendarId - 1;
  1690. // Have to have calendars
  1691. if (_calendars == null)
  1692. {
  1693. _calendars = new CalendarData[CalendarData.MAX_CALENDARS];
  1694. }
  1695. // we need the following local variable to avoid returning null
  1696. // when another thread creates a new array of CalendarData (above)
  1697. // right after we insert the newly created CalendarData (below)
  1698. CalendarData calendarData = _calendars[calendarIndex];
  1699. // Make sure that calendar has data
  1700. if (calendarData == null)
  1701. {
  1702. Debug.Assert(_sWindowsName != null, "[CultureData.GetCalendar] Expected _sWindowsName to be populated by already");
  1703. calendarData = new CalendarData(_sWindowsName, calendarId, this.UseUserOverride);
  1704. _calendars[calendarIndex] = calendarData;
  1705. }
  1706. return calendarData;
  1707. }
  1708. ///////////////////
  1709. // Text Information //
  1710. ///////////////////
  1711. // IsRightToLeft
  1712. internal bool IsRightToLeft
  1713. {
  1714. get
  1715. {
  1716. // Returns one of the following 4 reading layout values:
  1717. // 0 - Left to right (eg en-US)
  1718. // 1 - Right to left (eg arabic locales)
  1719. // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  1720. // 3 - Vertical top to bottom with columns proceeding to the right
  1721. return (this.IREADINGLAYOUT == 1);
  1722. }
  1723. }
  1724. // IREADINGLAYOUT
  1725. // Returns one of the following 4 reading layout values:
  1726. // 0 - Left to right (eg en-US)
  1727. // 1 - Right to left (eg arabic locales)
  1728. // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  1729. // 3 - Vertical top to bottom with columns proceeding to the right
  1730. //
  1731. // If exposed as a public API, we'd have an enum with those 4 values
  1732. private int IREADINGLAYOUT
  1733. {
  1734. get
  1735. {
  1736. if (_iReadingLayout == undef)
  1737. {
  1738. Debug.Assert(_sRealName != null, "[CultureData.IsRightToLeft] Expected _sRealName to be populated by already");
  1739. _iReadingLayout = GetLocaleInfo(LocaleNumberData.ReadingLayout);
  1740. }
  1741. return (_iReadingLayout);
  1742. }
  1743. }
  1744. // The TextInfo name never includes that alternate sort and is always specific
  1745. // For customs, it uses the SortLocale (since the textinfo is not exposed in Win7)
  1746. // en -> en-US
  1747. // en-US -> en-US
  1748. // fj (custom neutral) -> en-US (assuming that en-US is the sort locale for fj)
  1749. // fj_FJ (custom specific) -> en-US (assuming that en-US is the sort locale for fj-FJ)
  1750. // es-ES_tradnl -> es-ES
  1751. internal string STEXTINFO // Text info name to use for text information
  1752. {
  1753. get
  1754. {
  1755. // Note: Custom cultures might point at another culture's textinfo, however windows knows how
  1756. // to redirect it to the desired textinfo culture, so this is OK.
  1757. Debug.Assert(_sRealName != null, "[CultureData.STEXTINFO] Expected _sRealName to be populated by already");
  1758. return (_sRealName);
  1759. }
  1760. }
  1761. // Compare info name (including sorting key) to use if custom
  1762. internal string SCOMPAREINFO
  1763. {
  1764. get
  1765. {
  1766. Debug.Assert(_sRealName != null, "[CultureData.SCOMPAREINFO] Expected _sRealName to be populated by already");
  1767. return (_sRealName);
  1768. }
  1769. }
  1770. internal bool IsSupplementalCustomCulture
  1771. {
  1772. get
  1773. {
  1774. return IsCustomCultureId(this.ILANGUAGE);
  1775. }
  1776. }
  1777. internal int IDEFAULTANSICODEPAGE // default ansi code page ID (ACP)
  1778. {
  1779. get
  1780. {
  1781. if (_iDefaultAnsiCodePage == undef)
  1782. {
  1783. _iDefaultAnsiCodePage = GetAnsiCodePage(_sRealName);
  1784. }
  1785. return _iDefaultAnsiCodePage;
  1786. }
  1787. }
  1788. internal int IDEFAULTOEMCODEPAGE // default oem code page ID (OCP or OEM)
  1789. {
  1790. get
  1791. {
  1792. if (_iDefaultOemCodePage == undef)
  1793. {
  1794. _iDefaultOemCodePage = GetOemCodePage(_sRealName);
  1795. }
  1796. return _iDefaultOemCodePage;
  1797. }
  1798. }
  1799. internal int IDEFAULTMACCODEPAGE // default macintosh code page
  1800. {
  1801. get
  1802. {
  1803. if (_iDefaultMacCodePage == undef)
  1804. {
  1805. _iDefaultMacCodePage = GetMacCodePage(_sRealName);
  1806. }
  1807. return _iDefaultMacCodePage;
  1808. }
  1809. }
  1810. internal int IDEFAULTEBCDICCODEPAGE // default EBCDIC code page
  1811. {
  1812. get
  1813. {
  1814. if (_iDefaultEbcdicCodePage == undef)
  1815. {
  1816. _iDefaultEbcdicCodePage = GetEbcdicCodePage(_sRealName);
  1817. }
  1818. return _iDefaultEbcdicCodePage;
  1819. }
  1820. }
  1821. internal int ILANGUAGE
  1822. {
  1823. get
  1824. {
  1825. if (_iLanguage == 0)
  1826. {
  1827. Debug.Assert(_sRealName != null, "[CultureData.ILANGUAGE] Expected this.sRealName to be populated already");
  1828. _iLanguage = LocaleNameToLCID(_sRealName);
  1829. }
  1830. return _iLanguage;
  1831. }
  1832. }
  1833. internal bool IsNeutralCulture
  1834. {
  1835. get
  1836. {
  1837. // InitCultureData told us if we're neutral or not
  1838. return _bNeutral;
  1839. }
  1840. }
  1841. internal bool IsInvariantCulture
  1842. {
  1843. get
  1844. {
  1845. return string.IsNullOrEmpty(this.SNAME);
  1846. }
  1847. }
  1848. // Get an instance of our default calendar
  1849. internal Calendar DefaultCalendar
  1850. {
  1851. get
  1852. {
  1853. if (GlobalizationMode.Invariant)
  1854. {
  1855. return CultureInfo.GetCalendarInstance(CalendarIds[0]);
  1856. }
  1857. CalendarId defaultCalId = (CalendarId)GetLocaleInfo(LocaleNumberData.CalendarType);
  1858. if (defaultCalId == 0)
  1859. {
  1860. defaultCalId = this.CalendarIds[0];
  1861. }
  1862. return CultureInfo.GetCalendarInstance(defaultCalId);
  1863. }
  1864. }
  1865. // All of our era names
  1866. internal string[] EraNames(CalendarId calendarId)
  1867. {
  1868. Debug.Assert(calendarId > 0, "[CultureData.saEraNames] Expected Calendar.ID > 0");
  1869. return this.GetCalendar(calendarId).saEraNames;
  1870. }
  1871. internal string[] AbbrevEraNames(CalendarId calendarId)
  1872. {
  1873. Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
  1874. return this.GetCalendar(calendarId).saAbbrevEraNames;
  1875. }
  1876. internal string[] AbbreviatedEnglishEraNames(CalendarId calendarId)
  1877. {
  1878. Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
  1879. return this.GetCalendar(calendarId).saAbbrevEnglishEraNames;
  1880. }
  1881. //// string array DEFAULTS
  1882. //// Note: GetDTFIOverrideValues does the user overrides for these, so we don't have to.
  1883. // Time separator (derived from time format)
  1884. internal string TimeSeparator
  1885. {
  1886. get
  1887. {
  1888. if (_sTimeSeparator == null)
  1889. {
  1890. string longTimeFormat = GetTimeFormatString();
  1891. if (string.IsNullOrEmpty(longTimeFormat))
  1892. {
  1893. longTimeFormat = LongTimes[0];
  1894. }
  1895. // Compute STIME from time format
  1896. _sTimeSeparator = GetTimeSeparator(longTimeFormat);
  1897. }
  1898. return _sTimeSeparator;
  1899. }
  1900. }
  1901. // Date separator (derived from short date format)
  1902. internal string DateSeparator(CalendarId calendarId)
  1903. {
  1904. if (calendarId == CalendarId.JAPAN && !LocalAppContextSwitches.EnforceLegacyJapaneseDateParsing)
  1905. {
  1906. // The date separator is derived from the default short date pattern. So far this pattern is using
  1907. // '/' as date separator when using the Japanese calendar which make the formatting and parsing work fine.
  1908. // changing the default pattern is likely will happen in the near future which can easily break formatting
  1909. // and parsing.
  1910. // We are forcing here the date separator to '/' to ensure the parsing is not going to break when changing
  1911. // the default short date pattern. The application still can override this in the code by DateTimeFormatInfo.DateSeparartor.
  1912. return "/";
  1913. }
  1914. return GetDateSeparator(ShortDates(calendarId)[0]);
  1915. }
  1916. //////////////////////////////////////
  1917. // Helper Functions to get derived properties //
  1918. //////////////////////////////////////
  1919. ////////////////////////////////////////////////////////////////////////////
  1920. //
  1921. // Unescape a NLS style quote string
  1922. //
  1923. // This removes single quotes:
  1924. // 'fred' -> fred
  1925. // 'fred -> fred
  1926. // fred' -> fred
  1927. // fred's -> freds
  1928. //
  1929. // This removes the first \ of escaped characters:
  1930. // fred\'s -> fred's
  1931. // a\\b -> a\b
  1932. // a\b -> ab
  1933. //
  1934. // We don't build the stringbuilder unless we find a ' or a \. If we find a ' or a \, we
  1935. // always build a stringbuilder because we need to remove the ' or \.
  1936. //
  1937. ////////////////////////////////////////////////////////////////////////////
  1938. private static string UnescapeNlsString(string str, int start, int end)
  1939. {
  1940. Debug.Assert(str != null);
  1941. Debug.Assert(start >= 0);
  1942. Debug.Assert(end >= 0);
  1943. StringBuilder result = null;
  1944. for (int i = start; i < str.Length && i <= end; i++)
  1945. {
  1946. switch (str[i])
  1947. {
  1948. case '\'':
  1949. if (result == null)
  1950. {
  1951. result = new StringBuilder(str, start, i - start, str.Length);
  1952. }
  1953. break;
  1954. case '\\':
  1955. if (result == null)
  1956. {
  1957. result = new StringBuilder(str, start, i - start, str.Length);
  1958. }
  1959. ++i;
  1960. if (i < str.Length)
  1961. {
  1962. result.Append(str[i]);
  1963. }
  1964. break;
  1965. default:
  1966. if (result != null)
  1967. {
  1968. result.Append(str[i]);
  1969. }
  1970. break;
  1971. }
  1972. }
  1973. if (result == null)
  1974. return (str.Substring(start, end - start + 1));
  1975. return (result.ToString());
  1976. }
  1977. private static string GetTimeSeparator(string format)
  1978. {
  1979. // Time format separator (ie: : in 12:39:00)
  1980. //
  1981. // We calculate this from the provided time format
  1982. //
  1983. //
  1984. // Find the time separator so that we can pretend we know STIME.
  1985. //
  1986. return GetSeparator(format, "Hhms");
  1987. }
  1988. private static string GetDateSeparator(string format)
  1989. {
  1990. // Date format separator (ie: / in 9/1/03)
  1991. //
  1992. // We calculate this from the provided short date
  1993. //
  1994. //
  1995. // Find the date separator so that we can pretend we know SDATE.
  1996. //
  1997. return GetSeparator(format, "dyM");
  1998. }
  1999. private static string GetSeparator(string format, string timeParts)
  2000. {
  2001. int index = IndexOfTimePart(format, 0, timeParts);
  2002. if (index != -1)
  2003. {
  2004. // Found a time part, find out when it changes
  2005. char cTimePart = format[index];
  2006. do
  2007. {
  2008. index++;
  2009. } while (index < format.Length && format[index] == cTimePart);
  2010. int separatorStart = index;
  2011. // Now we need to find the end of the separator
  2012. if (separatorStart < format.Length)
  2013. {
  2014. int separatorEnd = IndexOfTimePart(format, separatorStart, timeParts);
  2015. if (separatorEnd != -1)
  2016. {
  2017. // From [separatorStart, count) is our string, except we need to unescape
  2018. return UnescapeNlsString(format, separatorStart, separatorEnd - 1);
  2019. }
  2020. }
  2021. }
  2022. return string.Empty;
  2023. }
  2024. private static int IndexOfTimePart(string format, int startIndex, string timeParts)
  2025. {
  2026. Debug.Assert(startIndex >= 0, "startIndex cannot be negative");
  2027. Debug.Assert(timeParts.IndexOfAny(new char[] { '\'', '\\' }) == -1, "timeParts cannot include quote characters");
  2028. bool inQuote = false;
  2029. for (int i = startIndex; i < format.Length; ++i)
  2030. {
  2031. // See if we have a time Part
  2032. if (!inQuote && timeParts.Contains(format[i]))
  2033. {
  2034. return i;
  2035. }
  2036. switch (format[i])
  2037. {
  2038. case '\\':
  2039. if (i + 1 < format.Length)
  2040. {
  2041. ++i;
  2042. switch (format[i])
  2043. {
  2044. case '\'':
  2045. case '\\':
  2046. break;
  2047. default:
  2048. --i; //backup since we will move over this next
  2049. break;
  2050. }
  2051. }
  2052. break;
  2053. case '\'':
  2054. inQuote = !inQuote;
  2055. break;
  2056. }
  2057. }
  2058. return -1;
  2059. }
  2060. internal static bool IsCustomCultureId(int cultureId)
  2061. {
  2062. return (cultureId == CultureInfo.LOCALE_CUSTOM_DEFAULT || cultureId == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED);
  2063. }
  2064. internal void GetNFIValues(NumberFormatInfo nfi)
  2065. {
  2066. if (GlobalizationMode.Invariant || this.IsInvariantCulture)
  2067. {
  2068. // FUTURE: NumberFormatInfo already has default values for many of these fields. Can we not do this?
  2069. nfi.positiveSign = _sPositiveSign;
  2070. nfi.negativeSign = _sNegativeSign;
  2071. nfi.numberGroupSeparator = _sThousandSeparator;
  2072. nfi.numberDecimalSeparator = _sDecimalSeparator;
  2073. nfi.numberDecimalDigits = _iDigits;
  2074. nfi.numberNegativePattern = _iNegativeNumber;
  2075. nfi.currencySymbol = _sCurrency;
  2076. nfi.currencyGroupSeparator = _sMonetaryThousand;
  2077. nfi.currencyDecimalSeparator = _sMonetaryDecimal;
  2078. nfi.currencyDecimalDigits = _iCurrencyDigits;
  2079. nfi.currencyNegativePattern = _iNegativeCurrency;
  2080. nfi.currencyPositivePattern = _iCurrency;
  2081. }
  2082. else
  2083. {
  2084. Debug.Assert(_sWindowsName != null, "[CultureData.GetNFIValues] Expected _sWindowsName to be populated by already");
  2085. // String values
  2086. nfi.positiveSign = GetLocaleInfo(LocaleStringData.PositiveSign);
  2087. nfi.negativeSign = GetLocaleInfo(LocaleStringData.NegativeSign);
  2088. nfi.numberDecimalSeparator = GetLocaleInfo(LocaleStringData.DecimalSeparator);
  2089. nfi.numberGroupSeparator = GetLocaleInfo(LocaleStringData.ThousandSeparator);
  2090. nfi.currencyGroupSeparator = GetLocaleInfo(LocaleStringData.MonetaryThousandSeparator);
  2091. nfi.currencyDecimalSeparator = GetLocaleInfo(LocaleStringData.MonetaryDecimalSeparator);
  2092. nfi.currencySymbol = GetLocaleInfo(LocaleStringData.MonetarySymbol);
  2093. // Numeric values
  2094. nfi.numberDecimalDigits = GetLocaleInfo(LocaleNumberData.FractionalDigitsCount);
  2095. nfi.currencyDecimalDigits = GetLocaleInfo(LocaleNumberData.MonetaryFractionalDigitsCount);
  2096. nfi.currencyPositivePattern = GetLocaleInfo(LocaleNumberData.PositiveMonetaryNumberFormat);
  2097. nfi.currencyNegativePattern = GetLocaleInfo(LocaleNumberData.NegativeMonetaryNumberFormat);
  2098. nfi.numberNegativePattern = GetLocaleInfo(LocaleNumberData.NegativeNumberFormat);
  2099. // LOCALE_SNATIVEDIGITS (array of 10 single character strings).
  2100. string digits = GetLocaleInfo(LocaleStringData.Digits);
  2101. nfi.nativeDigits = new string[10];
  2102. for (int i = 0; i < nfi.nativeDigits.Length; i++)
  2103. {
  2104. nfi.nativeDigits[i] = char.ToString(digits[i]);
  2105. }
  2106. nfi.digitSubstitution = GetDigitSubstitution(_sRealName);
  2107. }
  2108. //
  2109. // Gather additional data
  2110. //
  2111. nfi.numberGroupSizes = this.WAGROUPING;
  2112. nfi.currencyGroupSizes = this.WAMONGROUPING;
  2113. // prefer the cached value since these do not have user overrides
  2114. nfi.percentNegativePattern = this.INEGATIVEPERCENT;
  2115. nfi.percentPositivePattern = this.IPOSITIVEPERCENT;
  2116. nfi.percentSymbol = this.SPERCENT;
  2117. nfi.perMilleSymbol = this.SPERMILLE;
  2118. nfi.negativeInfinitySymbol = this.SNEGINFINITY;
  2119. nfi.positiveInfinitySymbol = this.SPOSINFINITY;
  2120. nfi.nanSymbol = this.SNAN;
  2121. //
  2122. // We don't have percent values, so use the number values
  2123. //
  2124. nfi.percentDecimalDigits = nfi.numberDecimalDigits;
  2125. nfi.percentDecimalSeparator = nfi.numberDecimalSeparator;
  2126. nfi.percentGroupSizes = nfi.numberGroupSizes;
  2127. nfi.percentGroupSeparator = nfi.numberGroupSeparator;
  2128. //
  2129. // Clean up a few odd values
  2130. //
  2131. // Windows usually returns an empty positive sign, but we like it to be "+"
  2132. if (nfi.positiveSign == null || nfi.positiveSign.Length == 0) nfi.positiveSign = "+";
  2133. //Special case for Italian. The currency decimal separator in the control panel is the empty string. When the user
  2134. //specifies C4 as the currency format, this results in the number apparently getting multiplied by 10000 because the
  2135. //decimal point doesn't show up. We'll just hack this here because our default currency format will never use nfi.
  2136. if (nfi.currencyDecimalSeparator == null || nfi.currencyDecimalSeparator.Length == 0)
  2137. {
  2138. nfi.currencyDecimalSeparator = nfi.numberDecimalSeparator;
  2139. }
  2140. }
  2141. // Helper
  2142. // This is ONLY used for caching names and shouldn't be used for anything else
  2143. internal static string AnsiToLower(string testString) =>
  2144. TextInfo.ToLowerAsciiInvariant(testString);
  2145. /// <remarks>
  2146. /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
  2147. /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
  2148. /// </remarks>
  2149. private enum LocaleStringData : uint
  2150. {
  2151. /// <summary>localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME)</summary>
  2152. LocalizedDisplayName = 0x00000002,
  2153. /// <summary>Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME)</summary>
  2154. EnglishDisplayName = 0x00000072,
  2155. /// <summary>Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME)</summary>
  2156. NativeDisplayName = 0x00000073,
  2157. /// <summary>Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME)</summary>
  2158. LocalizedLanguageName = 0x0000006f,
  2159. /// <summary>English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME)</summary>
  2160. EnglishLanguageName = 0x00001001,
  2161. /// <summary>native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME)</summary>
  2162. NativeLanguageName = 0x00000004,
  2163. /// <summary>localized name of country, eg "Germany" in UI language (corresponds to LOCALE_SLOCALIZEDCOUNTRYNAME)</summary>
  2164. LocalizedCountryName = 0x00000006,
  2165. /// <summary>English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME)</summary>
  2166. EnglishCountryName = 0x00001002,
  2167. /// <summary>native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME)</summary>
  2168. NativeCountryName = 0x00000008,
  2169. /// <summary>abbreviated language name (corresponds to LOCALE_SABBREVLANGNAME)</summary>
  2170. AbbreviatedWindowsLanguageName = 0x00000003,
  2171. /// <summary>list item separator (corresponds to LOCALE_SLIST)</summary>
  2172. ListSeparator = 0x0000000C,
  2173. /// <summary>decimal separator (corresponds to LOCALE_SDECIMAL)</summary>
  2174. DecimalSeparator = 0x0000000E,
  2175. /// <summary>thousand separator (corresponds to LOCALE_STHOUSAND)</summary>
  2176. ThousandSeparator = 0x0000000F,
  2177. /// <summary>digit grouping (corresponds to LOCALE_SGROUPING)</summary>
  2178. Digits = 0x00000013,
  2179. /// <summary>local monetary symbol (corresponds to LOCALE_SCURRENCY)</summary>
  2180. MonetarySymbol = 0x00000014,
  2181. /// <summary>English currency name (corresponds to LOCALE_SENGCURRNAME)</summary>
  2182. CurrencyEnglishName = 0x00001007,
  2183. /// <summary>Native currency name (corresponds to LOCALE_SNATIVECURRNAME)</summary>
  2184. CurrencyNativeName = 0x00001008,
  2185. /// <summary>uintl monetary symbol (corresponds to LOCALE_SINTLSYMBOL)</summary>
  2186. Iso4217MonetarySymbol = 0x00000015,
  2187. /// <summary>monetary decimal separator (corresponds to LOCALE_SMONDECIMALSEP)</summary>
  2188. MonetaryDecimalSeparator = 0x00000016,
  2189. /// <summary>monetary thousand separator (corresponds to LOCALE_SMONTHOUSANDSEP)</summary>
  2190. MonetaryThousandSeparator = 0x00000017,
  2191. /// <summary>AM designator (corresponds to LOCALE_S1159)</summary>
  2192. AMDesignator = 0x00000028,
  2193. /// <summary>PM designator (corresponds to LOCALE_S2359)</summary>
  2194. PMDesignator = 0x00000029,
  2195. /// <summary>positive sign (corresponds to LOCALE_SPOSITIVESIGN)</summary>
  2196. PositiveSign = 0x00000050,
  2197. /// <summary>negative sign (corresponds to LOCALE_SNEGATIVESIGN)</summary>
  2198. NegativeSign = 0x00000051,
  2199. /// <summary>ISO abbreviated language name (corresponds to LOCALE_SISO639LANGNAME)</summary>
  2200. Iso639LanguageTwoLetterName = 0x00000059,
  2201. /// <summary>ISO abbreviated country name (corresponds to LOCALE_SISO639LANGNAME2)</summary>
  2202. Iso639LanguageThreeLetterName = 0x00000067,
  2203. /// <summary>ISO abbreviated language name (corresponds to LOCALE_SISO639LANGNAME)</summary>
  2204. Iso639LanguageName = 0x00000059,
  2205. /// <summary>ISO abbreviated country name (corresponds to LOCALE_SISO3166CTRYNAME)</summary>
  2206. Iso3166CountryName = 0x0000005A,
  2207. /// <summary>3 letter ISO country code (corresponds to LOCALE_SISO3166CTRYNAME2)</summary>
  2208. Iso3166CountryName2 = 0x00000068, // 3 character ISO country name
  2209. /// <summary>Not a Number (corresponds to LOCALE_SNAN)</summary>
  2210. NaNSymbol = 0x00000069,
  2211. /// <summary>+ Infinity (corresponds to LOCALE_SPOSINFINITY)</summary>
  2212. PositiveInfinitySymbol = 0x0000006a,
  2213. /// <summary>- Infinity (corresponds to LOCALE_SNEGINFINITY)</summary>
  2214. NegativeInfinitySymbol = 0x0000006b,
  2215. /// <summary>Fallback name for resources (corresponds to LOCALE_SPARENT)</summary>
  2216. ParentName = 0x0000006d,
  2217. /// <summary>Fallback name for within the console (corresponds to LOCALE_SCONSOLEFALLBACKNAME)</summary>
  2218. ConsoleFallbackName = 0x0000006e,
  2219. /// <summary>Returns the percent symbol (corresponds to LOCALE_SPERCENT)</summary>
  2220. PercentSymbol = 0x00000076,
  2221. /// <summary>Returns the permille (U+2030) symbol (corresponds to LOCALE_SPERMILLE)</summary>
  2222. PerMilleSymbol = 0x00000077
  2223. }
  2224. /// <remarks>
  2225. /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
  2226. /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
  2227. /// </remarks>
  2228. private enum LocaleGroupingData : uint
  2229. {
  2230. /// <summary>digit grouping (corresponds to LOCALE_SGROUPING)</summary>
  2231. Digit = 0x00000010,
  2232. /// <summary>monetary grouping (corresponds to LOCALE_SMONGROUPING)</summary>
  2233. Monetary = 0x00000018,
  2234. }
  2235. /// <remarks>
  2236. /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
  2237. /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
  2238. /// </remarks>
  2239. private enum LocaleNumberData : uint
  2240. {
  2241. /// <summary>language id (corresponds to LOCALE_ILANGUAGE)</summary>
  2242. LanguageId = 0x00000001,
  2243. /// <summary>geographical location id, (corresponds to LOCALE_IGEOID)</summary>
  2244. GeoId = 0x0000005B,
  2245. /// <summary>0 = context, 1 = none, 2 = national (corresponds to LOCALE_IDIGITSUBSTITUTION)</summary>
  2246. DigitSubstitution = 0x00001014,
  2247. /// <summary>0 = metric, 1 = US (corresponds to LOCALE_IMEASURE)</summary>
  2248. MeasurementSystem = 0x0000000D,
  2249. /// <summary>number of fractional digits (corresponds to LOCALE_IDIGITS)</summary>
  2250. FractionalDigitsCount = 0x00000011,
  2251. /// <summary>negative number mode (corresponds to LOCALE_INEGNUMBER)</summary>
  2252. NegativeNumberFormat = 0x00001010,
  2253. /// <summary># local monetary digits (corresponds to LOCALE_ICURRDIGITS)</summary>
  2254. MonetaryFractionalDigitsCount = 0x00000019,
  2255. /// <summary>positive currency mode (corresponds to LOCALE_ICURRENCY)</summary>
  2256. PositiveMonetaryNumberFormat = 0x0000001B,
  2257. /// <summary>negative currency mode (corresponds to LOCALE_INEGCURR)</summary>
  2258. NegativeMonetaryNumberFormat = 0x0000001C,
  2259. /// <summary>type of calendar specifier (corresponds to LOCALE_ICALENDARTYPE)</summary>
  2260. CalendarType = 0x00001009,
  2261. /// <summary>first day of week specifier (corresponds to LOCALE_IFIRSTDAYOFWEEK)</summary>
  2262. FirstDayOfWeek = 0x0000100C,
  2263. /// <summary>first week of year specifier (corresponds to LOCALE_IFIRSTWEEKOFYEAR)</summary>
  2264. FirstWeekOfYear = 0x0000100D,
  2265. /// <summary>
  2266. /// Returns one of the following 4 reading layout values:
  2267. /// 0 - Left to right (eg en-US)
  2268. /// 1 - Right to left (eg arabic locales)
  2269. /// 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  2270. /// 3 - Vertical top to bottom with columns proceeding to the right
  2271. /// (corresponds to LOCALE_IREADINGLAYOUT)
  2272. /// </summary>
  2273. ReadingLayout = 0x00000070,
  2274. /// <summary>Returns 0-11 for the negative percent format (corresponds to LOCALE_INEGATIVEPERCENT)</summary>
  2275. NegativePercentFormat = 0x00000074,
  2276. /// <summary>Returns 0-3 for the positive percent format (corresponds to LOCALE_IPOSITIVEPERCENT)</summary>
  2277. PositivePercentFormat = 0x00000075,
  2278. /// <summary>default ansi code page (corresponds to LOCALE_IDEFAULTCODEPAGE)</summary>
  2279. OemCodePage = 0x0000000B,
  2280. /// <summary>default ansi code page (corresponds to LOCALE_IDEFAULTANSICODEPAGE)</summary>
  2281. AnsiCodePage = 0x00001004,
  2282. /// <summary>default mac code page (corresponds to LOCALE_IDEFAULTMACCODEPAGE)</summary>
  2283. MacCodePage = 0x00001011,
  2284. /// <summary>default ebcdic code page (corresponds to LOCALE_IDEFAULTEBCDICCODEPAGE)</summary>
  2285. EbcdicCodePage = 0x00001012,
  2286. }
  2287. }
  2288. }