From 8366f6ad79645de6543ccfb006812ae461e4132e Mon Sep 17 00:00:00 2001 From: Meri Khamoyan <96171496+mkhamoyan@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:19:03 +0200 Subject: [PATCH] [iOS][HybridGlobalization] Make consistent HybridGlobalization checks (#104082) Make hybrid globalization checks consistent --- .../System/Globalization/CalendarData.Icu.cs | 8 ++++--- .../System/Globalization/CultureData.Icu.cs | 10 ++++---- .../src/System/Globalization/CultureData.cs | 23 +++++++++---------- .../System/Globalization/Normalization.Icu.cs | 22 ++++++++++-------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index 26919ba0d50a8..52574e16d4ec5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -92,12 +92,14 @@ internal static int IcuGetCalendars(string localeName, CalendarId[] calendars) int count; #if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) + { count = Interop.Globalization.GetCalendarsNative(localeName, calendars, calendars.Length); + } else - count = Interop.Globalization.GetCalendars(localeName, calendars, calendars.Length); -#else - count = Interop.Globalization.GetCalendars(localeName, calendars, calendars.Length); #endif + { + count = Interop.Globalization.GetCalendars(localeName, calendars, calendars.Length); + } // ensure there is at least 1 calendar returned if (count == 0 && calendars.Length > 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs index cb38cba43e3b6..4d0c7156238e6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs @@ -521,12 +521,11 @@ private static CultureInfo[] IcuEnumCultures(CultureTypes types) bufferLength = Interop.Globalization.GetLocalesNative(null, 0); } else +#endif { bufferLength = Interop.Globalization.GetLocales(null, 0); } -#else - bufferLength = Interop.Globalization.GetLocales(null, 0); -#endif + if (bufferLength <= 0) { return Array.Empty(); @@ -540,12 +539,11 @@ private static CultureInfo[] IcuEnumCultures(CultureTypes types) bufferLength = Interop.Globalization.GetLocalesNative(chars, bufferLength); } else +#endif { bufferLength = Interop.Globalization.GetLocales(chars, bufferLength); } -#else - bufferLength = Interop.Globalization.GetLocales(chars, bufferLength); -#endif + if (bufferLength <= 0) { return Array.Empty(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index ed28dd5147a92..dba31f533c9ad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -976,11 +976,10 @@ internal string DisplayName private string GetLanguageDisplayNameCore(string cultureName) => GlobalizationMode.UseNls ? NlsGetLanguageDisplayName(cultureName) : #if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - GlobalizationMode.Hybrid ? GetLocaleInfoNative(cultureName, LocaleStringData.LocalizedDisplayName, CultureInfo.CurrentUICulture.Name) : - IcuGetLanguageDisplayName(cultureName); -#else - IcuGetLanguageDisplayName(cultureName); + GlobalizationMode.Hybrid ? + GetLocaleInfoNative(cultureName, LocaleStringData.LocalizedDisplayName, CultureInfo.CurrentUICulture.Name) : #endif + IcuGetLanguageDisplayName(cultureName); /// /// English pretty name for this locale (ie: English (United States)) @@ -1545,7 +1544,11 @@ internal int FirstDayOfWeek if (_iFirstDayOfWeek == undef && !GlobalizationMode.Invariant) { #if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - _iFirstDayOfWeek = GlobalizationMode.Hybrid ? GetLocaleInfoNative(LocaleNumberData.FirstDayOfWeek) : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); + if (GlobalizationMode.Hybrid) + { + _iFirstDayOfWeek = GetLocaleInfoNative(LocaleNumberData.FirstDayOfWeek); + } + else #elif TARGET_BROWSER if (GlobalizationMode.Hybrid) { @@ -1553,12 +1556,10 @@ internal int FirstDayOfWeek _iFirstDayOfWeek = GetFirstDayOfWeek(_sName); } else +#endif { - _iFirstDayOfWeek = IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); + _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); } -#else - _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); -#endif } return _iFirstDayOfWeek; } @@ -1581,12 +1582,10 @@ internal int CalendarWeekRule _iFirstWeekOfYear = GetFirstWeekOfYear(_sName); } else +#endif { _iFirstWeekOfYear = GetLocaleInfoCoreUserOverride(LocaleNumberData.FirstWeekOfYear); } -#else - _iFirstWeekOfYear = GetLocaleInfoCoreUserOverride(LocaleNumberData.FirstWeekOfYear); -#endif } return _iFirstWeekOfYear; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Icu.cs index c23a0cdae59f1..20ef88d440190 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Icu.cs @@ -22,12 +22,14 @@ private static unsafe bool IcuIsNormalized(string strInput, NormalizationForm no { #if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) + { ret = Interop.Globalization.IsNormalizedNative(normalizationForm, pInput, strInput.Length); + } else - ret = Interop.Globalization.IsNormalized(normalizationForm, pInput, strInput.Length); -#else - ret = Interop.Globalization.IsNormalized(normalizationForm, pInput, strInput.Length); #endif + { + ret = Interop.Globalization.IsNormalized(normalizationForm, pInput, strInput.Length); + } } if (ret == -1) @@ -61,13 +63,15 @@ private static unsafe string IcuNormalize(string strInput, NormalizationForm nor fixed (char* pDest = &MemoryMarshal.GetReference(buffer)) { #if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - if (GlobalizationMode.Hybrid) - realLen = Interop.Globalization.NormalizeStringNative(normalizationForm, pInput, strInput.Length, pDest, buffer.Length); - else - realLen = Interop.Globalization.NormalizeString(normalizationForm, pInput, strInput.Length, pDest, buffer.Length); -#else - realLen = Interop.Globalization.NormalizeString(normalizationForm, pInput, strInput.Length, pDest, buffer.Length); + if (GlobalizationMode.Hybrid) + { + realLen = Interop.Globalization.NormalizeStringNative(normalizationForm, pInput, strInput.Length, pDest, buffer.Length); + } + else #endif + { + realLen = Interop.Globalization.NormalizeString(normalizationForm, pInput, strInput.Length, pDest, buffer.Length); + } } if (realLen == -1)