Skip to content

Commit

Permalink
[iOS][HybridGlobalization] Make consistent HybridGlobalization checks (
Browse files Browse the repository at this point in the history
…#104082)

Make hybrid globalization checks consistent
  • Loading branch information
mkhamoyan authored Jul 1, 2024
1 parent daadf8e commit 8366f6a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CultureInfo>();
Expand All @@ -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<CultureInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// English pretty name for this locale (ie: English (United States))
Expand Down Expand Up @@ -1545,20 +1544,22 @@ 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)
{
Debug.Assert(_sName != null, "[FirstDayOfWeek] Expected _sName to be populated already");
_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;
}
Expand All @@ -1581,12 +1582,10 @@ internal int CalendarWeekRule
_iFirstWeekOfYear = GetFirstWeekOfYear(_sName);
}
else
#endif
{
_iFirstWeekOfYear = GetLocaleInfoCoreUserOverride(LocaleNumberData.FirstWeekOfYear);
}
#else
_iFirstWeekOfYear = GetLocaleInfoCoreUserOverride(LocaleNumberData.FirstWeekOfYear);
#endif
}
return _iFirstWeekOfYear;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8366f6a

Please sign in to comment.