From a794ba17fb6c79c3167491456e7a791c1d35d14b Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 27 Jun 2024 10:29:39 +0200 Subject: [PATCH 1/3] make consistent hybrid checks --- .../System/Globalization/CalendarData.Icu.cs | 7 +++++-- .../System/Globalization/CultureData.Icu.cs | 6 ++---- .../src/System/Globalization/CultureData.cs | 18 ++++++++++-------- .../System/Globalization/Normalization.Icu.cs | 12 +++++++++--- 4 files changed, 26 insertions(+), 17 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..a1aa56bb255d6 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,11 +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); + { + count = Interop.Globalization.GetCalendars(localeName, calendars, calendars.Length); + } #endif // ensure there is at least 1 calendar returned 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..2a0a49643b55e 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,11 +521,10 @@ private static CultureInfo[] IcuEnumCultures(CultureTypes types) bufferLength = Interop.Globalization.GetLocalesNative(null, 0); } else +#else { bufferLength = Interop.Globalization.GetLocales(null, 0); } -#else - bufferLength = Interop.Globalization.GetLocales(null, 0); #endif if (bufferLength <= 0) { @@ -540,11 +539,10 @@ private static CultureInfo[] IcuEnumCultures(CultureTypes types) bufferLength = Interop.Globalization.GetLocalesNative(chars, bufferLength); } else +#else { bufferLength = Interop.Globalization.GetLocales(chars, bufferLength); } -#else - bufferLength = Interop.Globalization.GetLocales(chars, bufferLength); #endif if (bufferLength <= 0) { 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..4fbf80bd36a4f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -976,8 +976,8 @@ 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); + GlobalizationMode.Hybrid ? + GetLocaleInfoNative(cultureName, LocaleStringData.LocalizedDisplayName, CultureInfo.CurrentUICulture.Name) : #else IcuGetLanguageDisplayName(cultureName); #endif @@ -1545,7 +1545,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,11 +1557,10 @@ internal int FirstDayOfWeek _iFirstDayOfWeek = GetFirstDayOfWeek(_sName); } else +#else { - _iFirstDayOfWeek = IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); + _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); } -#else - _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); #endif } return _iFirstDayOfWeek; @@ -1581,11 +1584,10 @@ internal int CalendarWeekRule _iFirstWeekOfYear = GetFirstWeekOfYear(_sName); } else +#else { _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..aaa81d86d519d 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,11 +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); + { + ret = Interop.Globalization.IsNormalized(normalizationForm, pInput, strInput.Length); + } #endif } @@ -62,11 +65,14 @@ private static unsafe string IcuNormalize(string strInput, NormalizationForm nor { #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); + } #endif } From 13d5e00f12f9253897d8ef6f742719cc541629db Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 27 Jun 2024 11:02:49 +0200 Subject: [PATCH 2/3] fix --- .../System/Globalization/CalendarData.Icu.cs | 3 +-- .../System/Globalization/CultureData.Icu.cs | 8 ++++---- .../src/System/Globalization/CultureData.cs | 6 ++---- .../System/Globalization/Normalization.Icu.cs | 20 +++++++++---------- 4 files changed, 16 insertions(+), 21 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 a1aa56bb255d6..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 @@ -96,11 +96,10 @@ internal static int IcuGetCalendars(string localeName, CalendarId[] calendars) count = Interop.Globalization.GetCalendarsNative(localeName, calendars, calendars.Length); } else -#else +#endif { count = Interop.Globalization.GetCalendars(localeName, calendars, calendars.Length); } -#endif // 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 2a0a49643b55e..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,11 +521,11 @@ private static CultureInfo[] IcuEnumCultures(CultureTypes types) bufferLength = Interop.Globalization.GetLocalesNative(null, 0); } else -#else +#endif { bufferLength = Interop.Globalization.GetLocales(null, 0); } -#endif + if (bufferLength <= 0) { return Array.Empty(); @@ -539,11 +539,11 @@ private static CultureInfo[] IcuEnumCultures(CultureTypes types) bufferLength = Interop.Globalization.GetLocalesNative(chars, bufferLength); } else -#else +#endif { 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 4fbf80bd36a4f..8453670b5acf7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -978,9 +978,8 @@ private string GetLanguageDisplayNameCore(string cultureName) => GlobalizationMo #if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS GlobalizationMode.Hybrid ? GetLocaleInfoNative(cultureName, LocaleStringData.LocalizedDisplayName, CultureInfo.CurrentUICulture.Name) : -#else - IcuGetLanguageDisplayName(cultureName); #endif + IcuGetLanguageDisplayName(cultureName); /// /// English pretty name for this locale (ie: English (United States)) @@ -1557,11 +1556,10 @@ internal int FirstDayOfWeek _iFirstDayOfWeek = GetFirstDayOfWeek(_sName); } else -#else +#endif { _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); } -#endif } return _iFirstDayOfWeek; } 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 aaa81d86d519d..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 @@ -26,11 +26,10 @@ private static unsafe bool IcuIsNormalized(string strInput, NormalizationForm no ret = Interop.Globalization.IsNormalizedNative(normalizationForm, pInput, strInput.Length); } else -#else +#endif { ret = Interop.Globalization.IsNormalized(normalizationForm, pInput, strInput.Length); } -#endif } if (ret == -1) @@ -64,16 +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 -#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) From b42a1b13eaeea0787ffc59f0bb83f446389bc760 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 27 Jun 2024 13:04:34 +0200 Subject: [PATCH 3/3] fix browser build failure --- .../src/System/Globalization/CultureData.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 8453670b5acf7..dba31f533c9ad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -1582,11 +1582,10 @@ internal int CalendarWeekRule _iFirstWeekOfYear = GetFirstWeekOfYear(_sName); } else -#else +#endif { _iFirstWeekOfYear = GetLocaleInfoCoreUserOverride(LocaleNumberData.FirstWeekOfYear); } -#endif } return _iFirstWeekOfYear; }