Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CultureInfo.cs
Go to the documentation of this file.
4
6
8{
9 private bool _isReadOnly;
10
12
14
16
18
20
22
23 internal bool _isInherited;
24
26
27 internal string _name;
28
29 private string _nonSortName;
30
31 private string _sortName;
32
33 private static volatile CultureInfo s_userDefaultCulture;
34
35 private static volatile CultureInfo s_userDefaultUICulture;
36
38
40
42
45
48
50
52
54
56
58
59 internal const int LOCALE_NEUTRAL = 0;
60
61 private const int LOCALE_USER_DEFAULT = 1024;
62
63 private const int LOCALE_SYSTEM_DEFAULT = 2048;
64
65 internal const int LOCALE_CUSTOM_UNSPECIFIED = 4096;
66
67 internal const int LOCALE_CUSTOM_DEFAULT = 3072;
68
69 internal const int LOCALE_INVARIANT = 127;
70
72 {
73 get
74 {
76 }
77 set
78 {
79 if (value == null)
80 {
81 throw new ArgumentNullException("value");
82 }
84 {
86 }
87 s_asyncLocalCurrentCulture.Value = value;
88 }
89 }
90
92 {
93 get
94 {
96 }
97 set
98 {
99 if (value == null)
100 {
101 throw new ArgumentNullException("value");
102 }
105 {
107 }
108 s_asyncLocalCurrentUICulture.Value = value;
109 }
110 }
111
113
115
117 {
118 get
119 {
121 }
122 set
123 {
125 }
126 }
127
129 {
130 get
131 {
133 }
134 set
135 {
136 if (value != null)
137 {
139 }
141 }
142 }
143
145
146 public virtual CultureInfo Parent
147 {
148 get
149 {
150 if (_parent == null)
151 {
153 if (text == "zh")
154 {
155 if (_name.Length == 5 && _name[2] == '-')
156 {
157 if ((_name[3] == 'C' && _name[4] == 'N') || (_name[3] == 'S' && _name[4] == 'G'))
158 {
159 text = "zh-Hans";
160 }
161 else if ((_name[3] == 'H' && _name[4] == 'K') || (_name[3] == 'M' && _name[4] == 'O') || (_name[3] == 'T' && _name[4] == 'W'))
162 {
163 text = "zh-Hant";
164 }
165 }
166 else if (_name.Length > 8 && MemoryExtensions.Equals(_name.AsSpan(2, 4), "-Han", StringComparison.Ordinal) && _name[7] == '-')
167 {
168 if (_name[6] == 't')
169 {
170 text = "zh-Hant";
171 }
172 else if (_name[6] == 's')
173 {
174 text = "zh-Hans";
175 }
176 }
177 }
179 }
180 return _parent;
181 }
182 }
183
184 public virtual int LCID => _cultureData.LCID;
185
187
188 public virtual string Name
189 {
190 get
191 {
192 string text = _nonSortName;
193 if (text == null)
194 {
195 string obj = _cultureData.Name ?? string.Empty;
196 string text2 = obj;
198 text = text2;
199 }
200 return text;
201 }
202 }
203
205
206 public string IetfLanguageTag
207 {
208 get
209 {
210 string name = Name;
211 if (!(name == "zh-CHT"))
212 {
213 if (name == "zh-CHS")
214 {
215 return "zh-Hans";
216 }
217 return Name;
218 }
219 return "zh-Hant";
220 }
221 }
222
223 public virtual string DisplayName => _cultureData.DisplayName;
224
225 public virtual string NativeName => _cultureData.NativeName;
226
227 public virtual string EnglishName => _cultureData.EnglishName;
228
230
232
234
236
237 public virtual TextInfo TextInfo
238 {
239 get
240 {
241 if (_textInfo == null)
242 {
244 textInfo.SetReadOnlyState(_isReadOnly);
246 }
247 return _textInfo;
248 }
249 }
250
252
254 {
255 get
256 {
257 CultureTypes cultureTypes = (_cultureData.IsNeutralCulture ? CultureTypes.NeutralCultures : CultureTypes.SpecificCultures);
259 cultureTypes |= CultureTypes.InstalledWin32Cultures;
261 {
262 cultureTypes |= CultureTypes.UserCustomCulture;
263 }
265 {
266 cultureTypes |= CultureTypes.ReplacementCultures;
267 }
268 return cultureTypes;
269 }
270 }
271
273 {
274 get
275 {
276 if (_numInfo == null)
277 {
279 numberFormatInfo._isReadOnly = _isReadOnly;
281 }
282 return _numInfo;
283 }
284 set
285 {
286 if (value == null)
287 {
288 throw new ArgumentNullException("value");
289 }
291 _numInfo = value;
292 }
293 }
294
296 {
297 get
298 {
299 if (_dateTimeInfo == null)
300 {
302 dateTimeFormatInfo._isReadOnly = _isReadOnly;
304 }
305 return _dateTimeInfo;
306 }
307 set
308 {
309 if (value == null)
310 {
311 throw new ArgumentNullException("value");
312 }
315 }
316 }
317
318 public virtual Calendar Calendar
319 {
320 get
321 {
322 if (_calendar == null)
323 {
326 defaultCalendar.SetReadOnlyState(_isReadOnly);
328 }
329 return _calendar;
330 }
331 }
332
334 {
335 get
336 {
338 {
339 return new GregorianCalendar[1]
340 {
342 };
343 }
345 Calendar[] array = new Calendar[calendarIds.Length];
346 for (int i = 0; i < array.Length; i++)
347 {
349 }
350 return array;
351 }
352 }
353
355
356 public bool IsReadOnly => _isReadOnly;
357
359
373
387
388 internal static string? UserDefaultLocaleName { get; set; } = GetUserDefaultLocaleName();
389
390
395
400
406
412
421
422 public CultureInfo(string name)
423 : this(name, useUserOverride: true)
424 {
425 }
426
427 public CultureInfo(string name, bool useUserOverride)
428 {
429 if (name == null)
430 {
431 throw new ArgumentNullException("name");
432 }
434 if (cultureData == null)
435 {
437 }
440 _isInherited = GetType() != typeof(CultureInfo);
441 }
442
444 {
446 _name = cultureData.CultureName;
448 }
449
450 private static CultureInfo CreateCultureInfoNoThrow(string name, bool useUserOverride)
451 {
453 if (cultureData == null)
454 {
455 return null;
456 }
457 return new CultureInfo(cultureData);
458 }
459
462 {
463 }
464
466 {
467 if (culture < 0)
468 {
470 }
471 switch (culture)
472 {
473 case 0:
474 case 1024:
475 case 2048:
476 case 3072:
477 case 4096:
479 }
481 _isInherited = GetType() != typeof(CultureInfo);
483 }
484
485 internal CultureInfo(string cultureName, string textAndCompareCultureName)
486 {
487 if (cultureName == null)
488 {
489 throw new ArgumentNullException("cultureName", SR.ArgumentNull_String);
490 }
495 _compareInfo = cultureInfo.CompareInfo;
496 _textInfo = cultureInfo.TextInfo;
497 }
498
499 private static CultureInfo GetCultureByName(string name)
500 {
501 try
502 {
503 return new CultureInfo(name)
504 {
505 _isReadOnly = true
506 };
507 }
508 catch (ArgumentException)
509 {
510 return InvariantCulture;
511 }
512 }
513
514 public static CultureInfo CreateSpecificCulture(string name)
515 {
517 try
518 {
519 cultureInfo = new CultureInfo(name);
520 }
521 catch (ArgumentException)
522 {
523 cultureInfo = null;
524 for (int i = 0; i < name.Length; i++)
525 {
526 if ('-' == name[i])
527 {
528 try
529 {
530 cultureInfo = new CultureInfo(name.Substring(0, i));
531 }
532 catch (ArgumentException)
533 {
534 throw;
535 }
536 break;
537 }
538 }
539 if (cultureInfo == null)
540 {
541 throw;
542 }
543 }
544 if (!cultureInfo.IsNeutralCulture)
545 {
546 return cultureInfo;
547 }
548 return new CultureInfo(cultureInfo._cultureData.SpecificCultureName);
549 }
550
551 internal static bool VerifyCultureName(string cultureName, bool throwException)
552 {
553 foreach (char c in cultureName)
554 {
555 if (!char.IsLetterOrDigit(c) && c != '-' && c != '_')
556 {
557 if (throwException)
558 {
560 }
561 return false;
562 }
563 }
564 return true;
565 }
566
568 {
569 if (!culture._isInherited)
570 {
571 return true;
572 }
574 }
575
577 {
578 if ((types & CultureTypes.UserCustomCulture) == CultureTypes.UserCustomCulture)
579 {
580 types |= CultureTypes.ReplacementCultures;
581 }
583 }
584
585 public override bool Equals([NotNullWhen(true)] object? value)
586 {
587 if (this == value)
588 {
589 return true;
590 }
592 {
593 if (Name.Equals(cultureInfo.Name))
594 {
595 return CompareInfo.Equals(cultureInfo.CompareInfo);
596 }
597 return false;
598 }
599 return false;
600 }
601
602 public override int GetHashCode()
603 {
604 return Name.GetHashCode() + CompareInfo.GetHashCode();
605 }
606
607 public override string ToString()
608 {
609 return _name;
610 }
611
612 public virtual object? GetFormat(Type? formatType)
613 {
615 {
616 return NumberFormat;
617 }
619 {
620 return DateTimeFormat;
621 }
622 return null;
623 }
624
637
639 {
640 if (calType == CalendarId.GREGORIAN)
641 {
642 return new GregorianCalendar();
643 }
645 }
646
648 {
649 switch (calType)
650 {
651 case CalendarId.GREGORIAN_US:
652 case CalendarId.GREGORIAN_ME_FRENCH:
653 case CalendarId.GREGORIAN_ARABIC:
654 case CalendarId.GREGORIAN_XLIT_ENGLISH:
655 case CalendarId.GREGORIAN_XLIT_FRENCH:
657 case CalendarId.TAIWAN:
658 return new TaiwanCalendar();
659 case CalendarId.JAPAN:
660 return new JapaneseCalendar();
661 case CalendarId.KOREA:
662 return new KoreanCalendar();
663 case CalendarId.THAI:
664 return new ThaiBuddhistCalendar();
665 case CalendarId.HIJRI:
666 return new HijriCalendar();
667 case CalendarId.HEBREW:
668 return new HebrewCalendar();
669 case CalendarId.UMALQURA:
670 return new UmAlQuraCalendar();
671 case CalendarId.PERSIAN:
672 return new PersianCalendar();
673 default:
674 return new GregorianCalendar();
675 }
676 }
677
689
690 public virtual object Clone()
691 {
692 CultureInfo cultureInfo = (CultureInfo)MemberwiseClone();
693 cultureInfo._isReadOnly = false;
694 if (!_isInherited)
695 {
696 if (_dateTimeInfo != null)
697 {
698 cultureInfo._dateTimeInfo = (DateTimeFormatInfo)_dateTimeInfo.Clone();
699 }
700 if (_numInfo != null)
701 {
702 cultureInfo._numInfo = (NumberFormatInfo)_numInfo.Clone();
703 }
704 }
705 else
706 {
707 cultureInfo.DateTimeFormat = (DateTimeFormatInfo)DateTimeFormat.Clone();
708 cultureInfo.NumberFormat = (NumberFormatInfo)NumberFormat.Clone();
709 }
710 if (_textInfo != null)
711 {
712 cultureInfo._textInfo = (TextInfo)_textInfo.Clone();
713 }
715 {
716 cultureInfo._calendar = cultureInfo.DateTimeFormat.Calendar;
717 }
718 else if (_calendar != null)
719 {
720 cultureInfo._calendar = (Calendar)_calendar.Clone();
721 }
722 return cultureInfo;
723 }
724
726 {
727 if (ci == null)
728 {
729 throw new ArgumentNullException("ci");
730 }
731 if (ci.IsReadOnly)
732 {
733 return ci;
734 }
735 CultureInfo cultureInfo = (CultureInfo)ci.MemberwiseClone();
736 if (!ci.IsNeutralCulture)
737 {
738 if (!ci._isInherited)
739 {
740 if (ci._dateTimeInfo != null)
741 {
742 cultureInfo._dateTimeInfo = DateTimeFormatInfo.ReadOnly(ci._dateTimeInfo);
743 }
744 if (ci._numInfo != null)
745 {
746 cultureInfo._numInfo = NumberFormatInfo.ReadOnly(ci._numInfo);
747 }
748 }
749 else
750 {
751 cultureInfo.DateTimeFormat = DateTimeFormatInfo.ReadOnly(ci.DateTimeFormat);
752 cultureInfo.NumberFormat = NumberFormatInfo.ReadOnly(ci.NumberFormat);
753 }
754 }
755 if (ci._textInfo != null)
756 {
757 cultureInfo._textInfo = System.Globalization.TextInfo.ReadOnly(ci._textInfo);
758 }
759 if (ci._calendar != null)
760 {
761 cultureInfo._calendar = System.Globalization.Calendar.ReadOnly(ci._calendar);
762 }
763 cultureInfo._isReadOnly = true;
764 return cultureInfo;
765 }
766
767 private void VerifyWritable()
768 {
769 if (_isReadOnly)
770 {
772 }
773 }
774
776 {
777 if (culture <= 0)
778 {
780 }
784 {
786 {
787 return value;
788 }
789 }
790 try
791 {
793 {
794 _isReadOnly = true
795 };
796 }
797 catch (ArgumentException)
798 {
800 }
802 {
804 return value;
805 }
806 }
807
808 public static CultureInfo GetCultureInfo(string name)
809 {
810 if (name == null)
811 {
812 throw new ArgumentNullException("name");
813 }
814 name = CultureData.AnsiToLower(name);
818 {
820 {
821 return value;
822 }
823 }
825 value._isReadOnly = true;
826 name = CultureData.AnsiToLower(value._name);
828 {
830 return value;
831 }
832 }
833
834 public static CultureInfo GetCultureInfo(string name, string altName)
835 {
836 if (name == null)
837 {
838 throw new ArgumentNullException("name");
839 }
840 if (altName == null)
841 {
842 throw new ArgumentNullException("altName");
843 }
844 name = CultureData.AnsiToLower(name);
846 string key = name + "\ufffd" + altName;
850 {
852 {
853 return value;
854 }
855 }
856 try
857 {
858 value = new CultureInfo(name, altName)
859 {
860 _isReadOnly = true
861 };
862 value.TextInfo.SetReadOnlyState(readOnly: true);
863 }
864 catch (ArgumentException)
865 {
867 }
869 {
871 return value;
872 }
873 }
874
875 public static CultureInfo GetCultureInfo(string name, bool predefinedOnly)
876 {
877 if (name == null)
878 {
879 throw new ArgumentNullException("name");
880 }
882 {
884 }
885 return GetCultureInfo(name);
886 }
887
889 {
890 if (name == "zh-CHT" || name == "zh-CHS")
891 {
893 }
895 if (cultureInfo.LCID > 65535 || cultureInfo.LCID == 1034)
896 {
898 }
899 return cultureInfo;
900 }
901
903 {
905 {
906 return InvariantCulture;
907 }
909 if (userDefaultLocaleName == null)
910 {
911 return InvariantCulture;
912 }
914 }
915
916 private unsafe static CultureInfo GetUserDefaultUICulture()
917 {
919 {
920 return InvariantCulture;
921 }
922 uint num = 0u;
923 uint num2 = 0u;
924 if (Interop.Kernel32.GetUserPreferredUILanguages(8u, &num, null, &num2) != 0)
925 {
926 Span<char> span = ((num2 > 256) ? ((Span<char>)new char[num2]) : stackalloc char[(int)num2]);
929 {
931 {
932 return GetCultureByName(span2.ToString());
933 }
934 }
935 }
937 }
938
939 private static string GetUserDefaultLocaleName()
940 {
941 string text;
943 {
945 if (text == null)
946 {
947 return CultureData.GetLocaleInfoEx("!x-sys-default-locale", 92u);
948 }
949 }
950 else
951 {
952 text = InvariantCulture.Name;
953 }
954 return text;
955 }
956}
static unsafe BOOL GetUserPreferredUILanguages(uint dwFlags, uint *pulNumLanguages, char *pwszLanguagesBuffer, uint *pcchLanguagesBuffer)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
virtual object Clone()
Definition Calendar.cs:54
static Calendar ReadOnly(Calendar calendar)
Definition Calendar.cs:61
override bool Equals([NotNullWhen(true)] object? value)
static CultureInfo[] GetCultures(CultureTypes types)
static bool NlsIsEnsurePredefinedLocaleName(string name)
static string AnsiToLower(string testString)
static CultureData GetCultureData(string cultureName, bool useUserOverride)
static bool IcuIsEnsurePredefinedLocaleName(string name)
static unsafe string GetLocaleInfoEx(string localeName, uint field)
CultureInfo(string name, bool useUserOverride)
static volatile CultureInfo s_DefaultThreadCurrentCulture
static volatile CultureInfo s_userDefaultCulture
static bool VerifyCultureName(string cultureName, bool throwException)
CultureInfo(string cultureName, string textAndCompareCultureName)
static CultureInfo CurrentUICulture
static Calendar GetCalendarInstanceRare(CalendarId calType)
virtual Calendar[] OptionalCalendars
static CultureInfo GetCultureInfo(string name)
CultureInfo GetConsoleFallbackUICulture()
static volatile CultureInfo s_DefaultThreadCurrentUICulture
static ? CultureInfo DefaultThreadCurrentCulture
static CultureInfo s_currentThreadCulture
static string GetCultureNotSupportedExceptionMessage()
static AsyncLocal< CultureInfo > s_asyncLocalCurrentCulture
static void AsyncLocalSetCurrentUICulture(AsyncLocalValueChangedArgs< CultureInfo > args)
static CultureInfo GetCultureInfo(string name, string altName)
DateTimeFormatInfo _dateTimeInfo
static CultureInfo s_currentThreadUICulture
static void AsyncLocalSetCurrentCulture(AsyncLocalValueChangedArgs< CultureInfo > args)
static CultureInfo ReadOnly(CultureInfo ci)
static volatile Dictionary< string, CultureInfo > s_cachedCulturesByName
static CultureInfo InitializeUserDefaultUICulture()
CultureInfo(CultureData cultureData, bool isReadOnly=false)
static CultureInfo CreateSpecificCulture(string name)
static Calendar GetCalendarInstance(CalendarId calType)
static CultureInfo GetCultureByName(string name)
static readonly CultureInfo s_InvariantCultureInfo
virtual string TwoLetterISOLanguageName
static CultureInfo[] GetCultures(CultureTypes types)
virtual CompareInfo CompareInfo
virtual string ThreeLetterISOLanguageName
static CultureInfo CreateCultureInfoNoThrow(string name, bool useUserOverride)
static volatile Dictionary< int, CultureInfo > s_cachedCulturesByLcid
virtual DateTimeFormatInfo DateTimeFormat
static CultureInfo UserDefaultUICulture
static CultureInfo InstalledUICulture
static CultureInfo InitializeUserDefaultCulture()
static unsafe CultureInfo GetUserDefaultUICulture()
static CultureInfo CurrentCulture
static ? string UserDefaultLocaleName
static CultureInfo GetCultureInfoByIetfLanguageTag(string name)
static CultureInfo InvariantCulture
static string GetUserDefaultLocaleName()
static CultureInfo GetCultureInfo(string name, bool predefinedOnly)
static CultureInfo GetUserDefaultCulture()
static volatile CultureInfo s_userDefaultUICulture
static AsyncLocal< CultureInfo > s_asyncLocalCurrentUICulture
static Dictionary< int, CultureInfo > CachedCulturesByLcid
static Dictionary< string, CultureInfo > CachedCulturesByName
static CultureInfo GetCultureInfo(int culture)
CultureInfo(int culture, bool useUserOverride)
static bool VerifyCultureName(CultureInfo culture, bool throwException)
virtual NumberFormatInfo NumberFormat
virtual string ThreeLetterWindowsLanguageName
virtual ? object GetFormat(Type? formatType)
static ? CultureInfo DefaultThreadCurrentUICulture
override bool Equals([NotNullWhen(true)] object? value)
static NumberFormatInfo ReadOnly(NumberFormatInfo nfi)
static TextInfo ReadOnly(TextInfo textInfo)
Definition TextInfo.cs:128
static bool Equals(this ReadOnlySpan< char > span, ReadOnlySpan< char > other, StringComparison comparisonType)
static string Argument_InvalidPredefinedCultureName
Definition SR.cs:662
static string ArgumentOutOfRange_NeedPosNum
Definition SR.cs:20
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_InvalidResourceCultureName
Definition SR.cs:732
static string Argument_CultureIetfNotSupported
Definition SR.cs:542
static string Argument_OneOfCulturesNotSupported
Definition SR.cs:834
static string Argument_CultureNotSupportedInInvariantMode
Definition SR.cs:550
static string Argument_CultureNotSupported
Definition SR.cs:548
static string ArgumentNull_String
Definition SR.cs:960
static string InvalidOperation_ReadOnly
Definition SR.cs:1504
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
static void ClearCachedData()
static void ResetTimeZone()
Definition TimeZone.cs:50