private static int NlsGetCalendars(string localeName, bool useUserOverride, CalendarId[] calendars) { NlsEnumCalendarsData data = default; data.userOverride = 0; data.calendars = new List <int>(); // First call GetLocaleInfo if necessary if (useUserOverride) { // They want user overrides, see if the user calendar matches the input calendar int userCalendar = CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE); // If we got a default, then use it as the first calendar if (userCalendar != 0) { data.userOverride = userCalendar; data.calendars.Add(userCalendar); } } unsafe { Interop.Kernel32.EnumCalendarInfoExEx(&EnumCalendarsCallback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, Unsafe.AsPointer(ref data)); } // Copy to the output array for (int i = 0; i < Math.Min(calendars.Length, data.calendars.Count); i++) { calendars[i] = (CalendarId)data.calendars[i]; } // Now we have a list of data, return the count return(data.calendars.Count); }
private bool LoadCalendarDataFromSystemCore(string localeName, CalendarId calendarId) { Debug.Assert(!GlobalizationMode.Invariant); if (GlobalizationMode.UseNls) { return(NlsLoadCalendarDataFromSystem(localeName, calendarId)); } // If running using ICU on Windows we should honor user overrides using NLS and the rest from ICU bool result = IcuLoadCalendarDataFromSystem(localeName, calendarId); if (result && bUseUserOverrides) { NormalizeCalendarId(ref calendarId, ref localeName); result &= CallGetCalendarInfoEx(localeName, calendarId, CAL_ITWODIGITYEARMAX, out this.iTwoDigitYearMax); // They want user overrides, see if the user calendar matches the input calendar CalendarId userCalendar = (CalendarId)CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE); // If the calendars were the same, see if the locales were the same if (userCalendar == calendarId) { string?shortDateOverride = CultureData.ReescapeWin32String(CultureData.GetLocaleInfoEx(localeName, LOCALE_SSHORTDATE)); string?longDateOverride = CultureData.ReescapeWin32String(CultureData.GetLocaleInfoEx(localeName, LOCALE_SLONGDATE)); InsertOrSwapOverride(shortDateOverride, ref this.saShortDates); InsertOrSwapOverride(longDateOverride, ref this.saLongDates); } } return(result); }
private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[]?data) { EnumData context = default; context.userOverride = null; context.strings = new List <string>(); // First call GetLocaleInfo if necessary if ((lcType != 0) && ((lcType & CAL_NOUSEROVERRIDE) == 0)) { // They want user overrides, see if the user calendar matches the input calendar CalendarId userCalendar = (CalendarId)CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE); // If the calendars were the same, see if the locales were the same if (userCalendar == calendar) { // They matched, get the user override since locale & calendar match string?res = CultureData.GetLocaleInfoEx(localeName, lcType); // if it succeeded remember the override for the later callers if (res != null) { // Remember this was the override (so we can look for duplicates later in the enum function) context.userOverride = res; // Add to the result strings. context.strings.Add(res); } } } // Now call the enumeration API. Work is done by our callback function Interop.Kernel32.EnumCalendarInfoExEx(&EnumCalendarInfoCallback, localeName, (uint)calendar, null, calType, Unsafe.AsPointer(ref context)); // Now we have a list of data, fail if we didn't find anything. Debug.Assert(context.strings != null); if (context.strings.Count == 0) { data = null; return(false); } string[] output = context.strings.ToArray(); if (calType == CAL_SABBREVERASTRING || calType == CAL_SERASTRING) { // Eras are enumerated backwards. (oldest era name first, but // Japanese calendar has newest era first in array, and is only // calendar with multiple eras) Array.Reverse(output, 0, output.Length); } data = output; return(true); }
private static CultureInfo NlsGetPredefinedCultureInfo(string name) { Debug.Assert(GlobalizationMode.UseNls); if (CultureData.GetLocaleInfoExInt(name, Interop.Kernel32.LOCALE_ICONSTRUCTEDLOCALE) == 1) { throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_InvalidPredefinedCultureName, name)); } return(GetCultureInfo(name)); }
// Call native side to figure out which calendars are allowed internal static int GetCalendars(String localeName, bool useUserOverride, CalendarId[] calendars) { Debug.Assert(!GlobalizationMode.Invariant); EnumCalendarsData data = new EnumCalendarsData(); data.userOverride = 0; data.calendars = new IntList(); // First call GetLocaleInfo if necessary if (useUserOverride) { // They want user overrides, see if the user calendar matches the input calendar int userCalendar = CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE); // If we got a default, then use it as the first calendar if (userCalendar != 0) { data.userOverride = userCalendar; data.calendars.Add(userCalendar); } } GCHandle contextHandle = GCHandle.Alloc(data); try { // Now call the enumeration API. Work is done by our callback function #if CORECLR Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarsCallback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, (IntPtr)contextHandle); #else IntPtr callback = AddrofIntrinsics.AddrOf <Func <IntPtr, uint, IntPtr, IntPtr, Interop.BOOL> >(EnumCalendarsCallback); Interop.Kernel32.EnumCalendarInfoExEx(callback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, (IntPtr)contextHandle); #endif } finally { contextHandle.Free(); } // Copy to the output array for (int i = 0; i < Math.Min(calendars.Length, data.calendars.Count); i++) { calendars[i] = (CalendarId)data.calendars[i]; } // Now we have a list of data, return the count return(data.calendars.Count); }
internal static int GetCalendarsCore(string localeName, bool useUserOverride, CalendarId[] calendars) { Debug.Assert(!GlobalizationMode.Invariant); if (GlobalizationMode.UseNls) { return(NlsGetCalendars(localeName, useUserOverride, calendars)); } int count = IcuGetCalendars(localeName, calendars); if (useUserOverride) { // They want user overrides, see if the user calendar matches the input calendar int userCalendar = CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE); if (userCalendar != 0 && (CalendarId)userCalendar != calendars[0]) { CalendarId userOverride = (CalendarId)userCalendar; for (int i = 1; i < calendars.Length; i++) { if (calendars[i] == userOverride) { CalendarId tmp = calendars[0]; calendars[0] = userOverride; calendars[i] = tmp; return(count); } } // We didn't find it, we insert it at the beginning of the array. If calendar's array is full, we drop the last element. count = count < calendars.Length ? count + 1 : count; Span <CalendarId> tmpSpan = stackalloc CalendarId[count]; // should be 23 max. tmpSpan[0] = userOverride; calendars.AsSpan(0, count - 1).CopyTo(tmpSpan.Slice(1)); tmpSpan.CopyTo(calendars); } } return(count); }
internal static bool NlsIsEnsurePredefinedLocaleName(string name) { Debug.Assert(GlobalizationMode.UseNls); return(CultureData.GetLocaleInfoExInt(name, Interop.Kernel32.LOCALE_ICONSTRUCTEDLOCALE) != 1); }
private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[] data) { EnumData context = new EnumData(); context.userOverride = null; context.strings = new StringList(); // First call GetLocaleInfo if necessary if (((lcType != 0) && ((lcType & CAL_NOUSEROVERRIDE) == 0)) && // Get user locale, see if it matches localeName. // Note that they should match exactly, including letter case GetUserDefaultLocaleName() == localeName) { // They want user overrides, see if the user calendar matches the input calendar CalendarId userCalendar = (CalendarId)CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE); // If the calendars were the same, see if the locales were the same if (userCalendar == calendar) { // They matched, get the user override since locale & calendar match string res = CultureData.GetLocaleInfoEx(localeName, lcType); // if it succeeded remember the override for the later callers if (res != "") { // Remember this was the override (so we can look for duplicates later in the enum function) context.userOverride = res; // Add to the result strings. context.strings.Add(res); } } } GCHandle contextHandle = GCHandle.Alloc(context); try { #if CORECLR Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarInfoCallback, localeName, (uint)calendar, null, calType, (IntPtr)contextHandle); #else // Now call the enumeration API. Work is done by our callback function IntPtr callback = AddrofIntrinsics.AddrOf <Func <IntPtr, uint, IntPtr, IntPtr, Interop.BOOL> >(EnumCalendarInfoCallback); Interop.Kernel32.EnumCalendarInfoExEx(callback, localeName, (uint)calendar, null, calType, (IntPtr)contextHandle); #endif // CORECLR } finally { contextHandle.Free(); } // Now we have a list of data, fail if we didn't find anything. if (context.strings.Count == 0) { data = null; return(false); } string[] output = context.strings.ToArray(); if (calType == CAL_SABBREVERASTRING || calType == CAL_SERASTRING) { // Eras are enumerated backwards. (oldest era name first, but // Japanese calendar has newest era first in array, and is only // calendar with multiple eras) Array.Reverse(output, 0, output.Length); } data = output; return(true); }