From f8e72d8c676782bd2815e12fb82fa3f959a244da Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 1 Feb 2023 11:43:15 +0100 Subject: [PATCH 01/25] Initial changes for GetLocaleInfoString --- .../src/Interop/Interop.Collation.iOS.cs | 52 +++++ .../Common/src/Interop/Interop.Locale.iOS.cs | 41 ++++ .../tests/HybridGlobalizationTests.iOS.cs | 0 .../System.Private.CoreLib.Shared.projitems | 5 + .../src/System/Globalization/CompareInfo.cs | 8 + .../System/Globalization/CompareInfo.iOS.cs | 36 ++++ .../System/Globalization/CultureData.Unix.cs | 2 +- .../src/System/Globalization/CultureData.cs | 28 ++- .../System/Globalization/CultureData.iOS.cs | 156 +++++++++++++++ .../System/Globalization/GlobalizationMode.cs | 2 + .../System.Globalization.Native/entrypoints.c | 3 + .../System.Globalization.Native/pal_locale.c | 23 +++ .../System.Globalization.Native/pal_locale.h | 2 + .../System.Globalization.Native/pal_locale.m | 180 ++++++++++++++++++ .../pal_localeStringData.c | 24 +++ .../pal_localeStringData.h | 7 + .../pal_locale_internal.h | 31 +++ src/tasks/AppleAppBuilder/AppleAppBuilder.cs | 5 + 18 files changed, 597 insertions(+), 8 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Interop.Collation.iOS.cs create mode 100644 src/libraries/Common/src/Interop/Interop.Locale.iOS.cs create mode 100644 src/libraries/System.Globalization/tests/HybridGlobalizationTests.iOS.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs diff --git a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs new file mode 100644 index 00000000000000..2e00e1a6cc8074 --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// check this file +using System; +using System.Globalization; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Globalization + { + /*[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "Native_GetSortHandle", StringMarshalling = StringMarshalling.Utf8)] + internal static unsafe partial ResultCode GetSortHandle(string localeName, out IntPtr sortHandle); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CloseSortHandle")] + internal static partial void CloseSortHandle(IntPtr handle); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CompareString", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int CompareString(IntPtr sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IndexOf", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int IndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LastIndexOf", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int LastIndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWith", StringMarshalling = StringMarshalling.Utf16)] + [MethodImpl(MethodImplOptions.NoInlining)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static unsafe partial bool StartsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWith", StringMarshalling = StringMarshalling.Utf16)] + [MethodImpl(MethodImplOptions.NoInlining)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static unsafe partial bool EndsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWith", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool StartsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWith", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool EndsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKey", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int GetSortKey(IntPtr sortHandle, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")] + internal static partial int GetSortVersion(IntPtr sortHandle);*/ + } +} diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs new file mode 100644 index 00000000000000..c88388ba9722fc --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Globalization + { + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "Native_GetLocaleName", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static unsafe partial bool NativeGetLocaleName(string localeName, char* value, int valueLength); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "Native_GetLocaleInfoString", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static unsafe partial bool NativeGetLocaleInfoString(string localeName, uint localeStringData, char* value, int valueLength, string? uiLocaleName = null); + + /*[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleName", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static unsafe partial bool GetDefaultLocaleName(char* value, int valueLength); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsPredefinedLocale", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool IsPredefinedLocale(string localeName); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static unsafe partial bool GetLocaleTimeFormat(string localeName, [MarshalAs(UnmanagedType.Bool)] bool shortFormat, char* value, int valueLength); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoInt", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes", StringMarshalling = StringMarshalling.Utf16)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize); + + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocales", StringMarshalling = StringMarshalling.Utf16)] + internal static partial int GetLocales([Out] char[]? value, int valueLength);*/ + } +} diff --git a/src/libraries/System.Globalization/tests/HybridGlobalizationTests.iOS.cs b/src/libraries/System.Globalization/tests/HybridGlobalizationTests.iOS.cs new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index feafd3b2ff447b..3e2db13fa50021 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -343,9 +343,11 @@ + + @@ -1253,6 +1255,9 @@ Common\Interop\Interop.Locale.cs + + Common\Interop\Interop.Locale.iOS.cs + Common\Interop\Interop.Normalization.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs index f0e89f12deff9a..043430100fd7d0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs @@ -174,6 +174,12 @@ private void InitSort(CultureInfo culture) { NlsInitSortHandle(); } + else if (GlobalizationMode.Hybrid) + { + // Add hybrid code + //InitNativeSortHandle(); + IcuInitSortHandle(culture.InteropName!); + } else { IcuInitSortHandle(culture.InteropName!); @@ -487,6 +493,8 @@ private static void ThrowCompareOptionsCheckFailed(CompareOptions options) private unsafe int CompareStringCore(ReadOnlySpan string1, ReadOnlySpan string2, CompareOptions options) => GlobalizationMode.UseNls ? NlsCompareString(string1, string2, options) : + /*GlobalizationMode.Hybrid ? + NativeCompareString(string1, string2, options) :*/ IcuCompareString(string1, string2, options); /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs new file mode 100644 index 00000000000000..a109c3f233b7fc --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Buffers; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Text; + +namespace System.Globalization +{ + public partial class CompareInfo + { + private void InitNativeSortHandle(string interopCultureName) + { + if (GlobalizationMode.Invariant) + { + _isAsciiEqualityOrdinal = true; + } + else + { + Debug.Assert(!GlobalizationMode.UseNls); + Debug.Assert(interopCultureName != null); + + // Inline the following condition to avoid potential implementation cycles within globalization + // + // _isAsciiEqualityOrdinal = _sortName == "" || _sortName == "en" || _sortName.StartsWith("en-", StringComparison.Ordinal); + // + /* _isAsciiEqualityOrdinal = _sortName.Length == 0 || + (_sortName.Length >= 2 && _sortName[0] == 'e' && _sortName[1] == 'n' && (_sortName.Length == 2 || _sortName[2] == '-')); + + _sortHandle = SortHandleCache.GetCachedSortHandle(interopCultureName);*/ + } + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index 2a253d5367be30..5d25e8e55ac7de 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -7,7 +7,7 @@ namespace System.Globalization { internal sealed partial class CultureData { - private bool InitCultureDataCore() => InitIcuCultureDataCore(); + private bool InitCultureDataCore() => GlobalizationMode.Hybrid ? InitNativeCultureDataCore() : InitIcuCultureDataCore(); // Unix doesn't support user overrides partial void InitUserOverride(bool useUserOverride); 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 079441b08d2e99..bc6ef7cc92f67d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -1541,7 +1541,9 @@ internal int FirstDayOfWeek { if (_iFirstDayOfWeek == undef && !GlobalizationMode.Invariant) { - _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); + _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() + //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(LocaleNumberData.FirstDayOfWeek) + : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); } return _iFirstDayOfWeek; } @@ -2286,7 +2288,9 @@ private int GetLocaleInfoCore(LocaleNumberData type) if (GlobalizationMode.Invariant) return 0; - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) + //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) + : IcuGetLocaleInfo(type); } private int GetLocaleInfoCoreUserOverride(LocaleNumberData type) @@ -2295,7 +2299,9 @@ private int GetLocaleInfoCoreUserOverride(LocaleNumberData type) if (GlobalizationMode.Invariant) return 0; - return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); + return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) + //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) + : IcuGetLocaleInfo(type); } private string GetLocaleInfoCoreUserOverride(LocaleStringData type) @@ -2304,7 +2310,9 @@ private string GetLocaleInfoCoreUserOverride(LocaleStringData type) if (GlobalizationMode.Invariant) return null!; - return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); + return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) + : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) + : IcuGetLocaleInfo(type); } private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = null) @@ -2313,7 +2321,9 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = if (GlobalizationMode.Invariant) return null!; - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) + : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type, uiCultureName) + : IcuGetLocaleInfo(type, uiCultureName); } private string GetLocaleInfoCore(string localeName, LocaleStringData type, string? uiCultureName = null) @@ -2322,7 +2332,9 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin if (GlobalizationMode.Invariant) return null!; - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) + : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(localeName, type, uiCultureName) + : IcuGetLocaleInfo(localeName, type, uiCultureName); } private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) @@ -2331,7 +2343,9 @@ private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) if (GlobalizationMode.Invariant) return null!; - return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); + return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) + //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) + : IcuGetLocaleInfo(type); } /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs new file mode 100644 index 00000000000000..1e4dd7e859f8fd --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -0,0 +1,156 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace System.Globalization +{ + internal sealed partial class CultureData + { + // Native constants, check if we need this for native + private const int Native_ULOC_KEYWORD_AND_VALUES_CAPACITY = 100; // max size of keyword or value + private const int Native_ULOC_FULLNAME_CAPACITY = 157; // max size of locale name + + /// + /// This method uses the sRealName field (which is initialized by the constructor before this is called) to + /// initialize the rest of the state of CultureData based on the underlying OS globalization library. + /// + private bool InitNativeCultureDataCore() + { + Debug.Assert(_sRealName != null); + Debug.Assert(!GlobalizationMode.Invariant); + string realNameBuffer = _sRealName; + /* const string ICU_COLLATION_KEYWORD = "@collation="; + + // Basic validation + if (!IsValidCultureName(realNameBuffer, out var index)) + { + return false; + } + + // Replace _ (alternate sort) with @collation= for ICU + ReadOnlySpan alternateSortName = default; + if (index > 0) + { + alternateSortName = realNameBuffer.AsSpan(index + 1); + realNameBuffer = string.Concat(realNameBuffer.AsSpan(0, index), ICU_COLLATION_KEYWORD, alternateSortName); + }*/ + + // Get the locale name + if (!NativeGetLocaleName(realNameBuffer, out _sWindowsName)) + { + return false; // fail + } + + /* // Replace the ICU collation keyword with an _ + Debug.Assert(_sWindowsName != null); + index = _sWindowsName.IndexOf(ICU_COLLATION_KEYWORD, StringComparison.Ordinal); + if (index >= 0) + { + // Use original culture name if alternateSortName is not set, which is possible even if the normalized + // culture name has "@collation=". + // "zh-TW-u-co-zhuyin" is a good example. The term "u-co-" means the following part will be the sort name + // and it will be treated in ICU as "zh-TW@collation=zhuyin". + _sName = alternateSortName.Length == 0 ? realNameBuffer : string.Concat(_sWindowsName.AsSpan(0, index), "_", alternateSortName); + } + else + { + _sName = _sWindowsName; + } + _sRealName = _sName; + + _iLanguage = LCID; + if (_iLanguage == 0) + { + _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED; + } + _bNeutral = TwoLetterISOCountryName.Length == 0; + // Implement for native + //_sSpecificCulture = _bNeutral ? IcuLocaleData.GetSpecificCultureName(_sRealName) : _sRealName; + // Remove the sort from sName unless custom culture + if (index > 0 && !_bNeutral && !IsCustomCultureId(_iLanguage)) + { + _sName = _sWindowsName.Substring(0, index); + }*/ + return true; + } + + internal static unsafe bool NativeGetLocaleName(string localeName, out string? windowsName) + { + // Is this needed for native? + // Get the locale name from ICU + char* buffer = stackalloc char[Native_ULOC_FULLNAME_CAPACITY]; + if (!Interop.Globalization.NativeGetLocaleName(localeName, buffer, Native_ULOC_FULLNAME_CAPACITY)) + { + windowsName = null; + return false; // fail + } + + // Success - use the locale name returned which may be different than realNameBuffer (casing) + windowsName = new string(buffer); // the name passed to subsequent ICU calls + return true; + } + + private string NativeGetLocaleInfo(LocaleStringData type, string? uiCultureName = null) + { + Debug.Assert(!GlobalizationMode.Invariant); + Debug.Assert(!GlobalizationMode.UseNls); + Debug.Assert(_sWindowsName != null, "[CultureData.NativeGetLocaleInfo] Expected _sWindowsName to be populated already"); + return NativeGetLocaleInfo(_sWindowsName, type, uiCultureName); + } + + // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the + // "windows" name, which can be specific for downlevel (< windows 7) os's. + private unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData type, string? uiCultureName = null) + { + Debug.Assert(!GlobalizationMode.UseNls); + Debug.Assert(localeName != null, "[CultureData.NativeGetLocaleInfo] Expected localeName to be not be null"); + + /*switch (type) + { + case LocaleStringData.NegativeInfinitySymbol: + // not an equivalent in ICU; prefix the PositiveInfinitySymbol with NegativeSign + return IcuGetLocaleInfo(localeName, LocaleStringData.NegativeSign) + + IcuGetLocaleInfo(localeName, LocaleStringData.PositiveInfinitySymbol); + }*/ + + char* buffer = stackalloc char[Native_ULOC_KEYWORD_AND_VALUES_CAPACITY]; + // this buffer is initialized + bool result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, buffer, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); + if (!result) + { + // Failed, just use empty string + Debug.Fail("[CultureData.NativeGetLocaleInfo(LocaleStringData)] Failed"); + return string.Empty; + } + return new string(buffer); + } + + /*private int NativeGetLocaleInfo(LocaleNumberData type) + { + Debug.Assert(!GlobalizationMode.UseNls); + + Debug.Assert(_sWindowsName != null, "[CultureData.NativeGetLocaleInfoInt(LocaleNumberData)] Expected _sWindowsName to be populated already"); + + switch (type) + { + case LocaleNumberData.CalendarType: + // returning 0 will cause the first supported calendar to be returned, which is the preferred calendar + return 0; + } + + + int value = 0; + bool result = Interop.Globalization.NativeGetLocaleInfoInt(_sWindowsName, (uint)type, ref value); + if (!result) + { + // Failed, just use 0 + Debug.Fail("[CultureData.NativeGetLocaleInfoInt(LocaleNumberData)] failed"); + } + + return value; + }*/ + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index 4f69f980150412..9b0d9429e5ba18 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -13,6 +13,7 @@ internal static partial class GlobalizationMode private static partial class Settings { internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); + internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", GlobalizationMode.Invariant); } @@ -20,6 +21,7 @@ private static partial class Settings // This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings // static cctor (on Unix) to be preserved when Invariant=false. internal static bool Invariant => Settings.Invariant; + internal static bool Hybrid => Settings.Hybrid; internal static bool PredefinedCulturesOnly => Settings.PredefinedCulturesOnly; private static bool TryGetAppLocalIcuSwitchValue([NotNullWhen(true)] out string? value) => diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 8d4901f62dcf6d..7c7710ee441348 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -24,6 +24,7 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_ChangeCaseTurkish) DllImportEntry(GlobalizationNative_CloseSortHandle) DllImportEntry(GlobalizationNative_CompareString) + //DllImportEntry(Native_CompareString) DllImportEntry(GlobalizationNative_EndsWith) DllImportEntry(GlobalizationNative_EnumCalendarInfo) DllImportEntry(GlobalizationNative_GetCalendarInfo) @@ -35,6 +36,8 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_GetLocaleInfoGroupingSizes) DllImportEntry(GlobalizationNative_GetLocaleInfoInt) DllImportEntry(GlobalizationNative_GetLocaleInfoString) + DllImportEntry(Native_GetLocaleName) + DllImportEntry(Native_GetLocaleInfoString) DllImportEntry(GlobalizationNative_GetLocaleName) DllImportEntry(GlobalizationNative_GetLocales) DllImportEntry(GlobalizationNative_GetLocaleTimeFormat) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.c b/src/native/libs/System.Globalization.Native/pal_locale.c index eada9f12ddd39f..32ce3f5c424b52 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.c +++ b/src/native/libs/System.Globalization.Native/pal_locale.c @@ -212,6 +212,29 @@ int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, return UErrorCodeToBool(status); } +int32_t Native_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength) +{ + UErrorCode status = U_ZERO_ERROR; + + /* char localeNameBuffer[ULOC_FULLNAME_CAPACITY]; + GetLocale(localeName, localeNameBuffer, ULOC_FULLNAME_CAPACITY, true, &status); + u_charsToUChars_safe(localeNameBuffer, value, valueLength, &status); + + if (U_SUCCESS(status)) + { + FixupLocaleName(value, valueLength); + }*/ + +#ifdef __APPLE__ + + return NativeGetLocaleName(localeName, + value, + valueLength); +#endif + + return UErrorCodeToBool(status); +} + int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength) { char localeNameBuffer[ULOC_FULLNAME_CAPACITY]; diff --git a/src/native/libs/System.Globalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_locale.h index 1180c4919f4028..10cb152d1934a4 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_locale.h @@ -9,6 +9,8 @@ PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLeng PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); +PALEXPORT int32_t Native_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); + PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName); diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index f574b9d14797e3..f0572faf5d49f5 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -5,6 +5,7 @@ #include "pal_locale_internal.h" #import +#include "pal_localeStringData.h" char* DetectDefaultAppleLocaleName() { @@ -28,3 +29,182 @@ return strdup([localeName UTF8String]); } +/*NSLocale * NativeGetSortHandle() +{ + NSLocale *currentLocale = [NSLocale currentLocale]; + + return currentLocale; +}*/ +int32_t NativeGetLocaleName(const UChar* localeName, + UChar* value, + int32_t valueLength) +{ + UErrorCode status = U_ZERO_ERROR; + NSLocale *currentLocale = [NSLocale currentLocale]; + value = (UChar *)[currentLocale.localeIdentifier UTF8String]; + return UErrorCodeToBool(status); +} + + +int32_t NativeGetLocaleInfoString(const UChar* localeName, + LocaleStringData localeStringData, + UChar* value, + int32_t valueLength, + const UChar* uiLocaleName) +{ + NSLocale *currentLocale = [NSLocale currentLocale]; + + UErrorCode status = U_ZERO_ERROR; + // char locale[ULOC_FULLNAME_CAPACITY] = ""; + // char uiLocale[ULOC_FULLNAME_CAPACITY] = ""; +// for icu + // GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &status); + + if (U_FAILURE(status)) + { + return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR); + } + + switch (localeStringData) + { + case LocaleString_LocalizedDisplayName: + value = (UChar *)[[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; + break; + case LocaleString_EnglishDisplayName: + value = (UChar *)[currentLocale.localeIdentifier UTF8String]; + break; + case LocaleString_NativeDisplayName: + value = (UChar *)[currentLocale.localeIdentifier UTF8String]; + break; + case LocaleString_LocalizedLanguageName: + value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + break; + case LocaleString_EnglishLanguageName: + value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + break; + case LocaleString_NativeLanguageName: + value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + break; + case LocaleString_EnglishCountryName: + value = (UChar *)[[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + break; + case LocaleString_NativeCountryName: + value = (UChar *)[[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + break; + case LocaleString_ThousandSeparator: + value = (UChar *)[currentLocale.groupingSeparator UTF8String]; + break; + case LocaleString_DecimalSeparator: + value = (UChar *)[currentLocale.decimalSeparator UTF8String]; + break; + /*case LocaleString_Digits: + { + // Native digit can be more than one 16-bit character (e.g. ccp-Cakm-BD locale which using surrogate pairs to represent the native digit). + // We'll separate the native digits in the returned buffer by the character '\uFFFF'. + int32_t symbolLength = 0; + status = GetDigitSymbol(locale, status, UNUM_ZERO_DIGIT_SYMBOL, 0, value, valueLength, &symbolLength); + + int32_t charIndex = symbolLength; + + if (U_SUCCESS(status) && (uint32_t)charIndex < (uint32_t)valueLength) + { + value[charIndex++] = 0xFFFF; + + // symbols UNUM_ONE_DIGIT to UNUM_NINE_DIGIT are contiguous + for (int32_t symbol = UNUM_ONE_DIGIT_SYMBOL; symbol <= UNUM_NINE_DIGIT_SYMBOL && charIndex < valueLength - 3; symbol++) + { + status = GetDigitSymbol(locale, status, (UNumberFormatSymbol)symbol, charIndex, value, valueLength, &symbolLength); + charIndex += symbolLength; + if (!U_SUCCESS(status) || (uint32_t)charIndex >= (uint32_t)valueLength) + { + break; + } + + value[charIndex++] = 0xFFFF; + } + + if ((uint32_t)charIndex < (uint32_t)valueLength) + { + value[charIndex] = 0; + } + } + } + break; + case LocaleString_MonetarySymbol: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_CURRENCY_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_Iso4217MonetarySymbol: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INTL_CURRENCY_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_CurrencyEnglishName: + status = GetLocaleCurrencyName(locale, false, value, valueLength); + break; + case LocaleString_CurrencyNativeName: + status = GetLocaleCurrencyName(locale, true, value, valueLength); + break; + case LocaleString_MonetaryDecimalSeparator: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_MonetaryThousandSeparator: + status = + GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_AMDesignator: + status = GetLocaleInfoAmPm(locale, true, value, valueLength); + break; + case LocaleString_PMDesignator: + status = GetLocaleInfoAmPm(locale, false, value, valueLength); + break; + case LocaleString_PositiveSign: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PLUS_SIGN_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_NegativeSign: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MINUS_SIGN_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_Iso639LanguageTwoLetterName: + status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); + break; + case LocaleString_Iso639LanguageThreeLetterName: + status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); + break; + case LocaleString_Iso3166CountryName: + status = GetLocaleIso3166CountryName(locale, value, valueLength); + break; + case LocaleString_Iso3166CountryName2: + status = GetLocaleIso3166CountryCode(locale, value, valueLength); + break; + case LocaleString_NaNSymbol: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_NAN_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_PositiveInfinitySymbol: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INFINITY_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_ParentName: + { + // ICU supports lang[-script][-region][-variant] so up to 4 parents + // including invariant locale + char localeNameTemp[ULOC_FULLNAME_CAPACITY]; + + uloc_getParent(locale, localeNameTemp, ULOC_FULLNAME_CAPACITY, &status); + u_charsToUChars_safe(localeNameTemp, value, valueLength, &status); + if (U_SUCCESS(status)) + { + FixupLocaleName(value, valueLength); + } + break; + } + case LocaleString_PercentSymbol: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERCENT_SYMBOL, value, valueLength, NULL); + break; + case LocaleString_PerMilleSymbol: + status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERMILL_SYMBOL, value, valueLength, NULL); + break;*/ + default: + status = U_UNSUPPORTED_ERROR; + break; + } + + return UErrorCodeToBool(status); +} + + diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.c b/src/native/libs/System.Globalization.Native/pal_localeStringData.c index 9120b89bd329bd..b19f90526be8c6 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.c +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.c @@ -401,6 +401,30 @@ int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, return UErrorCodeToBool(status); } +/* +PAL Function: +GetLocaleInfoString + +Obtains string locale information. +Returns 1 for success, 0 otherwise +*/ +int32_t Native_GetLocaleInfoString(const UChar* localeName, + LocaleStringData localeStringData, + UChar* value, + int32_t valueLength, + const UChar* uiLocaleName) +{ +#ifdef __APPLE__ + + return NativeGetLocaleInfoString(localeName, + localeStringData, + value, + valueLength, + uiLocaleName); +#endif + +} + /* PAL Function: GetLocaleTimeFormat diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index 3d1d26f91b4ebf..f81479bc5b0b8f 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -6,6 +6,7 @@ #include "pal_locale.h" #include "pal_compiler.h" +#include "pal_localeStringData.h" // Enum that corresponds to managed enum CultureData.LocaleStringData. // The numeric values of the enum members match their Win32 counterparts. @@ -49,6 +50,12 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeNam int32_t valueLength, const UChar* uiLocaleName); +PALEXPORT int32_t Native_GetLocaleInfoString(const UChar* localeName, + LocaleStringData localeStringData, + UChar* value, + int32_t valueLength, + const UChar* uiLocaleName); + PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength); diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index c754554bbfdd55..b1996e038ae6ec 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -4,6 +4,7 @@ #pragma once #include "pal_icushim_internal.h" +#include "pal_localeStringData.h" /* Function: @@ -60,4 +61,34 @@ DetectDefaultSystemLocaleName Detects the default locale string for Apple platforms */ char* DetectDefaultAppleLocaleName(void); + +/* +Function: +NativeGetSortHandle + +NativeGetSortHandle for Apple platforms +*/ +//NSLocale* NativeGetSortHandle(void); + +/* +Function: +NativeGetLocaleName + +NativeGetLocaleName for Apple platforms +*/ +int32_t NativeGetLocaleName(const UChar* localeName, + UChar* value, + int32_t valueLength); + +/* +Function: +NativeGetLocaleInfoString + +NativeGetLocaleInfoString for Apple platforms +*/ +int32_t NativeGetLocaleInfoString(const UChar* localeName, + LocaleStringData localeStringData, + UChar* value, + int32_t valueLength, + const UChar* uiLocaleName); #endif diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 193e047efc68a9..4b131700962328 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -148,6 +148,11 @@ public string TargetOS /// public bool InvariantGlobalization { get; set; } + /// + /// Forces the runtime to use hybrid(icu files + native functions) mode + /// + public bool HybridGlobalization { get; set; } + /// /// Forces the runtime to use the interpreter /// From a82743d69b67e0d23445516561fbf37e3e51fe4b Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 1 Feb 2023 12:02:31 +0100 Subject: [PATCH 02/25] Remove CompareInfo changes --- .../src/Interop/Interop.Collation.iOS.cs | 52 ------------------- .../System.Private.CoreLib.Shared.projitems | 1 - .../src/System/Globalization/CompareInfo.cs | 8 --- .../System/Globalization/CompareInfo.iOS.cs | 36 ------------- .../System.Globalization.Native/entrypoints.c | 1 - .../System.Globalization.Native/pal_locale.m | 6 --- .../pal_locale_internal.h | 8 --- 7 files changed, 112 deletions(-) delete mode 100644 src/libraries/Common/src/Interop/Interop.Collation.iOS.cs delete mode 100644 src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs diff --git a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs deleted file mode 100644 index 2e00e1a6cc8074..00000000000000 --- a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// check this file -using System; -using System.Globalization; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Globalization - { - /*[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "Native_GetSortHandle", StringMarshalling = StringMarshalling.Utf8)] - internal static unsafe partial ResultCode GetSortHandle(string localeName, out IntPtr sortHandle); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CloseSortHandle")] - internal static partial void CloseSortHandle(IntPtr handle); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CompareString", StringMarshalling = StringMarshalling.Utf16)] - internal static unsafe partial int CompareString(IntPtr sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IndexOf", StringMarshalling = StringMarshalling.Utf16)] - internal static unsafe partial int IndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LastIndexOf", StringMarshalling = StringMarshalling.Utf16)] - internal static unsafe partial int LastIndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWith", StringMarshalling = StringMarshalling.Utf16)] - [MethodImpl(MethodImplOptions.NoInlining)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static unsafe partial bool StartsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWith", StringMarshalling = StringMarshalling.Utf16)] - [MethodImpl(MethodImplOptions.NoInlining)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static unsafe partial bool EndsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWith", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool StartsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWith", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool EndsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKey", StringMarshalling = StringMarshalling.Utf16)] - internal static unsafe partial int GetSortKey(IntPtr sortHandle, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")] - internal static partial int GetSortVersion(IntPtr sortHandle);*/ - } -} diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 3e2db13fa50021..56273dc05742b0 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -343,7 +343,6 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs index 043430100fd7d0..f0e89f12deff9a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs @@ -174,12 +174,6 @@ private void InitSort(CultureInfo culture) { NlsInitSortHandle(); } - else if (GlobalizationMode.Hybrid) - { - // Add hybrid code - //InitNativeSortHandle(); - IcuInitSortHandle(culture.InteropName!); - } else { IcuInitSortHandle(culture.InteropName!); @@ -493,8 +487,6 @@ private static void ThrowCompareOptionsCheckFailed(CompareOptions options) private unsafe int CompareStringCore(ReadOnlySpan string1, ReadOnlySpan string2, CompareOptions options) => GlobalizationMode.UseNls ? NlsCompareString(string1, string2, options) : - /*GlobalizationMode.Hybrid ? - NativeCompareString(string1, string2, options) :*/ IcuCompareString(string1, string2, options); /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs deleted file mode 100644 index a109c3f233b7fc..00000000000000 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Buffers; -using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; - -namespace System.Globalization -{ - public partial class CompareInfo - { - private void InitNativeSortHandle(string interopCultureName) - { - if (GlobalizationMode.Invariant) - { - _isAsciiEqualityOrdinal = true; - } - else - { - Debug.Assert(!GlobalizationMode.UseNls); - Debug.Assert(interopCultureName != null); - - // Inline the following condition to avoid potential implementation cycles within globalization - // - // _isAsciiEqualityOrdinal = _sortName == "" || _sortName == "en" || _sortName.StartsWith("en-", StringComparison.Ordinal); - // - /* _isAsciiEqualityOrdinal = _sortName.Length == 0 || - (_sortName.Length >= 2 && _sortName[0] == 'e' && _sortName[1] == 'n' && (_sortName.Length == 2 || _sortName[2] == '-')); - - _sortHandle = SortHandleCache.GetCachedSortHandle(interopCultureName);*/ - } - } - } -} diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 7c7710ee441348..0cadf4ddb08692 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -24,7 +24,6 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_ChangeCaseTurkish) DllImportEntry(GlobalizationNative_CloseSortHandle) DllImportEntry(GlobalizationNative_CompareString) - //DllImportEntry(Native_CompareString) DllImportEntry(GlobalizationNative_EndsWith) DllImportEntry(GlobalizationNative_EnumCalendarInfo) DllImportEntry(GlobalizationNative_GetCalendarInfo) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index f0572faf5d49f5..9b718a0b2d513e 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -29,12 +29,6 @@ return strdup([localeName UTF8String]); } -/*NSLocale * NativeGetSortHandle() -{ - NSLocale *currentLocale = [NSLocale currentLocale]; - - return currentLocale; -}*/ int32_t NativeGetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength) diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index b1996e038ae6ec..b850c7f4a3dfee 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -62,14 +62,6 @@ Detects the default locale string for Apple platforms */ char* DetectDefaultAppleLocaleName(void); -/* -Function: -NativeGetSortHandle - -NativeGetSortHandle for Apple platforms -*/ -//NSLocale* NativeGetSortHandle(void); - /* Function: NativeGetLocaleName From 954ed0f00218eaaf0ab479367275cd6e5ae23f1d Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 1 Feb 2023 14:02:26 +0100 Subject: [PATCH 03/25] Updated more cases --- .../System.Globalization.Native/pal_locale.m | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 9b718a0b2d513e..672e7dfca39529 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -91,8 +91,9 @@ int32_t NativeGetLocaleInfoString(const UChar* localeName, case LocaleString_DecimalSeparator: value = (UChar *)[currentLocale.decimalSeparator UTF8String]; break; - /*case LocaleString_Digits: - { + case LocaleString_Digits: + // TODO + /*{ // Native digit can be more than one 16-bit character (e.g. ccp-Cakm-BD locale which using surrogate pairs to represent the native digit). // We'll separate the native digits in the returned buffer by the character '\uFFFF'. int32_t symbolLength = 0; @@ -122,60 +123,73 @@ int32_t NativeGetLocaleInfoString(const UChar* localeName, value[charIndex] = 0; } } - } + }*/ break; case LocaleString_MonetarySymbol: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_CURRENCY_SYMBOL, value, valueLength, NULL); + value = (UChar *)[currentLocale.currencySymbol UTF8String]; break; case LocaleString_Iso4217MonetarySymbol: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INTL_CURRENCY_SYMBOL, value, valueLength, NULL); + // check if this is correct + value = (UChar *)[currentLocale.currencySymbol UTF8String]; break; case LocaleString_CurrencyEnglishName: - status = GetLocaleCurrencyName(locale, false, value, valueLength); + value = (UChar *)[[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; break; case LocaleString_CurrencyNativeName: - status = GetLocaleCurrencyName(locale, true, value, valueLength); + value = (UChar *)[[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; break; case LocaleString_MonetaryDecimalSeparator: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength, NULL); + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength, NULL); break; case LocaleString_MonetaryThousandSeparator: - status = - GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength, NULL); + // TODO + /*status = + GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength, NULL);*/ break; case LocaleString_AMDesignator: - status = GetLocaleInfoAmPm(locale, true, value, valueLength); + // TODO + //status = GetLocaleInfoAmPm(locale, true, value, valueLength); break; case LocaleString_PMDesignator: - status = GetLocaleInfoAmPm(locale, false, value, valueLength); + // TODO + //status = GetLocaleInfoAmPm(locale, false, value, valueLength); break; case LocaleString_PositiveSign: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PLUS_SIGN_SYMBOL, value, valueLength, NULL); + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PLUS_SIGN_SYMBOL, value, valueLength, NULL); break; case LocaleString_NegativeSign: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MINUS_SIGN_SYMBOL, value, valueLength, NULL); + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MINUS_SIGN_SYMBOL, value, valueLength, NULL); break; case LocaleString_Iso639LanguageTwoLetterName: - status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); + // TODO + //status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); break; case LocaleString_Iso639LanguageThreeLetterName: - status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); + // TODO + //status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); break; case LocaleString_Iso3166CountryName: - status = GetLocaleIso3166CountryName(locale, value, valueLength); + // TODO + //status = GetLocaleIso3166CountryName(locale, value, valueLength); break; case LocaleString_Iso3166CountryName2: - status = GetLocaleIso3166CountryCode(locale, value, valueLength); + // TODO + //status = GetLocaleIso3166CountryCode(locale, value, valueLength); break; case LocaleString_NaNSymbol: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_NAN_SYMBOL, value, valueLength, NULL); + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_NAN_SYMBOL, value, valueLength, NULL); break; case LocaleString_PositiveInfinitySymbol: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INFINITY_SYMBOL, value, valueLength, NULL); + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INFINITY_SYMBOL, value, valueLength, NULL); break; case LocaleString_ParentName: - { - // ICU supports lang[-script][-region][-variant] so up to 4 parents + // TODO + /* // ICU supports lang[-script][-region][-variant] so up to 4 parents // including invariant locale char localeNameTemp[ULOC_FULLNAME_CAPACITY]; @@ -184,15 +198,16 @@ int32_t NativeGetLocaleInfoString(const UChar* localeName, if (U_SUCCESS(status)) { FixupLocaleName(value, valueLength); - } + }*/ break; - } case LocaleString_PercentSymbol: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERCENT_SYMBOL, value, valueLength, NULL); + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERCENT_SYMBOL, value, valueLength, NULL); break; case LocaleString_PerMilleSymbol: - status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERMILL_SYMBOL, value, valueLength, NULL); - break;*/ + // TODO + //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERMILL_SYMBOL, value, valueLength, NULL); + break; default: status = U_UNSUPPORTED_ERROR; break; From 1362d457ea9eb84040e16cccfcdba131fcce6d9d Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 8 Feb 2023 10:51:06 +0100 Subject: [PATCH 04/25] updated hybrid mode property --- docs/workflow/trimming/feature-switches.md | 1 + eng/testing/tests.ioslike.targets | 1 + .../tests/TestUtilities/System/PlatformDetection.cs | 4 ++++ .../tests/HybridGlobalizationTests.iOS.cs | 0 .../src/ILLink/ILLink.Substitutions.Shared.xml | 2 ++ src/mono/msbuild/apple/build/AppleApp.targets | 1 + src/tasks/AppleAppBuilder/Templates/runtime.m | 4 ++++ src/tasks/AppleAppBuilder/Xcode.cs | 9 ++++++++- 8 files changed, 21 insertions(+), 1 deletion(-) delete mode 100644 src/libraries/System.Globalization/tests/HybridGlobalizationTests.iOS.cs diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index 7600b3d7d480b4..d8a46f517248bf 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -14,6 +14,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif | EventSourceSupport | System.Diagnostics.Tracing.EventSource.IsSupported | Any EventSource related code or logic is trimmed when set to false | | InvariantGlobalization | System.Globalization.Invariant | All globalization specific code and data is trimmed when set to true | | PredefinedCulturesOnly | System.Globalization.PredefinedCulturesOnly | Don't allow creating a culture for which the platform does not have data | +| HybridGlobalization | System.Globalization.Hybrid | Loading ICU + native implementations | | UseSystemResourceKeys | System.Resources.UseSystemResourceKeys | Any localizable resources for system assemblies is trimmed when set to true | | HttpActivityPropagationSupport | System.Net.Http.EnableActivityPropagation | Any dependency related to diagnostics support for System.Net.Http is trimmed when set to false | | UseNativeHttpHandler | System.Net.Http.UseNativeHttpHandler | HttpClient uses by default platform native implementation of HttpMessageHandler if set to true. | diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index 8b46d2d90122d5..7a90d8c24855e7 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -98,6 +98,7 @@ library test project. Eg. $(InvariantGlobalization) --> <_ApplePropertyNames Include="InvariantGlobalization" /> + <_ApplePropertyNames Include="HybridGlobalization" /> <_ApplePropertyNames Include="AssemblyName" /> <_ApplePropertyNames Include="MonoEnableLLVM" /> diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 9d81146e977cbe..67559904cd907d 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -344,6 +344,9 @@ public static string GetDistroVersionString() private static readonly Lazy m_isInvariant = new Lazy(() => (bool?)Type.GetType("System.Globalization.GlobalizationMode")?.GetProperty("Invariant", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) == true); + private static readonly Lazy m_isHybrid = new Lazy(() + => (bool?)Type.GetType("System.Globalization.GlobalizationMode")?.GetProperty("Hybrid", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) == true); + private static readonly Lazy m_icuVersion = new Lazy(GetICUVersion); public static Version ICUVersion => m_icuVersion.Value; @@ -351,6 +354,7 @@ public static string GetDistroVersionString() public static bool IsNotInvariantGlobalization => !IsInvariantGlobalization; public static bool IsIcuGlobalization => ICUVersion > new Version(0, 0, 0, 0); public static bool IsNlsGlobalization => IsNotInvariantGlobalization && !IsIcuGlobalization; + public static bool IsHybridGlobalization => m_isHybrid.Value; public static bool IsSubstAvailable { diff --git a/src/libraries/System.Globalization/tests/HybridGlobalizationTests.iOS.cs b/src/libraries/System.Globalization/tests/HybridGlobalizationTests.iOS.cs deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml index 9765f3ab4f662e..f919b0fe6d6f74 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml @@ -10,10 +10,12 @@ to be trimmed when Invariant=true, and allows for the Settings static cctor (on Unix) to be preserved when Invariant=false. --> + + diff --git a/src/mono/msbuild/apple/build/AppleApp.targets b/src/mono/msbuild/apple/build/AppleApp.targets index 7dd0c53d887a67..8d127b9648f55d 100644 --- a/src/mono/msbuild/apple/build/AppleApp.targets +++ b/src/mono/msbuild/apple/build/AppleApp.targets @@ -131,6 +131,7 @@ ForceInterpreter="$(MonoForceInterpreter)" EnableAppSandbox="$(EnableAppSandbox)" InvariantGlobalization="$(InvariantGlobalization)" + HybridGlobalization="$(HybridGlobalization)" UseConsoleUITemplate="True" GenerateXcodeProject="$(GenerateXcodeProject)" GenerateCMakeProject="$(GenerateCMakeProject)" diff --git a/src/tasks/AppleAppBuilder/Templates/runtime.m b/src/tasks/AppleAppBuilder/Templates/runtime.m index 1d0cd6ff0076f8..d01925d7ab8892 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime.m @@ -242,6 +242,10 @@ setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); #endif +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif + #if ENABLE_RUNTIME_LOGGING setenv ("MONO_LOG_LEVEL", "debug", TRUE); setenv ("MONO_LOG_MASK", "all", TRUE); diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index 227ff3752d2346..e8132cdcd9eff1 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -144,6 +144,7 @@ public string GenerateXCode( bool forceAOT, bool forceInterpreter, bool invariantGlobalization, + bool hybridGlobalization, bool optimized, bool enableRuntimeLogging, bool enableAppSandbox, @@ -151,7 +152,7 @@ public string GenerateXCode( string? runtimeComponents=null, string? nativeMainSource = null) { - var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource); + var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource); CreateXcodeProject(projectName, cmakeDirectoryPath); return Path.Combine(binDir, projectName, projectName + ".xcodeproj"); } @@ -202,6 +203,7 @@ public string GenerateCMake( bool forceAOT, bool forceInterpreter, bool invariantGlobalization, + bool hybridGlobalization, bool optimized, bool enableRuntimeLogging, bool enableAppSandbox, @@ -380,6 +382,11 @@ public string GenerateCMake( defines.AppendLine("add_definitions(-DINVARIANT_GLOBALIZATION=1)"); } + if (hybridGlobalization) + { + defines.AppendLine("add_definitions(-DHYBRID_GLOBALIZATION=1)"); + } + if (enableRuntimeLogging) { defines.AppendLine("add_definitions(-DENABLE_RUNTIME_LOGGING=1)"); From cb2368808b8bde5ec5796f048a85751bf86f0a2f Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 10 Feb 2023 13:26:57 +0100 Subject: [PATCH 05/25] update --- .../tests/CultureInfo/CultureInfoAll.cs | 1 + .../CultureInfo/CultureInfoEnglishName.cs | 4 + .../CultureInfo/CultureInfoNativeName.cs | 2 + .../tests/Hybrid/Hybrid.Tests.csproj | 13 ++ .../tests/Hybrid/HybridMode.cs | 179 ++++++++++++++++++ .../System/Globalization/CultureData.Unix.cs | 2 +- .../src/System/Globalization/CultureData.cs | 11 +- .../System/Globalization/CultureData.iOS.cs | 7 + .../System.Globalization.Native/pal_locale.m | 168 +++++++++------- .../pal_localeStringData.c | 9 +- .../pal_localeStringData.h | 1 + .../pal_locale_internal.h | 2 +- src/tasks/AppleAppBuilder/AppleAppBuilder.cs | 4 +- 13 files changed, 326 insertions(+), 77 deletions(-) create mode 100644 src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj create mode 100644 src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs index c82e17f11163c8..f621aac50eb951 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs @@ -826,6 +826,7 @@ public void CultureNotFoundExceptionTest() [Theory] [PlatformSpecific(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] // for these platforms cultures are taken from icu filters [InlineData("nb-NO")] + // check this test public void ContainsCulture(string culture) { var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 67a19e61401164..e1b319df9eb1ee 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -33,6 +33,10 @@ public static IEnumerable EnglishName_TestData() [MemberData(nameof(EnglishName_TestData))] public void EnglishName(string name, string expected) { + // Add here test + System.Console.WriteLine("Globalization mode is IsInvariantGlobalization: " + PlatformDetection.IsInvariantGlobalization); + System.Console.WriteLine("Globalization mode is IsHybridGlobalization: " + PlatformDetection.IsHybridGlobalization); + System.Console.WriteLine("Globalization log EnglishName: " + name); CultureInfo myTestCulture = new CultureInfo(name); Assert.Equal(expected, myTestCulture.EnglishName); } diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs index 8293613177688c..2f016ce394388e 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs @@ -30,6 +30,8 @@ public static IEnumerable NativeName_TestData() [MemberData(nameof(NativeName_TestData))] public void NativeName(string name, string expected) { + // Add here test + System.Console.WriteLine("Globalization log NativeName: " + name); CultureInfo myTestCulture = new CultureInfo(name); Assert.Equal(expected, myTestCulture.NativeName); } diff --git a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj new file mode 100644 index 00000000000000..85b9cc33534896 --- /dev/null +++ b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj @@ -0,0 +1,13 @@ + + + $(NetCoreAppCurrent) + true + true + false + false + true + + + + + \ No newline at end of file diff --git a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs new file mode 100644 index 00000000000000..4f492cede3bb01 --- /dev/null +++ b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs @@ -0,0 +1,179 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Buffers; +using System.Reflection; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using Xunit; + +namespace System.Globalization.Tests +{ + public class HybridModeTests + { + + public static IEnumerable Cultures_TestData() + { + yield return new object[] { "en-US" }; + /* yield return new object[] { "ja-JP" }; + yield return new object[] { "fr-FR" }; + yield return new object[] { "tr-TR" }; + yield return new object[] { "" };*/ + } + + //private static readonly string[] s_cultureNames = new string[] { "en-US", "ja-JP", "fr-FR", "tr-TR", "" }; + + //[ConditionalTheory(nameof(PredefinedCulturesOnlyIsDisabled))] + [Theory] + [MemberData(nameof(Cultures_TestData))] + public void TestCultureData(string cultureName) + { + CultureInfo ci = new CultureInfo(cultureName); + /* bool invariant = (bool) typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("InvariantGlobalization", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); + bool hybrid = (bool) typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("HybridGlobalization", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); + System.Console.WriteLine("Globalization mode is IsInvariantGlobalization: " + invariant); + System.Console.WriteLine("Globalization mode is HybridGlobalization: " + hybrid);*/ + // Add here test + // System.Console.WriteLine("Globalization mode is IsInvariantGlobalization: " + PlatformDetection.IsInvariantGlobalization); + // System.Console.WriteLine("Globalization mode is IsHybridGlobalization: " + PlatformDetection.IsHybridGlobalization); + System.Console.WriteLine("Globalization mode log EnglishName: " + ci.EnglishName); + // CultureInfo myTestCulture = new CultureInfo(name); + //Assert.Equal(expected, myTestCulture.EnglishName); + // + // DateTimeInfo + // + + /*Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedDayNames, ci.DateTimeFormat.AbbreviatedDayNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedMonthGenitiveNames, ci.DateTimeFormat.AbbreviatedMonthGenitiveNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedMonthNames, ci.DateTimeFormat.AbbreviatedMonthNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AMDesignator, ci.DateTimeFormat.AMDesignator); + Assert.True(ci.DateTimeFormat.Calendar is GregorianCalendar); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.CalendarWeekRule); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.DateSeparator, ci.DateTimeFormat.DateSeparator); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.DayNames, ci.DateTimeFormat.DayNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.FirstDayOfWeek, ci.DateTimeFormat.FirstDayOfWeek); + + for (DayOfWeek dow = DayOfWeek.Sunday; dow < DayOfWeek.Saturday; dow++) + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedDayName(dow), ci.DateTimeFormat.GetAbbreviatedDayName(dow)); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedEraName(1), ci.DateTimeFormat.GetAbbreviatedEraName(1)); + + for (int i = 1; i <= 12; i++) + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedMonthName(i), ci.DateTimeFormat.GetAbbreviatedMonthName(i)); + + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAllDateTimePatterns(), ci.DateTimeFormat.GetAllDateTimePatterns()); + + for (DayOfWeek dow = DayOfWeek.Sunday; dow < DayOfWeek.Saturday; dow++) + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetDayName(dow), ci.DateTimeFormat.GetDayName(dow)); + + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetEra(CultureInfo.InvariantCulture.DateTimeFormat.GetEraName(1)), ci.DateTimeFormat.GetEra(ci.DateTimeFormat.GetEraName(1))); + + for (int i = 1; i <= 12; i++) + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i), ci.DateTimeFormat.GetMonthName(i)); + for (DayOfWeek dow = DayOfWeek.Sunday; dow < DayOfWeek.Saturday; dow++) + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetShortestDayName(dow), ci.DateTimeFormat.GetShortestDayName(dow)); + + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.LongDatePattern, ci.DateTimeFormat.LongDatePattern); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.LongTimePattern, ci.DateTimeFormat.LongTimePattern); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.MonthDayPattern, ci.DateTimeFormat.MonthDayPattern); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.MonthGenitiveNames, ci.DateTimeFormat.MonthGenitiveNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.MonthNames, ci.DateTimeFormat.MonthNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.NativeCalendarName, ci.DateTimeFormat.NativeCalendarName); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.PMDesignator, ci.DateTimeFormat.PMDesignator); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern, ci.DateTimeFormat.RFC1123Pattern); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.ShortDatePattern, ci.DateTimeFormat.ShortDatePattern); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.ShortestDayNames, ci.DateTimeFormat.ShortestDayNames); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.ShortTimePattern, ci.DateTimeFormat.ShortTimePattern); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.TimeSeparator, ci.DateTimeFormat.TimeSeparator); + Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.YearMonthPattern, ci.DateTimeFormat.YearMonthPattern); + + // + // Culture data + // + + Assert.True(ci.Calendar is GregorianCalendar); + + CultureTypes ct = ci.Name == "" ? CultureInfo.InvariantCulture.CultureTypes : CultureInfo.InvariantCulture.CultureTypes | CultureTypes.UserCustomCulture; + Assert.Equal(ct, ci.CultureTypes); + Assert.Equal(CultureInfo.InvariantCulture.NativeName, ci.DisplayName); + Assert.Equal(CultureInfo.InvariantCulture.EnglishName, ci.EnglishName); + Assert.Equal(CultureInfo.InvariantCulture.GetConsoleFallbackUICulture(), ci.GetConsoleFallbackUICulture()); + Assert.Equal(cultureName, ci.IetfLanguageTag); + Assert.Equal(CultureInfo.InvariantCulture.IsNeutralCulture, ci.IsNeutralCulture); + Assert.Equal(CultureInfo.InvariantCulture.KeyboardLayoutId, ci.KeyboardLayoutId); + Assert.Equal(ci.Name == "" ? 0x7F : 0x1000, ci.LCID); + Assert.Equal(cultureName, ci.Name); + Assert.Equal(CultureInfo.InvariantCulture.NativeName, ci.NativeName); + Assert.Equal(1, ci.OptionalCalendars.Length); + Assert.True(ci.OptionalCalendars[0] is GregorianCalendar); + Assert.Equal(CultureInfo.InvariantCulture.Parent, ci.Parent); + Assert.Equal(CultureInfo.InvariantCulture.ThreeLetterISOLanguageName, ci.ThreeLetterISOLanguageName); + Assert.Equal(CultureInfo.InvariantCulture.ThreeLetterWindowsLanguageName, ci.ThreeLetterWindowsLanguageName); + Assert.Equal(CultureInfo.InvariantCulture.TwoLetterISOLanguageName, ci.TwoLetterISOLanguageName); + Assert.Equal(ci.Name == "" ? false : true, ci.UseUserOverride); + + // + // Culture Creations + // + Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.CurrentCulture); + Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.CurrentUICulture); + Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.InstalledUICulture); + Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.CreateSpecificCulture("en")); + Assert.Equal(ci, CultureInfo.GetCultureInfo(cultureName).Clone()); + Assert.Equal(ci, CultureInfo.GetCultureInfoByIetfLanguageTag(cultureName)); + + // + // NumberFormatInfo + // + + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalDigits, ci.NumberFormat.CurrencyDecimalDigits); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalSeparator, ci.NumberFormat.CurrencyDecimalSeparator); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyGroupSeparator, ci.NumberFormat.CurrencyGroupSeparator); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyGroupSizes, ci.NumberFormat.CurrencyGroupSizes); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyNegativePattern, ci.NumberFormat.CurrencyNegativePattern); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyPositivePattern, ci.NumberFormat.CurrencyPositivePattern); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencySymbol, ci.NumberFormat.CurrencySymbol); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.DigitSubstitution, ci.NumberFormat.DigitSubstitution); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NaNSymbol, ci.NumberFormat.NaNSymbol); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NativeDigits, ci.NumberFormat.NativeDigits); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NegativeInfinitySymbol, ci.NumberFormat.NegativeInfinitySymbol); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NegativeSign, ci.NumberFormat.NegativeSign); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberDecimalDigits, ci.NumberFormat.NumberDecimalDigits); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator, ci.NumberFormat.NumberDecimalSeparator); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberGroupSeparator, ci.NumberFormat.NumberGroupSeparator); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberGroupSizes, ci.NumberFormat.NumberGroupSizes); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberNegativePattern, ci.NumberFormat.NumberNegativePattern); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentDecimalDigits, ci.NumberFormat.PercentDecimalDigits); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentDecimalSeparator, ci.NumberFormat.PercentDecimalSeparator); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentGroupSeparator, ci.NumberFormat.PercentGroupSeparator); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentGroupSizes, ci.NumberFormat.PercentGroupSizes); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentNegativePattern, ci.NumberFormat.PercentNegativePattern); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentPositivePattern, ci.NumberFormat.PercentPositivePattern); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentSymbol, ci.NumberFormat.PercentSymbol); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PerMilleSymbol, ci.NumberFormat.PerMilleSymbol); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PositiveInfinitySymbol, ci.NumberFormat.PositiveInfinitySymbol); + Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PositiveSign, ci.NumberFormat.PositiveSign); + + // + // TextInfo + // + + Assert.Equal(CultureInfo.InvariantCulture.TextInfo.ANSICodePage, ci.TextInfo.ANSICodePage); + Assert.Equal(cultureName, ci.TextInfo.CultureName); + Assert.Equal(CultureInfo.InvariantCulture.TextInfo.EBCDICCodePage, ci.TextInfo.EBCDICCodePage); + Assert.Equal(CultureInfo.InvariantCulture.TextInfo.IsRightToLeft, ci.TextInfo.IsRightToLeft); + Assert.Equal(ci.Name == "" ? 0x7F : 0x1000, ci.TextInfo.LCID); + Assert.Equal(CultureInfo.InvariantCulture.TextInfo.ListSeparator, ci.TextInfo.ListSeparator); + Assert.Equal(CultureInfo.InvariantCulture.TextInfo.MacCodePage, ci.TextInfo.MacCodePage); + Assert.Equal(CultureInfo.InvariantCulture.TextInfo.OEMCodePage, ci.TextInfo.OEMCodePage); + + // + // CompareInfo + // + Assert.Equal(ci.Name == "" ? 0x7F : 0x1000, ci.CompareInfo.LCID); + Assert.True(cultureName.Equals(ci.CompareInfo.Name, StringComparison.OrdinalIgnoreCase));*/ + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index 5d25e8e55ac7de..db4ba3927876a3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -7,7 +7,7 @@ namespace System.Globalization { internal sealed partial class CultureData { - private bool InitCultureDataCore() => GlobalizationMode.Hybrid ? InitNativeCultureDataCore() : InitIcuCultureDataCore(); + private bool InitCultureDataCore() => InitIcuCultureDataCore(); //GlobalizationMode.Hybrid ? InitNativeCultureDataCore() : InitIcuCultureDataCore(); // Unix doesn't support user overrides partial void InitUserOverride(bool useUserOverride); 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 bc6ef7cc92f67d..b7a0b6dbba51b0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -969,15 +969,18 @@ internal string EnglishName get { string? englishDisplayName = _sEnglishDisplayName; + System.Diagnostics.Debug.Write("Globalization EnglishName get englishDisplayName: " + englishDisplayName); if (englishDisplayName == null && !GlobalizationMode.Invariant) { // If its neutral use the language name if (IsNeutralCulture) { englishDisplayName = GetLocaleInfoCore(LocaleStringData.EnglishDisplayName); + System.Diagnostics.Debug.Write("Globalization EnglishName get IsNeutralCulture englishDisplayName: " + englishDisplayName); if (string.IsNullOrEmpty(englishDisplayName)) { englishDisplayName = EnglishLanguageName; + System.Diagnostics.Debug.Write("Globalization EnglishName get IsNeutralCulture nested if englishDisplayName: " + englishDisplayName); } // differentiate the legacy display names @@ -992,10 +995,11 @@ internal string EnglishName else { englishDisplayName = GetLocaleInfoCore(LocaleStringData.EnglishDisplayName); - + System.Diagnostics.Debug.Write("Globalization EnglishName get else case englishDisplayName: " + englishDisplayName); // if it isn't found build one: if (string.IsNullOrEmpty(englishDisplayName)) { + System.Diagnostics.Debug.Write("Globalization EnglishName get still null englishDisplayName: " + englishDisplayName); // Our existing names mostly look like: // "English" + "United States" -> "English (United States)" // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)" @@ -1007,16 +1011,19 @@ internal string EnglishName ", ", EnglishCountryName, ")"); + System.Diagnostics.Debug.Write("Globalization EnglishName get concat englishDisplayName: " + englishDisplayName); } else { // "English" + "United States" -> "English (United States)" englishDisplayName = EnglishLanguageName + " (" + EnglishCountryName + ")"; + System.Diagnostics.Debug.Write("Globalization EnglishName get concat else englishDisplayName: " + englishDisplayName); } } } _sEnglishDisplayName = englishDisplayName; + System.Diagnostics.Debug.Write("Globalization EnglishName get final initialization englishDisplayName: " + englishDisplayName); } return englishDisplayName!; @@ -2320,7 +2327,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; - +// call this function return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index 1e4dd7e859f8fd..e25e1a4bf69cbe 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -82,6 +82,8 @@ internal static unsafe bool NativeGetLocaleName(string localeName, out string? w // Is this needed for native? // Get the locale name from ICU char* buffer = stackalloc char[Native_ULOC_FULLNAME_CAPACITY]; + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleName is called"); + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleName is called localeName: " + localeName); if (!Interop.Globalization.NativeGetLocaleName(localeName, buffer, Native_ULOC_FULLNAME_CAPACITY)) { windowsName = null; @@ -118,7 +120,12 @@ private unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData ty char* buffer = stackalloc char[Native_ULOC_KEYWORD_AND_VALUES_CAPACITY]; // this buffer is initialized + Debug.Write("Globalization NativeGetLocaleInfo is called"); + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called localeName: " + localeName); + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called type: " + type.ToString()); bool result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, buffer, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called result: " + result.ToString()); + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called buffer: " + new string(buffer)); if (!result) { // Failed, just use empty string diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 672e7dfca39529..6cb50b3d15bbef 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -5,6 +5,8 @@ #include "pal_locale_internal.h" #import +#import + #include "pal_localeStringData.h" char* DetectDefaultAppleLocaleName() @@ -40,180 +42,206 @@ int32_t NativeGetLocaleName(const UChar* localeName, } -int32_t NativeGetLocaleInfoString(const UChar* localeName, +UChar* NativeGetLocaleInfoString(const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName) { + NSLog(@"NSLog NativeGetLocaleInfoString is running"); NSLocale *currentLocale = [NSLocale currentLocale]; - - UErrorCode status = U_ZERO_ERROR; - // char locale[ULOC_FULLNAME_CAPACITY] = ""; - // char uiLocale[ULOC_FULLNAME_CAPACITY] = ""; -// for icu - // GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &status); + NSLocale *locale = [NSLocale autoupdatingCurrentLocale]; - if (U_FAILURE(status)) + NSLog(@"NSLog NativeGetLocaleInfoString is running after NSLocale"); + // UErrorCode status = U_ZERO_ERROR; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + NSLog(@"NSLog NativeGetLocaleInfoString is running after NSNumberFormatter"); + /* if (U_FAILURE(status)) { - return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR); - } + // return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR); + return value; + }*/ switch (localeStringData) { case LocaleString_LocalizedDisplayName: + NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); value = (UChar *)[[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; + //return value; break; case LocaleString_EnglishDisplayName: - value = (UChar *)[currentLocale.localeIdentifier UTF8String]; - break; + NSLog(@"NSLog LocaleString_EnglishDisplayName case is running"); + //check why is this wrong? + value = (UChar *)[locale.localeIdentifier UTF8String]; + //value = (UChar *)[[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; + //return value; + break; case LocaleString_NativeDisplayName: + NSLog(@"NSLog LocaleString_NativeDisplayName case is running"); value = (UChar *)[currentLocale.localeIdentifier UTF8String]; + //return value; break; case LocaleString_LocalizedLanguageName: + NSLog(@"NSLog LocaleString_LocalizedLanguageName case is running"); value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + //return value; break; case LocaleString_EnglishLanguageName: + NSLog(@"NSLog LocaleString_EnglishLanguageName case is running"); value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + //return value; break; case LocaleString_NativeLanguageName: + NSLog(@"NSLog LocaleString_NativeLanguageName case is running"); value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; - break; + //return value; + break; case LocaleString_EnglishCountryName: + NSLog(@"NSLog LocaleString_EnglishCountryName case is running"); value = (UChar *)[[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + //return value; break; case LocaleString_NativeCountryName: + NSLog(@"NSLog LocaleString_NativeCountryName case is running"); value = (UChar *)[[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + //return value; break; case LocaleString_ThousandSeparator: + NSLog(@"NSLog LocaleString_ThousandSeparator case is running"); value = (UChar *)[currentLocale.groupingSeparator UTF8String]; + //return value; break; case LocaleString_DecimalSeparator: + NSLog(@"NSLog LocaleString_DecimalSeparator case is running"); value = (UChar *)[currentLocale.decimalSeparator UTF8String]; + //return value; break; case LocaleString_Digits: + NSLog(@"NSLog LocaleString_Digits case is running"); // TODO - /*{ - // Native digit can be more than one 16-bit character (e.g. ccp-Cakm-BD locale which using surrogate pairs to represent the native digit). - // We'll separate the native digits in the returned buffer by the character '\uFFFF'. - int32_t symbolLength = 0; - status = GetDigitSymbol(locale, status, UNUM_ZERO_DIGIT_SYMBOL, 0, value, valueLength, &symbolLength); - - int32_t charIndex = symbolLength; - - if (U_SUCCESS(status) && (uint32_t)charIndex < (uint32_t)valueLength) - { - value[charIndex++] = 0xFFFF; - - // symbols UNUM_ONE_DIGIT to UNUM_NINE_DIGIT are contiguous - for (int32_t symbol = UNUM_ONE_DIGIT_SYMBOL; symbol <= UNUM_NINE_DIGIT_SYMBOL && charIndex < valueLength - 3; symbol++) - { - status = GetDigitSymbol(locale, status, (UNumberFormatSymbol)symbol, charIndex, value, valueLength, &symbolLength); - charIndex += symbolLength; - if (!U_SUCCESS(status) || (uint32_t)charIndex >= (uint32_t)valueLength) - { - break; - } - - value[charIndex++] = 0xFFFF; - } - - if ((uint32_t)charIndex < (uint32_t)valueLength) - { - value[charIndex] = 0; - } - } - }*/ - break; + //return value; + break; case LocaleString_MonetarySymbol: + NSLog(@"NSLog LocaleString_MonetarySymbol case is running"); value = (UChar *)[currentLocale.currencySymbol UTF8String]; + //return value; break; case LocaleString_Iso4217MonetarySymbol: + NSLog(@"NSLog LocaleString_Iso4217MonetarySymbol case is running"); // check if this is correct value = (UChar *)[currentLocale.currencySymbol UTF8String]; + //return value; break; case LocaleString_CurrencyEnglishName: + NSLog(@"NSLog LocaleString_CurrencyEnglishName case is running"); value = (UChar *)[[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; + //return value; break; case LocaleString_CurrencyNativeName: + NSLog(@"NSLog LocaleString_CurrencyNativeName case is running"); value = (UChar *)[[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; + //return value; break; case LocaleString_MonetaryDecimalSeparator: + NSLog(@"NSLog LocaleString_MonetaryDecimalSeparator case is running"); // TODO //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength, NULL); + //return value; break; case LocaleString_MonetaryThousandSeparator: + NSLog(@"NSLog LocaleString_MonetaryThousandSeparator case is running"); // TODO /*status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength, NULL);*/ + //return value; break; case LocaleString_AMDesignator: + NSLog(@"NSLog LocaleString_AMDesignator case is running"); // TODO //status = GetLocaleInfoAmPm(locale, true, value, valueLength); + //return value; break; case LocaleString_PMDesignator: + NSLog(@"NSLog LocaleString_PMDesignator case is running"); // TODO //status = GetLocaleInfoAmPm(locale, false, value, valueLength); + //return value; break; case LocaleString_PositiveSign: - // TODO - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PLUS_SIGN_SYMBOL, value, valueLength, NULL); + NSLog(@"NSLog LocaleString_PositiveSign case is running"); + value = (UChar *)[numberFormatter.plusSign UTF8String]; + //return value; break; case LocaleString_NegativeSign: - // TODO - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MINUS_SIGN_SYMBOL, value, valueLength, NULL); + NSLog(@"NSLog LocaleString_NegativeSign case is running"); + value = (UChar *)[numberFormatter.minusSign UTF8String]; + //return value; break; case LocaleString_Iso639LanguageTwoLetterName: + NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); // TODO //status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); + //return value; break; case LocaleString_Iso639LanguageThreeLetterName: + NSLog(@"NSLog LocaleString_Iso639LanguageThreeLetterName case is running"); // TODO //status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); + //return value; break; case LocaleString_Iso3166CountryName: + NSLog(@"NSLog LocaleString_Iso3166CountryName case is running"); // TODO + value = (UChar *)[currentLocale.countryCode UTF8String]; //status = GetLocaleIso3166CountryName(locale, value, valueLength); + //return value; break; case LocaleString_Iso3166CountryName2: + NSLog(@"NSLog LocaleString_Iso3166CountryName2 case is running"); // TODO //status = GetLocaleIso3166CountryCode(locale, value, valueLength); + //return value; break; case LocaleString_NaNSymbol: - // TODO - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_NAN_SYMBOL, value, valueLength, NULL); + NSLog(@"NSLog LocaleString_NaNSymbol case is running"); + value = (UChar *)[numberFormatter.notANumberSymbol UTF8String]; + //return value; break; case LocaleString_PositiveInfinitySymbol: - // TODO - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INFINITY_SYMBOL, value, valueLength, NULL); + NSLog(@"NSLog LocaleString_PositiveInfinitySymbol case is running"); + value = (UChar *)[numberFormatter.positiveInfinitySymbol UTF8String]; + //return value; + break; + case LocaleString_NegativeInfinitySymbol: + NSLog(@"NSLog LocaleString_NegativeInfinitySymbol case is running"); + value = (UChar *)[numberFormatter.negativeInfinitySymbol UTF8String]; + //return value; break; case LocaleString_ParentName: + NSLog(@"NSLog LocaleString_ParentName case is running"); // TODO - /* // ICU supports lang[-script][-region][-variant] so up to 4 parents - // including invariant locale - char localeNameTemp[ULOC_FULLNAME_CAPACITY]; - - uloc_getParent(locale, localeNameTemp, ULOC_FULLNAME_CAPACITY, &status); - u_charsToUChars_safe(localeNameTemp, value, valueLength, &status); - if (U_SUCCESS(status)) - { - FixupLocaleName(value, valueLength); - }*/ + + //return value; break; case LocaleString_PercentSymbol: - // TODO - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERCENT_SYMBOL, value, valueLength, NULL); + NSLog(@"NSLog LocaleString_PercentSymbol case is running"); + value = (UChar *)[numberFormatter.percentSymbol UTF8String]; + //return value; break; case LocaleString_PerMilleSymbol: - // TODO - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PERMILL_SYMBOL, value, valueLength, NULL); + NSLog(@"NSLog LocaleString_PerMilleSymbol case is running"); + value = (UChar *)[numberFormatter.perMillSymbol UTF8String]; + //return value; break; default: - status = U_UNSUPPORTED_ERROR; + NSLog(@"NSLog default case is running"); + // status = U_UNSUPPORTED_ERROR; + //return value; break; } - - return UErrorCodeToBool(status); + NSLog(@"Globalization nativeGetLocaleInfo value: %s", (char*)value); + //return UErrorCodeToBool(U_ZERO_ERROR); + return value; } diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.c b/src/native/libs/System.Globalization.Native/pal_localeStringData.c index b19f90526be8c6..c2325109e326a0 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.c +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.c @@ -6,9 +6,11 @@ #include #include #include +#include #include "pal_locale_internal.h" #include "pal_localeStringData.h" +#include /* Function: @@ -416,11 +418,16 @@ int32_t Native_GetLocaleInfoString(const UChar* localeName, { #ifdef __APPLE__ - return NativeGetLocaleInfoString(localeName, + UChar* val = NativeGetLocaleInfoString(localeName, localeStringData, value, valueLength, uiLocaleName); + + g_print("Globalization Native_GetLocaleInfoString val: %s", (char*)val); + g_print("Globalization Native_GetLocaleInfoString value: %s", (char*)value); + value = val; + return 1; #endif } diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index f81479bc5b0b8f..d38f0a19da189f 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -39,6 +39,7 @@ typedef enum LocaleString_Iso3166CountryName2= 0x00000068, LocaleString_NaNSymbol = 0x00000069, LocaleString_PositiveInfinitySymbol = 0x0000006a, + LocaleString_NegativeInfinitySymbol = 0x0000006b, LocaleString_ParentName = 0x0000006d, LocaleString_PercentSymbol = 0x00000076, LocaleString_PerMilleSymbol = 0x00000077 diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index b850c7f4a3dfee..95e6052f8770b8 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -78,7 +78,7 @@ NativeGetLocaleInfoString NativeGetLocaleInfoString for Apple platforms */ -int32_t NativeGetLocaleInfoString(const UChar* localeName, +UChar* NativeGetLocaleInfoString(const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 4b131700962328..0dbb2cf7839d9a 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -257,7 +257,7 @@ public override bool Execute() if (GenerateXcodeProject) { XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, - AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource); + AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource); if (BuildAppBundle) { @@ -275,7 +275,7 @@ public override bool Execute() else if (GenerateCMakeProject) { generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, - AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource); + AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource); } return true; From af32324c0332ed9985640e6648ff9d8db514523e Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 13 Feb 2023 14:53:36 +0100 Subject: [PATCH 06/25] working version of NativeGetLocaleInfoString --- .../Common/src/Interop/Interop.Locale.iOS.cs | 6 +- .../src/System/Globalization/CultureData.cs | 2 +- .../System/Globalization/CultureData.iOS.cs | 27 ++---- .../System.Globalization.Native/entrypoints.c | 2 +- .../System.Globalization.Native/pal_locale.m | 92 ++++++++++--------- .../pal_localeStringData.c | 28 ------ .../pal_localeStringData.h | 5 +- .../pal_locale_internal.h | 5 +- 8 files changed, 63 insertions(+), 104 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index c88388ba9722fc..da683c30aa375a 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.InteropServices; +using System; internal static partial class Interop { @@ -11,9 +12,8 @@ internal static partial class Globalization [return: MarshalAs(UnmanagedType.Bool)] internal static unsafe partial bool NativeGetLocaleName(string localeName, char* value, int valueLength); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "Native_GetLocaleInfoString", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static unsafe partial bool NativeGetLocaleInfoString(string localeName, uint localeStringData, char* value, int valueLength, string? uiLocaleName = null); + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "NativeGetLocaleInfoString", StringMarshalling = StringMarshalling.Utf8)] + internal static unsafe partial string NativeGetLocaleInfoString(string localeName, uint localeStringData, int valueLength, string? uiLocaleName = null); /*[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleName", StringMarshalling = StringMarshalling.Utf16)] [return: MarshalAs(UnmanagedType.Bool)] 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 b7a0b6dbba51b0..260cb883bb0577 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -924,7 +924,7 @@ internal string CultureName // Parent name (which may be a custom locale/culture) // Ask using the real name, so that we get parents of neutrals - internal string ParentName => _sParent ??= GetLocaleInfoCore(_sRealName!, LocaleStringData.ParentName); + internal string ParentName => _sParent ??= string.Empty; // Localized pretty name for this locale (ie: Inglis (estados Unitos)) internal string DisplayName diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index e25e1a4bf69cbe..e1b10978462aab 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Text; +using System.Runtime.InteropServices; namespace System.Globalization { @@ -105,34 +107,17 @@ private string NativeGetLocaleInfo(LocaleStringData type, string? uiCultureName // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the // "windows" name, which can be specific for downlevel (< windows 7) os's. - private unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData type, string? uiCultureName = null) + private static unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData type, string? uiCultureName = null) { Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(localeName != null, "[CultureData.NativeGetLocaleInfo] Expected localeName to be not be null"); - /*switch (type) - { - case LocaleStringData.NegativeInfinitySymbol: - // not an equivalent in ICU; prefix the PositiveInfinitySymbol with NegativeSign - return IcuGetLocaleInfo(localeName, LocaleStringData.NegativeSign) + - IcuGetLocaleInfo(localeName, LocaleStringData.PositiveInfinitySymbol); - }*/ - - char* buffer = stackalloc char[Native_ULOC_KEYWORD_AND_VALUES_CAPACITY]; - // this buffer is initialized Debug.Write("Globalization NativeGetLocaleInfo is called"); System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called localeName: " + localeName); System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called type: " + type.ToString()); - bool result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, buffer, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called result: " + result.ToString()); - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called buffer: " + new string(buffer)); - if (!result) - { - // Failed, just use empty string - Debug.Fail("[CultureData.NativeGetLocaleInfo(LocaleStringData)] Failed"); - return string.Empty; - } - return new string(buffer); + string result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); + System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called result: " + result); + return result; } /*private int NativeGetLocaleInfo(LocaleNumberData type) diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 0cadf4ddb08692..704692fe50655d 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -36,7 +36,7 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_GetLocaleInfoInt) DllImportEntry(GlobalizationNative_GetLocaleInfoString) DllImportEntry(Native_GetLocaleName) - DllImportEntry(Native_GetLocaleInfoString) + DllImportEntry(NativeGetLocaleInfoString) DllImportEntry(GlobalizationNative_GetLocaleName) DllImportEntry(GlobalizationNative_GetLocales) DllImportEntry(GlobalizationNative_GetLocaleTimeFormat) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 6cb50b3d15bbef..fed5bbce6f59e1 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -41,196 +41,201 @@ int32_t NativeGetLocaleName(const UChar* localeName, return UErrorCodeToBool(status); } - -UChar* NativeGetLocaleInfoString(const UChar* localeName, +const char* NativeGetLocaleInfoString(const char* localeName, LocaleStringData localeStringData, - UChar* value, int32_t valueLength, - const UChar* uiLocaleName) + const char* uiLocaleName) { NSLog(@"NSLog NativeGetLocaleInfoString is running"); NSLocale *currentLocale = [NSLocale currentLocale]; NSLocale *locale = [NSLocale autoupdatingCurrentLocale]; + const char* value; NSLog(@"NSLog NativeGetLocaleInfoString is running after NSLocale"); // UErrorCode status = U_ZERO_ERROR; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; NSLog(@"NSLog NativeGetLocaleInfoString is running after NSNumberFormatter"); - /* if (U_FAILURE(status)) - { - // return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR); - return value; - }*/ switch (localeStringData) { case LocaleString_LocalizedDisplayName: NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); - value = (UChar *)[[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; + value = [[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; //return value; break; case LocaleString_EnglishDisplayName: NSLog(@"NSLog LocaleString_EnglishDisplayName case is running"); //check why is this wrong? - value = (UChar *)[locale.localeIdentifier UTF8String]; + //value = (char *)locale.localeIdentifier; + /* NSData* storage= [locale.localeIdentifier dataUsingEncoding:NSUTF8StringEncoding]; + value = (char*)storage.bytes;*/ + value = [locale.localeIdentifier UTF8String]; //value = (UChar *)[[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; //return value; break; case LocaleString_NativeDisplayName: NSLog(@"NSLog LocaleString_NativeDisplayName case is running"); - value = (UChar *)[currentLocale.localeIdentifier UTF8String]; + value = [currentLocale.localeIdentifier UTF8String]; //return value; break; case LocaleString_LocalizedLanguageName: NSLog(@"NSLog LocaleString_LocalizedLanguageName case is running"); - value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; //return value; break; case LocaleString_EnglishLanguageName: NSLog(@"NSLog LocaleString_EnglishLanguageName case is running"); - value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; //return value; break; case LocaleString_NativeLanguageName: NSLog(@"NSLog LocaleString_NativeLanguageName case is running"); - value = (UChar *)[[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; //return value; break; case LocaleString_EnglishCountryName: NSLog(@"NSLog LocaleString_EnglishCountryName case is running"); - value = (UChar *)[[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + value = [[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; //return value; break; case LocaleString_NativeCountryName: NSLog(@"NSLog LocaleString_NativeCountryName case is running"); - value = (UChar *)[[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + value = [[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; //return value; break; case LocaleString_ThousandSeparator: NSLog(@"NSLog LocaleString_ThousandSeparator case is running"); - value = (UChar *)[currentLocale.groupingSeparator UTF8String]; + value = [currentLocale.groupingSeparator UTF8String]; //return value; break; case LocaleString_DecimalSeparator: NSLog(@"NSLog LocaleString_DecimalSeparator case is running"); - value = (UChar *)[currentLocale.decimalSeparator UTF8String]; + value = [currentLocale.decimalSeparator UTF8String]; //return value; break; case LocaleString_Digits: NSLog(@"NSLog LocaleString_Digits case is running"); - // TODO + // TODO fake value + value = [currentLocale.currencySymbol UTF8String]; //return value; break; case LocaleString_MonetarySymbol: NSLog(@"NSLog LocaleString_MonetarySymbol case is running"); - value = (UChar *)[currentLocale.currencySymbol UTF8String]; + value = [currentLocale.currencySymbol UTF8String]; //return value; break; case LocaleString_Iso4217MonetarySymbol: NSLog(@"NSLog LocaleString_Iso4217MonetarySymbol case is running"); // check if this is correct - value = (UChar *)[currentLocale.currencySymbol UTF8String]; + value = [currentLocale.currencySymbol UTF8String]; //return value; break; case LocaleString_CurrencyEnglishName: NSLog(@"NSLog LocaleString_CurrencyEnglishName case is running"); - value = (UChar *)[[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; + value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; //return value; break; case LocaleString_CurrencyNativeName: NSLog(@"NSLog LocaleString_CurrencyNativeName case is running"); - value = (UChar *)[[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; + value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; //return value; break; case LocaleString_MonetaryDecimalSeparator: NSLog(@"NSLog LocaleString_MonetaryDecimalSeparator case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength, NULL); //return value; break; case LocaleString_MonetaryThousandSeparator: NSLog(@"NSLog LocaleString_MonetaryThousandSeparator case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; /*status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength, NULL);*/ //return value; break; case LocaleString_AMDesignator: NSLog(@"NSLog LocaleString_AMDesignator case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //status = GetLocaleInfoAmPm(locale, true, value, valueLength); //return value; break; case LocaleString_PMDesignator: NSLog(@"NSLog LocaleString_PMDesignator case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //status = GetLocaleInfoAmPm(locale, false, value, valueLength); //return value; break; case LocaleString_PositiveSign: NSLog(@"NSLog LocaleString_PositiveSign case is running"); - value = (UChar *)[numberFormatter.plusSign UTF8String]; + value = [numberFormatter.plusSign UTF8String]; //return value; break; case LocaleString_NegativeSign: NSLog(@"NSLog LocaleString_NegativeSign case is running"); - value = (UChar *)[numberFormatter.minusSign UTF8String]; + value = [numberFormatter.minusSign UTF8String]; //return value; break; case LocaleString_Iso639LanguageTwoLetterName: NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); //return value; break; case LocaleString_Iso639LanguageThreeLetterName: NSLog(@"NSLog LocaleString_Iso639LanguageThreeLetterName case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); //return value; break; case LocaleString_Iso3166CountryName: NSLog(@"NSLog LocaleString_Iso3166CountryName case is running"); // TODO - value = (UChar *)[currentLocale.countryCode UTF8String]; + value = [currentLocale.countryCode UTF8String]; //status = GetLocaleIso3166CountryName(locale, value, valueLength); //return value; break; case LocaleString_Iso3166CountryName2: NSLog(@"NSLog LocaleString_Iso3166CountryName2 case is running"); - // TODO + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //status = GetLocaleIso3166CountryCode(locale, value, valueLength); //return value; break; case LocaleString_NaNSymbol: NSLog(@"NSLog LocaleString_NaNSymbol case is running"); - value = (UChar *)[numberFormatter.notANumberSymbol UTF8String]; + value = [numberFormatter.notANumberSymbol UTF8String]; //return value; break; case LocaleString_PositiveInfinitySymbol: NSLog(@"NSLog LocaleString_PositiveInfinitySymbol case is running"); - value = (UChar *)[numberFormatter.positiveInfinitySymbol UTF8String]; + value = [numberFormatter.positiveInfinitySymbol UTF8String]; //return value; break; case LocaleString_NegativeInfinitySymbol: NSLog(@"NSLog LocaleString_NegativeInfinitySymbol case is running"); - value = (UChar *)[numberFormatter.negativeInfinitySymbol UTF8String]; + value = [numberFormatter.negativeInfinitySymbol UTF8String]; //return value; break; case LocaleString_ParentName: NSLog(@"NSLog LocaleString_ParentName case is running"); - // TODO - + // TODO fake value + value = [locale.localeIdentifier UTF8String]; //return value; break; case LocaleString_PercentSymbol: NSLog(@"NSLog LocaleString_PercentSymbol case is running"); - value = (UChar *)[numberFormatter.percentSymbol UTF8String]; + value = [numberFormatter.percentSymbol UTF8String]; //return value; break; case LocaleString_PerMilleSymbol: NSLog(@"NSLog LocaleString_PerMilleSymbol case is running"); - value = (UChar *)[numberFormatter.perMillSymbol UTF8String]; + value = [numberFormatter.perMillSymbol UTF8String]; //return value; break; default: @@ -239,9 +244,8 @@ int32_t NativeGetLocaleName(const UChar* localeName, //return value; break; } - NSLog(@"Globalization nativeGetLocaleInfo value: %s", (char*)value); - //return UErrorCodeToBool(U_ZERO_ERROR); - return value; + NSLog(@"Globalization nativeGetLocaleInfo value: %s", value); + return strdup(value); } diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.c b/src/native/libs/System.Globalization.Native/pal_localeStringData.c index c2325109e326a0..210c2e1f8ab637 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.c +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.c @@ -403,34 +403,6 @@ int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, return UErrorCodeToBool(status); } -/* -PAL Function: -GetLocaleInfoString - -Obtains string locale information. -Returns 1 for success, 0 otherwise -*/ -int32_t Native_GetLocaleInfoString(const UChar* localeName, - LocaleStringData localeStringData, - UChar* value, - int32_t valueLength, - const UChar* uiLocaleName) -{ -#ifdef __APPLE__ - - UChar* val = NativeGetLocaleInfoString(localeName, - localeStringData, - value, - valueLength, - uiLocaleName); - - g_print("Globalization Native_GetLocaleInfoString val: %s", (char*)val); - g_print("Globalization Native_GetLocaleInfoString value: %s", (char*)value); - value = val; - return 1; -#endif - -} /* PAL Function: diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index d38f0a19da189f..c3a7082e4039ca 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -51,11 +51,10 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeNam int32_t valueLength, const UChar* uiLocaleName); -PALEXPORT int32_t Native_GetLocaleInfoString(const UChar* localeName, +PALEXPORT const char* NativeGetLocaleInfoString(const char* localeName, LocaleStringData localeStringData, - UChar* value, int32_t valueLength, - const UChar* uiLocaleName); + const char* uiLocaleName); PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, int shortFormat, UChar* value, diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index 95e6052f8770b8..f272bc4d0249a4 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -78,9 +78,8 @@ NativeGetLocaleInfoString NativeGetLocaleInfoString for Apple platforms */ -UChar* NativeGetLocaleInfoString(const UChar* localeName, +const char* NativeGetLocaleInfoString(const char* localeName, LocaleStringData localeStringData, - UChar* value, int32_t valueLength, - const UChar* uiLocaleName); + const char* uiLocaleName); #endif From 83f4e7b0f713587d8b1b4f3f93faf85029baeeed Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 14 Feb 2023 15:33:14 +0100 Subject: [PATCH 07/25] update --- .../Common/src/Interop/Interop.Locale.iOS.cs | 1 + .../src/System/Globalization/CultureData.cs | 1 + .../System/Globalization/CultureData.iOS.cs | 1 + .../src/System/Globalization/CultureInfo.cs | 1 + .../System.Globalization.Native/pal_locale.m | 67 +++++-------------- 5 files changed, 19 insertions(+), 52 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index da683c30aa375a..bdaa3f38ae0fb1 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using System; +// internal static partial class Interop { 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 260cb883bb0577..65aded9e8010e5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2359,6 +2359,7 @@ private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes. /// + //important private enum LocaleStringData : uint { /// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index e1b10978462aab..24a97a401e956b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -109,6 +109,7 @@ private string NativeGetLocaleInfo(LocaleStringData type, string? uiCultureName // "windows" name, which can be specific for downlevel (< windows 7) os's. private static unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData type, string? uiCultureName = null) { + // Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(localeName != null, "[CultureData.NativeGetLocaleInfo] Expected localeName to be not be null"); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs index d5c1f218c81619..d0435c88c7630d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs @@ -470,6 +470,7 @@ public static CultureInfo InvariantCulture /// /// Return the parent CultureInfo for the current instance. /// + // public virtual CultureInfo Parent { get diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index fed5bbce6f59e1..f30ba3bf3ad7f8 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -47,13 +47,24 @@ int32_t NativeGetLocaleName(const UChar* localeName, const char* uiLocaleName) { NSLog(@"NSLog NativeGetLocaleInfoString is running"); - NSLocale *currentLocale = [NSLocale currentLocale]; + // NSLocale *currentLocale = [NSLocale currentLocale]; NSLocale *locale = [NSLocale autoupdatingCurrentLocale]; + NSString *s = [NSString stringWithFormat:@"%s", localeName]; + + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:s]; + const char* value; NSLog(@"NSLog NativeGetLocaleInfoString is running after NSLocale"); // UErrorCode status = U_ZERO_ERROR; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + //NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; + //[calendar setLocale:currentLocale]; + NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; + timeFormatter.locale = currentLocale; + + NSLog(@"NSLog NativeGetLocaleInfoString is running after NSNumberFormatter"); switch (localeStringData) @@ -61,187 +72,139 @@ int32_t NativeGetLocaleName(const UChar* localeName, case LocaleString_LocalizedDisplayName: NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); value = [[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; - //return value; break; case LocaleString_EnglishDisplayName: NSLog(@"NSLog LocaleString_EnglishDisplayName case is running"); - //check why is this wrong? - //value = (char *)locale.localeIdentifier; - /* NSData* storage= [locale.localeIdentifier dataUsingEncoding:NSUTF8StringEncoding]; - value = (char*)storage.bytes;*/ - value = [locale.localeIdentifier UTF8String]; - //value = (UChar *)[[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; - //return value; + value = [currentLocale.localeIdentifier UTF8String]; break; case LocaleString_NativeDisplayName: NSLog(@"NSLog LocaleString_NativeDisplayName case is running"); value = [currentLocale.localeIdentifier UTF8String]; - //return value; break; case LocaleString_LocalizedLanguageName: NSLog(@"NSLog LocaleString_LocalizedLanguageName case is running"); value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; - //return value; break; case LocaleString_EnglishLanguageName: NSLog(@"NSLog LocaleString_EnglishLanguageName case is running"); value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; - //return value; break; case LocaleString_NativeLanguageName: NSLog(@"NSLog LocaleString_NativeLanguageName case is running"); value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; - //return value; break; case LocaleString_EnglishCountryName: NSLog(@"NSLog LocaleString_EnglishCountryName case is running"); value = [[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; - //return value; break; case LocaleString_NativeCountryName: NSLog(@"NSLog LocaleString_NativeCountryName case is running"); value = [[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; - //return value; break; case LocaleString_ThousandSeparator: NSLog(@"NSLog LocaleString_ThousandSeparator case is running"); value = [currentLocale.groupingSeparator UTF8String]; - //return value; break; case LocaleString_DecimalSeparator: NSLog(@"NSLog LocaleString_DecimalSeparator case is running"); value = [currentLocale.decimalSeparator UTF8String]; - //return value; break; case LocaleString_Digits: NSLog(@"NSLog LocaleString_Digits case is running"); // TODO fake value value = [currentLocale.currencySymbol UTF8String]; - //return value; break; case LocaleString_MonetarySymbol: NSLog(@"NSLog LocaleString_MonetarySymbol case is running"); value = [currentLocale.currencySymbol UTF8String]; - //return value; break; case LocaleString_Iso4217MonetarySymbol: NSLog(@"NSLog LocaleString_Iso4217MonetarySymbol case is running"); // check if this is correct value = [currentLocale.currencySymbol UTF8String]; - //return value; break; case LocaleString_CurrencyEnglishName: NSLog(@"NSLog LocaleString_CurrencyEnglishName case is running"); value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; - //return value; break; case LocaleString_CurrencyNativeName: NSLog(@"NSLog LocaleString_CurrencyNativeName case is running"); value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; - //return value; break; case LocaleString_MonetaryDecimalSeparator: NSLog(@"NSLog LocaleString_MonetaryDecimalSeparator case is running"); // TODO fake value value = [locale.localeIdentifier UTF8String]; - //status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength, NULL); - //return value; break; case LocaleString_MonetaryThousandSeparator: NSLog(@"NSLog LocaleString_MonetaryThousandSeparator case is running"); // TODO fake value value = [locale.localeIdentifier UTF8String]; - /*status = - GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength, NULL);*/ - //return value; break; case LocaleString_AMDesignator: NSLog(@"NSLog LocaleString_AMDesignator case is running"); // TODO fake value - value = [locale.localeIdentifier UTF8String]; - //status = GetLocaleInfoAmPm(locale, true, value, valueLength); - //return value; + value = [timeFormatter.AMSymbol UTF8String]; break; case LocaleString_PMDesignator: NSLog(@"NSLog LocaleString_PMDesignator case is running"); // TODO fake value - value = [locale.localeIdentifier UTF8String]; - //status = GetLocaleInfoAmPm(locale, false, value, valueLength); - //return value; + value = [timeFormatter.pmSymbol UTF8String]; break; case LocaleString_PositiveSign: NSLog(@"NSLog LocaleString_PositiveSign case is running"); value = [numberFormatter.plusSign UTF8String]; - //return value; break; case LocaleString_NegativeSign: NSLog(@"NSLog LocaleString_NegativeSign case is running"); value = [numberFormatter.minusSign UTF8String]; - //return value; break; case LocaleString_Iso639LanguageTwoLetterName: NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); // TODO fake value value = [locale.localeIdentifier UTF8String]; - //status = GetLocaleIso639LanguageTwoLetterName(locale, value, valueLength); - //return value; break; case LocaleString_Iso639LanguageThreeLetterName: NSLog(@"NSLog LocaleString_Iso639LanguageThreeLetterName case is running"); // TODO fake value value = [locale.localeIdentifier UTF8String]; - //status = GetLocaleIso639LanguageThreeLetterName(locale, value, valueLength); - //return value; break; case LocaleString_Iso3166CountryName: NSLog(@"NSLog LocaleString_Iso3166CountryName case is running"); - // TODO value = [currentLocale.countryCode UTF8String]; - //status = GetLocaleIso3166CountryName(locale, value, valueLength); - //return value; break; case LocaleString_Iso3166CountryName2: NSLog(@"NSLog LocaleString_Iso3166CountryName2 case is running"); // TODO fake value value = [locale.localeIdentifier UTF8String]; - //status = GetLocaleIso3166CountryCode(locale, value, valueLength); - //return value; break; case LocaleString_NaNSymbol: NSLog(@"NSLog LocaleString_NaNSymbol case is running"); value = [numberFormatter.notANumberSymbol UTF8String]; - //return value; break; case LocaleString_PositiveInfinitySymbol: NSLog(@"NSLog LocaleString_PositiveInfinitySymbol case is running"); value = [numberFormatter.positiveInfinitySymbol UTF8String]; - //return value; break; case LocaleString_NegativeInfinitySymbol: NSLog(@"NSLog LocaleString_NegativeInfinitySymbol case is running"); value = [numberFormatter.negativeInfinitySymbol UTF8String]; - //return value; break; case LocaleString_ParentName: NSLog(@"NSLog LocaleString_ParentName case is running"); // TODO fake value value = [locale.localeIdentifier UTF8String]; - //return value; break; case LocaleString_PercentSymbol: NSLog(@"NSLog LocaleString_PercentSymbol case is running"); value = [numberFormatter.percentSymbol UTF8String]; - //return value; break; case LocaleString_PerMilleSymbol: NSLog(@"NSLog LocaleString_PerMilleSymbol case is running"); value = [numberFormatter.perMillSymbol UTF8String]; - //return value; break; default: NSLog(@"NSLog default case is running"); - // status = U_UNSUPPORTED_ERROR; - //return value; break; } NSLog(@"Globalization nativeGetLocaleInfo value: %s", value); From 4ac3e6ba33726da4b69e777ae971b1e3699e48bd Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 08:10:42 +0100 Subject: [PATCH 08/25] Refactored and added more cases --- .../Common/src/Interop/Interop.Locale.iOS.cs | 28 +-- .../tests/Hybrid/HybridMode.cs | 188 ++++-------------- .../System/Globalization/CultureData.Unix.cs | 3 +- .../src/System/Globalization/CultureData.cs | 26 +-- .../System/Globalization/CultureData.iOS.cs | 92 +-------- .../src/System/Globalization/CultureInfo.cs | 1 - .../System.Globalization.Native/entrypoints.c | 4 +- .../System.Globalization.Native/pal_locale.c | 23 --- .../System.Globalization.Native/pal_locale.h | 2 +- .../System.Globalization.Native/pal_locale.m | 126 +++++------- .../pal_localeStringData.c | 3 - .../pal_locale_internal.h | 3 +- 12 files changed, 95 insertions(+), 404 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index bdaa3f38ae0fb1..45dcb3348c9a3d 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -9,34 +9,10 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "Native_GetLocaleName", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static unsafe partial bool NativeGetLocaleName(string localeName, char* value, int valueLength); + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "NativeGetLocaleName", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial string NativeGetLocaleName(string localeName, int valueLength); [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "NativeGetLocaleInfoString", StringMarshalling = StringMarshalling.Utf8)] internal static unsafe partial string NativeGetLocaleInfoString(string localeName, uint localeStringData, int valueLength, string? uiLocaleName = null); - - /*[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleName", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static unsafe partial bool GetDefaultLocaleName(char* value, int valueLength); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsPredefinedLocale", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool IsPredefinedLocale(string localeName); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static unsafe partial bool GetLocaleTimeFormat(string localeName, [MarshalAs(UnmanagedType.Bool)] bool shortFormat, char* value, int valueLength); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoInt", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes", StringMarshalling = StringMarshalling.Utf16)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize); - - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocales", StringMarshalling = StringMarshalling.Utf16)] - internal static partial int GetLocales([Out] char[]? value, int valueLength);*/ } } diff --git a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs index 4f492cede3bb01..26ca0af5a34ca5 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs +++ b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs @@ -14,166 +14,50 @@ namespace System.Globalization.Tests { public class HybridModeTests { - - public static IEnumerable Cultures_TestData() + public static IEnumerable EnglishName_TestData() { - yield return new object[] { "en-US" }; - /* yield return new object[] { "ja-JP" }; - yield return new object[] { "fr-FR" }; - yield return new object[] { "tr-TR" }; - yield return new object[] { "" };*/ + yield return new object[] { "en-US", "English (United States)" }; + yield return new object[] { "fr-FR", "French (France)" }; } - //private static readonly string[] s_cultureNames = new string[] { "en-US", "ja-JP", "fr-FR", "tr-TR", "" }; + public static IEnumerable NativeName_TestData() + { + yield return new object[] { "en-US", "English (United States)" }; + yield return new object[] { "fr-FR", "français (France)" }; + yield return new object[] { "en-CA", "English (Canada)" }; + } - //[ConditionalTheory(nameof(PredefinedCulturesOnlyIsDisabled))] [Theory] - [MemberData(nameof(Cultures_TestData))] - public void TestCultureData(string cultureName) + [MemberData(nameof(EnglishName_TestData))] + public void TestEnglishName(string cultureName, string expected) { - CultureInfo ci = new CultureInfo(cultureName); - /* bool invariant = (bool) typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("InvariantGlobalization", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); - bool hybrid = (bool) typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("HybridGlobalization", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); - System.Console.WriteLine("Globalization mode is IsInvariantGlobalization: " + invariant); - System.Console.WriteLine("Globalization mode is HybridGlobalization: " + hybrid);*/ - // Add here test - // System.Console.WriteLine("Globalization mode is IsInvariantGlobalization: " + PlatformDetection.IsInvariantGlobalization); - // System.Console.WriteLine("Globalization mode is IsHybridGlobalization: " + PlatformDetection.IsHybridGlobalization); - System.Console.WriteLine("Globalization mode log EnglishName: " + ci.EnglishName); - // CultureInfo myTestCulture = new CultureInfo(name); - //Assert.Equal(expected, myTestCulture.EnglishName); - // - // DateTimeInfo - // - - /*Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedDayNames, ci.DateTimeFormat.AbbreviatedDayNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedMonthGenitiveNames, ci.DateTimeFormat.AbbreviatedMonthGenitiveNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedMonthNames, ci.DateTimeFormat.AbbreviatedMonthNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.AMDesignator, ci.DateTimeFormat.AMDesignator); - Assert.True(ci.DateTimeFormat.Calendar is GregorianCalendar); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.CalendarWeekRule); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.DateSeparator, ci.DateTimeFormat.DateSeparator); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.DayNames, ci.DateTimeFormat.DayNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.FirstDayOfWeek, ci.DateTimeFormat.FirstDayOfWeek); - - for (DayOfWeek dow = DayOfWeek.Sunday; dow < DayOfWeek.Saturday; dow++) - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedDayName(dow), ci.DateTimeFormat.GetAbbreviatedDayName(dow)); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedEraName(1), ci.DateTimeFormat.GetAbbreviatedEraName(1)); - - for (int i = 1; i <= 12; i++) - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedMonthName(i), ci.DateTimeFormat.GetAbbreviatedMonthName(i)); - - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetAllDateTimePatterns(), ci.DateTimeFormat.GetAllDateTimePatterns()); - - for (DayOfWeek dow = DayOfWeek.Sunday; dow < DayOfWeek.Saturday; dow++) - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetDayName(dow), ci.DateTimeFormat.GetDayName(dow)); - - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetEra(CultureInfo.InvariantCulture.DateTimeFormat.GetEraName(1)), ci.DateTimeFormat.GetEra(ci.DateTimeFormat.GetEraName(1))); - - for (int i = 1; i <= 12; i++) - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i), ci.DateTimeFormat.GetMonthName(i)); - for (DayOfWeek dow = DayOfWeek.Sunday; dow < DayOfWeek.Saturday; dow++) - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.GetShortestDayName(dow), ci.DateTimeFormat.GetShortestDayName(dow)); - - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.LongDatePattern, ci.DateTimeFormat.LongDatePattern); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.LongTimePattern, ci.DateTimeFormat.LongTimePattern); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.MonthDayPattern, ci.DateTimeFormat.MonthDayPattern); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.MonthGenitiveNames, ci.DateTimeFormat.MonthGenitiveNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.MonthNames, ci.DateTimeFormat.MonthNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.NativeCalendarName, ci.DateTimeFormat.NativeCalendarName); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.PMDesignator, ci.DateTimeFormat.PMDesignator); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern, ci.DateTimeFormat.RFC1123Pattern); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.ShortDatePattern, ci.DateTimeFormat.ShortDatePattern); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.ShortestDayNames, ci.DateTimeFormat.ShortestDayNames); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.ShortTimePattern, ci.DateTimeFormat.ShortTimePattern); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.TimeSeparator, ci.DateTimeFormat.TimeSeparator); - Assert.Equal(CultureInfo.InvariantCulture.DateTimeFormat.YearMonthPattern, ci.DateTimeFormat.YearMonthPattern); - - // - // Culture data - // - - Assert.True(ci.Calendar is GregorianCalendar); - - CultureTypes ct = ci.Name == "" ? CultureInfo.InvariantCulture.CultureTypes : CultureInfo.InvariantCulture.CultureTypes | CultureTypes.UserCustomCulture; - Assert.Equal(ct, ci.CultureTypes); - Assert.Equal(CultureInfo.InvariantCulture.NativeName, ci.DisplayName); - Assert.Equal(CultureInfo.InvariantCulture.EnglishName, ci.EnglishName); - Assert.Equal(CultureInfo.InvariantCulture.GetConsoleFallbackUICulture(), ci.GetConsoleFallbackUICulture()); - Assert.Equal(cultureName, ci.IetfLanguageTag); - Assert.Equal(CultureInfo.InvariantCulture.IsNeutralCulture, ci.IsNeutralCulture); - Assert.Equal(CultureInfo.InvariantCulture.KeyboardLayoutId, ci.KeyboardLayoutId); - Assert.Equal(ci.Name == "" ? 0x7F : 0x1000, ci.LCID); - Assert.Equal(cultureName, ci.Name); - Assert.Equal(CultureInfo.InvariantCulture.NativeName, ci.NativeName); - Assert.Equal(1, ci.OptionalCalendars.Length); - Assert.True(ci.OptionalCalendars[0] is GregorianCalendar); - Assert.Equal(CultureInfo.InvariantCulture.Parent, ci.Parent); - Assert.Equal(CultureInfo.InvariantCulture.ThreeLetterISOLanguageName, ci.ThreeLetterISOLanguageName); - Assert.Equal(CultureInfo.InvariantCulture.ThreeLetterWindowsLanguageName, ci.ThreeLetterWindowsLanguageName); - Assert.Equal(CultureInfo.InvariantCulture.TwoLetterISOLanguageName, ci.TwoLetterISOLanguageName); - Assert.Equal(ci.Name == "" ? false : true, ci.UseUserOverride); - - // - // Culture Creations - // - Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.CurrentCulture); - Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.CurrentUICulture); - Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.InstalledUICulture); - Assert.Equal(CultureInfo.InvariantCulture, CultureInfo.CreateSpecificCulture("en")); - Assert.Equal(ci, CultureInfo.GetCultureInfo(cultureName).Clone()); - Assert.Equal(ci, CultureInfo.GetCultureInfoByIetfLanguageTag(cultureName)); - - // - // NumberFormatInfo - // - - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalDigits, ci.NumberFormat.CurrencyDecimalDigits); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalSeparator, ci.NumberFormat.CurrencyDecimalSeparator); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyGroupSeparator, ci.NumberFormat.CurrencyGroupSeparator); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyGroupSizes, ci.NumberFormat.CurrencyGroupSizes); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyNegativePattern, ci.NumberFormat.CurrencyNegativePattern); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencyPositivePattern, ci.NumberFormat.CurrencyPositivePattern); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.CurrencySymbol, ci.NumberFormat.CurrencySymbol); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.DigitSubstitution, ci.NumberFormat.DigitSubstitution); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NaNSymbol, ci.NumberFormat.NaNSymbol); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NativeDigits, ci.NumberFormat.NativeDigits); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NegativeInfinitySymbol, ci.NumberFormat.NegativeInfinitySymbol); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NegativeSign, ci.NumberFormat.NegativeSign); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberDecimalDigits, ci.NumberFormat.NumberDecimalDigits); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator, ci.NumberFormat.NumberDecimalSeparator); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberGroupSeparator, ci.NumberFormat.NumberGroupSeparator); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberGroupSizes, ci.NumberFormat.NumberGroupSizes); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.NumberNegativePattern, ci.NumberFormat.NumberNegativePattern); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentDecimalDigits, ci.NumberFormat.PercentDecimalDigits); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentDecimalSeparator, ci.NumberFormat.PercentDecimalSeparator); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentGroupSeparator, ci.NumberFormat.PercentGroupSeparator); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentGroupSizes, ci.NumberFormat.PercentGroupSizes); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentNegativePattern, ci.NumberFormat.PercentNegativePattern); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentPositivePattern, ci.NumberFormat.PercentPositivePattern); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PercentSymbol, ci.NumberFormat.PercentSymbol); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PerMilleSymbol, ci.NumberFormat.PerMilleSymbol); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PositiveInfinitySymbol, ci.NumberFormat.PositiveInfinitySymbol); - Assert.Equal(CultureInfo.InvariantCulture.NumberFormat.PositiveSign, ci.NumberFormat.PositiveSign); - - // - // TextInfo - // + CultureInfo myTestCulture = new CultureInfo(cultureName); + Assert.Equal(expected, myTestCulture.EnglishName); + } - Assert.Equal(CultureInfo.InvariantCulture.TextInfo.ANSICodePage, ci.TextInfo.ANSICodePage); - Assert.Equal(cultureName, ci.TextInfo.CultureName); - Assert.Equal(CultureInfo.InvariantCulture.TextInfo.EBCDICCodePage, ci.TextInfo.EBCDICCodePage); - Assert.Equal(CultureInfo.InvariantCulture.TextInfo.IsRightToLeft, ci.TextInfo.IsRightToLeft); - Assert.Equal(ci.Name == "" ? 0x7F : 0x1000, ci.TextInfo.LCID); - Assert.Equal(CultureInfo.InvariantCulture.TextInfo.ListSeparator, ci.TextInfo.ListSeparator); - Assert.Equal(CultureInfo.InvariantCulture.TextInfo.MacCodePage, ci.TextInfo.MacCodePage); - Assert.Equal(CultureInfo.InvariantCulture.TextInfo.OEMCodePage, ci.TextInfo.OEMCodePage); + [Theory] + [MemberData(nameof(NativeName_TestData))] + public void TestNativeName(string cultureName, string expected) + { + CultureInfo myTestCulture = new CultureInfo(cultureName); + Assert.Equal(expected, myTestCulture.NativeName); + } - // - // CompareInfo - // - Assert.Equal(ci.Name == "" ? 0x7F : 0x1000, ci.CompareInfo.LCID); - Assert.True(cultureName.Equals(ci.CompareInfo.Name, StringComparison.OrdinalIgnoreCase));*/ + [Theory] + [InlineData("de-DE", "de")] + [InlineData("en-US", "en")] + public void TwoLetterISOLanguageName(string name, string expected) + { + Assert.Equal(expected, new CultureInfo(name).TwoLetterISOLanguageName); + } + + [Theory] + [InlineData("de-DE", "Deutsch (Deutschland)", "de (DE)")] + public void TestDisplayName(string cultureName, string nativeName, string englishDisplayName) + { + CultureInfo ci = CultureInfo.GetCultureInfo(cultureName); + Assert.Equal(nativeName, ci.NativeName); + Assert.Equal(englishDisplayName, ci.DisplayName); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index db4ba3927876a3..348a9e1a9121db 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -7,8 +7,7 @@ namespace System.Globalization { internal sealed partial class CultureData { - private bool InitCultureDataCore() => InitIcuCultureDataCore(); //GlobalizationMode.Hybrid ? InitNativeCultureDataCore() : InitIcuCultureDataCore(); - + private bool InitCultureDataCore() => InitIcuCultureDataCore(); // Unix doesn't support user overrides partial void InitUserOverride(bool useUserOverride); 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 65aded9e8010e5..e9708173a09b51 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -924,7 +924,7 @@ internal string CultureName // Parent name (which may be a custom locale/culture) // Ask using the real name, so that we get parents of neutrals - internal string ParentName => _sParent ??= string.Empty; + internal string ParentName => _sParent ??= GetLocaleInfoCore(_sRealName!, LocaleStringData.ParentName); // Localized pretty name for this locale (ie: Inglis (estados Unitos)) internal string DisplayName @@ -969,18 +969,15 @@ internal string EnglishName get { string? englishDisplayName = _sEnglishDisplayName; - System.Diagnostics.Debug.Write("Globalization EnglishName get englishDisplayName: " + englishDisplayName); if (englishDisplayName == null && !GlobalizationMode.Invariant) { // If its neutral use the language name if (IsNeutralCulture) { englishDisplayName = GetLocaleInfoCore(LocaleStringData.EnglishDisplayName); - System.Diagnostics.Debug.Write("Globalization EnglishName get IsNeutralCulture englishDisplayName: " + englishDisplayName); if (string.IsNullOrEmpty(englishDisplayName)) { englishDisplayName = EnglishLanguageName; - System.Diagnostics.Debug.Write("Globalization EnglishName get IsNeutralCulture nested if englishDisplayName: " + englishDisplayName); } // differentiate the legacy display names @@ -995,11 +992,9 @@ internal string EnglishName else { englishDisplayName = GetLocaleInfoCore(LocaleStringData.EnglishDisplayName); - System.Diagnostics.Debug.Write("Globalization EnglishName get else case englishDisplayName: " + englishDisplayName); // if it isn't found build one: if (string.IsNullOrEmpty(englishDisplayName)) { - System.Diagnostics.Debug.Write("Globalization EnglishName get still null englishDisplayName: " + englishDisplayName); // Our existing names mostly look like: // "English" + "United States" -> "English (United States)" // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)" @@ -1011,19 +1006,16 @@ internal string EnglishName ", ", EnglishCountryName, ")"); - System.Diagnostics.Debug.Write("Globalization EnglishName get concat englishDisplayName: " + englishDisplayName); } else { // "English" + "United States" -> "English (United States)" englishDisplayName = EnglishLanguageName + " (" + EnglishCountryName + ")"; - System.Diagnostics.Debug.Write("Globalization EnglishName get concat else englishDisplayName: " + englishDisplayName); } } } _sEnglishDisplayName = englishDisplayName; - System.Diagnostics.Debug.Write("Globalization EnglishName get final initialization englishDisplayName: " + englishDisplayName); } return englishDisplayName!; @@ -1549,7 +1541,6 @@ internal int FirstDayOfWeek if (_iFirstDayOfWeek == undef && !GlobalizationMode.Invariant) { _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() - //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(LocaleNumberData.FirstDayOfWeek) : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); } return _iFirstDayOfWeek; @@ -2295,9 +2286,7 @@ private int GetLocaleInfoCore(LocaleNumberData type) if (GlobalizationMode.Invariant) return 0; - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) - //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) - : IcuGetLocaleInfo(type); + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); } private int GetLocaleInfoCoreUserOverride(LocaleNumberData type) @@ -2306,9 +2295,7 @@ private int GetLocaleInfoCoreUserOverride(LocaleNumberData type) if (GlobalizationMode.Invariant) return 0; - return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) - //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) - : IcuGetLocaleInfo(type); + return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); } private string GetLocaleInfoCoreUserOverride(LocaleStringData type) @@ -2327,7 +2314,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; -// call this function + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); @@ -2350,16 +2337,13 @@ private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) if (GlobalizationMode.Invariant) return null!; - return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) - //: GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) - : IcuGetLocaleInfo(type); + return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); } /// /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes. /// - //important private enum LocaleStringData : uint { /// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index 24a97a401e956b..507ba68763d019 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -24,76 +24,16 @@ private bool InitNativeCultureDataCore() Debug.Assert(_sRealName != null); Debug.Assert(!GlobalizationMode.Invariant); string realNameBuffer = _sRealName; - /* const string ICU_COLLATION_KEYWORD = "@collation="; - - // Basic validation - if (!IsValidCultureName(realNameBuffer, out var index)) - { - return false; - } - - // Replace _ (alternate sort) with @collation= for ICU - ReadOnlySpan alternateSortName = default; - if (index > 0) - { - alternateSortName = realNameBuffer.AsSpan(index + 1); - realNameBuffer = string.Concat(realNameBuffer.AsSpan(0, index), ICU_COLLATION_KEYWORD, alternateSortName); - }*/ // Get the locale name - if (!NativeGetLocaleName(realNameBuffer, out _sWindowsName)) - { - return false; // fail - } - - /* // Replace the ICU collation keyword with an _ - Debug.Assert(_sWindowsName != null); - index = _sWindowsName.IndexOf(ICU_COLLATION_KEYWORD, StringComparison.Ordinal); - if (index >= 0) - { - // Use original culture name if alternateSortName is not set, which is possible even if the normalized - // culture name has "@collation=". - // "zh-TW-u-co-zhuyin" is a good example. The term "u-co-" means the following part will be the sort name - // and it will be treated in ICU as "zh-TW@collation=zhuyin". - _sName = alternateSortName.Length == 0 ? realNameBuffer : string.Concat(_sWindowsName.AsSpan(0, index), "_", alternateSortName); - } - else - { - _sName = _sWindowsName; - } - _sRealName = _sName; - - _iLanguage = LCID; - if (_iLanguage == 0) - { - _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED; - } - _bNeutral = TwoLetterISOCountryName.Length == 0; - // Implement for native - //_sSpecificCulture = _bNeutral ? IcuLocaleData.GetSpecificCultureName(_sRealName) : _sRealName; - // Remove the sort from sName unless custom culture - if (index > 0 && !_bNeutral && !IsCustomCultureId(_iLanguage)) - { - _sName = _sWindowsName.Substring(0, index); - }*/ + NativeGetLocaleName(realNameBuffer, out _sWindowsName); return true; } internal static unsafe bool NativeGetLocaleName(string localeName, out string? windowsName) { - // Is this needed for native? - // Get the locale name from ICU - char* buffer = stackalloc char[Native_ULOC_FULLNAME_CAPACITY]; - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleName is called"); System.Diagnostics.Debug.Write("Globalization NativeGetLocaleName is called localeName: " + localeName); - if (!Interop.Globalization.NativeGetLocaleName(localeName, buffer, Native_ULOC_FULLNAME_CAPACITY)) - { - windowsName = null; - return false; // fail - } - - // Success - use the locale name returned which may be different than realNameBuffer (casing) - windowsName = new string(buffer); // the name passed to subsequent ICU calls + windowsName = Interop.Globalization.NativeGetLocaleName(localeName, Native_ULOC_FULLNAME_CAPACITY); return true; } @@ -109,41 +49,13 @@ private string NativeGetLocaleInfo(LocaleStringData type, string? uiCultureName // "windows" name, which can be specific for downlevel (< windows 7) os's. private static unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData type, string? uiCultureName = null) { - // Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(localeName != null, "[CultureData.NativeGetLocaleInfo] Expected localeName to be not be null"); - Debug.Write("Globalization NativeGetLocaleInfo is called"); System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called localeName: " + localeName); - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called type: " + type.ToString()); string result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called result: " + result); return result; } - - /*private int NativeGetLocaleInfo(LocaleNumberData type) - { - Debug.Assert(!GlobalizationMode.UseNls); - - Debug.Assert(_sWindowsName != null, "[CultureData.NativeGetLocaleInfoInt(LocaleNumberData)] Expected _sWindowsName to be populated already"); - - switch (type) - { - case LocaleNumberData.CalendarType: - // returning 0 will cause the first supported calendar to be returned, which is the preferred calendar - return 0; - } - - - int value = 0; - bool result = Interop.Globalization.NativeGetLocaleInfoInt(_sWindowsName, (uint)type, ref value); - if (!result) - { - // Failed, just use 0 - Debug.Fail("[CultureData.NativeGetLocaleInfoInt(LocaleNumberData)] failed"); - } - - return value; - }*/ } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs index d0435c88c7630d..d5c1f218c81619 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs @@ -470,7 +470,6 @@ public static CultureInfo InvariantCulture /// /// Return the parent CultureInfo for the current instance. /// - // public virtual CultureInfo Parent { get diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 704692fe50655d..9560aac0e87ff9 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -35,8 +35,6 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_GetLocaleInfoGroupingSizes) DllImportEntry(GlobalizationNative_GetLocaleInfoInt) DllImportEntry(GlobalizationNative_GetLocaleInfoString) - DllImportEntry(Native_GetLocaleName) - DllImportEntry(NativeGetLocaleInfoString) DllImportEntry(GlobalizationNative_GetLocaleName) DllImportEntry(GlobalizationNative_GetLocales) DllImportEntry(GlobalizationNative_GetLocaleTimeFormat) @@ -60,6 +58,8 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_ToAscii) DllImportEntry(GlobalizationNative_ToUnicode) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) + DllImportEntry(NativeGetLocaleName) + DllImportEntry(NativeGetLocaleInfoString) }; EXTERN_C const void* GlobalizationResolveDllImport(const char* name); diff --git a/src/native/libs/System.Globalization.Native/pal_locale.c b/src/native/libs/System.Globalization.Native/pal_locale.c index 32ce3f5c424b52..eada9f12ddd39f 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.c +++ b/src/native/libs/System.Globalization.Native/pal_locale.c @@ -212,29 +212,6 @@ int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, return UErrorCodeToBool(status); } -int32_t Native_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength) -{ - UErrorCode status = U_ZERO_ERROR; - - /* char localeNameBuffer[ULOC_FULLNAME_CAPACITY]; - GetLocale(localeName, localeNameBuffer, ULOC_FULLNAME_CAPACITY, true, &status); - u_charsToUChars_safe(localeNameBuffer, value, valueLength, &status); - - if (U_SUCCESS(status)) - { - FixupLocaleName(value, valueLength); - }*/ - -#ifdef __APPLE__ - - return NativeGetLocaleName(localeName, - value, - valueLength); -#endif - - return UErrorCodeToBool(status); -} - int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength) { char localeNameBuffer[ULOC_FULLNAME_CAPACITY]; diff --git a/src/native/libs/System.Globalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_locale.h index 10cb152d1934a4..bfd721e6ddde0d 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_locale.h @@ -9,7 +9,7 @@ PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLeng PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); -PALEXPORT int32_t Native_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); +PALEXPORT const char* NativeGetLocaleName(const char* localeName, int32_t valueLength); PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index f30ba3bf3ad7f8..bb48e91d394f5c 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -31,14 +31,13 @@ return strdup([localeName UTF8String]); } -int32_t NativeGetLocaleName(const UChar* localeName, - UChar* value, +const char* NativeGetLocaleName(const char* localeName, int32_t valueLength) { - UErrorCode status = U_ZERO_ERROR; - NSLocale *currentLocale = [NSLocale currentLocale]; - value = (UChar *)[currentLocale.localeIdentifier UTF8String]; - return UErrorCodeToBool(status); + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + const char* value = [currentLocale.localeIdentifier UTF8String]; + return strdup(value); } const char* NativeGetLocaleInfoString(const char* localeName, @@ -46,168 +45,133 @@ int32_t NativeGetLocaleName(const UChar* localeName, int32_t valueLength, const char* uiLocaleName) { - NSLog(@"NSLog NativeGetLocaleInfoString is running"); - // NSLocale *currentLocale = [NSLocale currentLocale]; - NSLocale *locale = [NSLocale autoupdatingCurrentLocale]; - NSString *s = [NSString stringWithFormat:@"%s", localeName]; - - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:s]; - const char* value; - - NSLog(@"NSLog NativeGetLocaleInfoString is running after NSLocale"); - // UErrorCode status = U_ZERO_ERROR; + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; numberFormatter.locale = currentLocale; - //NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; - //[calendar setLocale:currentLocale]; - NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; - timeFormatter.locale = currentLocale; + NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setLocale:currentLocale]; + NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; - NSLog(@"NSLog NativeGetLocaleInfoString is running after NSNumberFormatter"); - switch (localeStringData) { + ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) case LocaleString_LocalizedDisplayName: - NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); - value = [[currentLocale localizedStringForLocaleIdentifier:currentLocale.localeIdentifier] UTF8String]; + value = [[gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier] UTF8String]; break; + /// Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME) case LocaleString_EnglishDisplayName: - NSLog(@"NSLog LocaleString_EnglishDisplayName case is running"); - value = [currentLocale.localeIdentifier UTF8String]; + value = [[gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier] UTF8String]; break; + /// Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME) case LocaleString_NativeDisplayName: - NSLog(@"NSLog LocaleString_NativeDisplayName case is running"); - value = [currentLocale.localeIdentifier UTF8String]; + value = [[currentLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier] UTF8String]; break; + /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) case LocaleString_LocalizedLanguageName: - NSLog(@"NSLog LocaleString_LocalizedLanguageName case is running"); - value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + value = [[gbLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; break; + /// English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME) case LocaleString_EnglishLanguageName: - NSLog(@"NSLog LocaleString_EnglishLanguageName case is running"); - value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; + value = [[gbLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; break; + /// native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME) case LocaleString_NativeLanguageName: - NSLog(@"NSLog LocaleString_NativeLanguageName case is running"); value = [[currentLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; break; + /// English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME) case LocaleString_EnglishCountryName: - NSLog(@"NSLog LocaleString_EnglishCountryName case is running"); - value = [[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; + value = [[gbLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; break; + /// native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME) case LocaleString_NativeCountryName: - NSLog(@"NSLog LocaleString_NativeCountryName case is running"); value = [[currentLocale localizedStringForCountryCode:currentLocale.countryCode] UTF8String]; break; case LocaleString_ThousandSeparator: - NSLog(@"NSLog LocaleString_ThousandSeparator case is running"); value = [currentLocale.groupingSeparator UTF8String]; break; case LocaleString_DecimalSeparator: - NSLog(@"NSLog LocaleString_DecimalSeparator case is running"); value = [currentLocale.decimalSeparator UTF8String]; + // or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String]; break; case LocaleString_Digits: - NSLog(@"NSLog LocaleString_Digits case is running"); - // TODO fake value - value = [currentLocale.currencySymbol UTF8String]; + // TODO find mapping for Digits + value = "0123456789"; break; case LocaleString_MonetarySymbol: - NSLog(@"NSLog LocaleString_MonetarySymbol case is running"); value = [currentLocale.currencySymbol UTF8String]; break; case LocaleString_Iso4217MonetarySymbol: - NSLog(@"NSLog LocaleString_Iso4217MonetarySymbol case is running"); - // check if this is correct + // check if this is correct, check currencyISOCode value = [currentLocale.currencySymbol UTF8String]; break; case LocaleString_CurrencyEnglishName: - NSLog(@"NSLog LocaleString_CurrencyEnglishName case is running"); - value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; + value = [[gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; break; case LocaleString_CurrencyNativeName: - NSLog(@"NSLog LocaleString_CurrencyNativeName case is running"); value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; break; case LocaleString_MonetaryDecimalSeparator: - NSLog(@"NSLog LocaleString_MonetaryDecimalSeparator case is running"); - // TODO fake value - value = [locale.localeIdentifier UTF8String]; + // TODO find mapping for MonetaryDecimalSeparator + value = ""; break; case LocaleString_MonetaryThousandSeparator: - NSLog(@"NSLog LocaleString_MonetaryThousandSeparator case is running"); - // TODO fake value - value = [locale.localeIdentifier UTF8String]; + // TODO find mapping for MonetaryThousandSeparator + value = ""; break; case LocaleString_AMDesignator: - NSLog(@"NSLog LocaleString_AMDesignator case is running"); - // TODO fake value - value = [timeFormatter.AMSymbol UTF8String]; + value = [dateFormatter.AMSymbol UTF8String]; break; case LocaleString_PMDesignator: - NSLog(@"NSLog LocaleString_PMDesignator case is running"); - // TODO fake value - value = [timeFormatter.pmSymbol UTF8String]; + value = [dateFormatter.PMSymbol UTF8String]; break; case LocaleString_PositiveSign: - NSLog(@"NSLog LocaleString_PositiveSign case is running"); value = [numberFormatter.plusSign UTF8String]; break; case LocaleString_NegativeSign: - NSLog(@"NSLog LocaleString_NegativeSign case is running"); value = [numberFormatter.minusSign UTF8String]; break; case LocaleString_Iso639LanguageTwoLetterName: - NSLog(@"NSLog LocaleString_LocalizedDisplayName case is running"); - // TODO fake value - value = [locale.localeIdentifier UTF8String]; + // check if this is correct + value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String]; break; case LocaleString_Iso639LanguageThreeLetterName: - NSLog(@"NSLog LocaleString_Iso639LanguageThreeLetterName case is running"); - // TODO fake value - value = [locale.localeIdentifier UTF8String]; + // TODO find mapping for Iso639LanguageThreeLetterName + // check ISOLanguageCodes + value = [currentLocale.languageCode UTF8String]; break; case LocaleString_Iso3166CountryName: - NSLog(@"NSLog LocaleString_Iso3166CountryName case is running"); value = [currentLocale.countryCode UTF8String]; break; case LocaleString_Iso3166CountryName2: - NSLog(@"NSLog LocaleString_Iso3166CountryName2 case is running"); - // TODO fake value - value = [locale.localeIdentifier UTF8String]; + // TODO find mapping for Iso3166CountryName2 + value = [currentLocale.countryCode UTF8String]; break; case LocaleString_NaNSymbol: - NSLog(@"NSLog LocaleString_NaNSymbol case is running"); value = [numberFormatter.notANumberSymbol UTF8String]; break; case LocaleString_PositiveInfinitySymbol: - NSLog(@"NSLog LocaleString_PositiveInfinitySymbol case is running"); value = [numberFormatter.positiveInfinitySymbol UTF8String]; break; case LocaleString_NegativeInfinitySymbol: - NSLog(@"NSLog LocaleString_NegativeInfinitySymbol case is running"); value = [numberFormatter.negativeInfinitySymbol UTF8String]; break; case LocaleString_ParentName: - NSLog(@"NSLog LocaleString_ParentName case is running"); - // TODO fake value - value = [locale.localeIdentifier UTF8String]; + // TODO find mapping for ParentName + value = ""; break; case LocaleString_PercentSymbol: - NSLog(@"NSLog LocaleString_PercentSymbol case is running"); value = [numberFormatter.percentSymbol UTF8String]; break; case LocaleString_PerMilleSymbol: - NSLog(@"NSLog LocaleString_PerMilleSymbol case is running"); value = [numberFormatter.perMillSymbol UTF8String]; break; default: - NSLog(@"NSLog default case is running"); break; } - NSLog(@"Globalization nativeGetLocaleInfo value: %s", value); + NSLog(@"Globalization nativeGetLocaleInfo value: %s", value); return strdup(value); } diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.c b/src/native/libs/System.Globalization.Native/pal_localeStringData.c index 210c2e1f8ab637..9120b89bd329bd 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.c +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.c @@ -6,11 +6,9 @@ #include #include #include -#include #include "pal_locale_internal.h" #include "pal_localeStringData.h" -#include /* Function: @@ -403,7 +401,6 @@ int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, return UErrorCodeToBool(status); } - /* PAL Function: GetLocaleTimeFormat diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index f272bc4d0249a4..fa9d49ae153fa5 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -68,8 +68,7 @@ NativeGetLocaleName NativeGetLocaleName for Apple platforms */ -int32_t NativeGetLocaleName(const UChar* localeName, - UChar* value, +const char* NativeGetLocaleName(const char* localeName, int32_t valueLength); /* From 60e090ad520f1016d14c0fff78adf016f13bdb21 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 08:18:39 +0100 Subject: [PATCH 09/25] Removed comments --- .../System.Globalization/tests/CultureInfo/CultureInfoAll.cs | 1 - .../tests/CultureInfo/CultureInfoEnglishName.cs | 4 ---- .../tests/CultureInfo/CultureInfoNativeName.cs | 2 -- .../src/System/Globalization/CultureData.Unix.cs | 1 + .../src/System/Globalization/CultureData.cs | 4 ++-- .../src/System/Globalization/CultureData.iOS.cs | 3 --- 6 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs index f621aac50eb951..c82e17f11163c8 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoAll.cs @@ -826,7 +826,6 @@ public void CultureNotFoundExceptionTest() [Theory] [PlatformSpecific(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] // for these platforms cultures are taken from icu filters [InlineData("nb-NO")] - // check this test public void ContainsCulture(string culture) { var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index e1b319df9eb1ee..67a19e61401164 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -33,10 +33,6 @@ public static IEnumerable EnglishName_TestData() [MemberData(nameof(EnglishName_TestData))] public void EnglishName(string name, string expected) { - // Add here test - System.Console.WriteLine("Globalization mode is IsInvariantGlobalization: " + PlatformDetection.IsInvariantGlobalization); - System.Console.WriteLine("Globalization mode is IsHybridGlobalization: " + PlatformDetection.IsHybridGlobalization); - System.Console.WriteLine("Globalization log EnglishName: " + name); CultureInfo myTestCulture = new CultureInfo(name); Assert.Equal(expected, myTestCulture.EnglishName); } diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs index 2f016ce394388e..8293613177688c 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs @@ -30,8 +30,6 @@ public static IEnumerable NativeName_TestData() [MemberData(nameof(NativeName_TestData))] public void NativeName(string name, string expected) { - // Add here test - System.Console.WriteLine("Globalization log NativeName: " + name); CultureInfo myTestCulture = new CultureInfo(name); Assert.Equal(expected, myTestCulture.NativeName); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index 348a9e1a9121db..2a253d5367be30 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -8,6 +8,7 @@ namespace System.Globalization internal sealed partial class CultureData { private bool InitCultureDataCore() => InitIcuCultureDataCore(); + // Unix doesn't support user overrides partial void InitUserOverride(bool useUserOverride); 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 e9708173a09b51..b1478b64482ef2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -992,6 +992,7 @@ internal string EnglishName else { englishDisplayName = GetLocaleInfoCore(LocaleStringData.EnglishDisplayName); + // if it isn't found build one: if (string.IsNullOrEmpty(englishDisplayName)) { @@ -1540,8 +1541,7 @@ internal int FirstDayOfWeek { if (_iFirstDayOfWeek == undef && !GlobalizationMode.Invariant) { - _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() - : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); + _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); } return _iFirstDayOfWeek; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index 507ba68763d019..2795ac06a85dbf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -32,7 +32,6 @@ private bool InitNativeCultureDataCore() internal static unsafe bool NativeGetLocaleName(string localeName, out string? windowsName) { - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleName is called localeName: " + localeName); windowsName = Interop.Globalization.NativeGetLocaleName(localeName, Native_ULOC_FULLNAME_CAPACITY); return true; } @@ -52,9 +51,7 @@ private static unsafe string NativeGetLocaleInfo(string localeName, LocaleString Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(localeName != null, "[CultureData.NativeGetLocaleInfo] Expected localeName to be not be null"); - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called localeName: " + localeName); string result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); - System.Diagnostics.Debug.Write("Globalization NativeGetLocaleInfo is called result: " + result); return result; } } From 26ce9a9b2fea0d4a4b86ffba664c39554745a43a Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 08:21:37 +0100 Subject: [PATCH 10/25] updated --- src/libraries/Common/src/Interop/Interop.Locale.iOS.cs | 1 - .../src/System/Globalization/CultureData.iOS.cs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index 45dcb3348c9a3d..ff4dcb506dcffc 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -3,7 +3,6 @@ using System.Runtime.InteropServices; using System; -// internal static partial class Interop { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index 2795ac06a85dbf..dce75758c9cf67 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -15,7 +15,7 @@ internal sealed partial class CultureData private const int Native_ULOC_KEYWORD_AND_VALUES_CAPACITY = 100; // max size of keyword or value private const int Native_ULOC_FULLNAME_CAPACITY = 157; // max size of locale name - /// + /// /// This method uses the sRealName field (which is initialized by the constructor before this is called) to /// initialize the rest of the state of CultureData based on the underlying OS globalization library. /// @@ -41,6 +41,7 @@ private string NativeGetLocaleInfo(LocaleStringData type, string? uiCultureName Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(_sWindowsName != null, "[CultureData.NativeGetLocaleInfo] Expected _sWindowsName to be populated already"); + return NativeGetLocaleInfo(_sWindowsName, type, uiCultureName); } From dc347f5514580951fccaeda6013376eb18859f65 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 08:48:35 +0100 Subject: [PATCH 11/25] native functions only for apple platforms --- src/native/libs/System.Globalization.Native/pal_locale.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 977375ce87548e..6affceb6609b5e 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -31,6 +31,8 @@ return strdup([localeName UTF8String]); } +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) + const char* NativeGetLocaleName(const char* localeName, int32_t valueLength) { @@ -175,7 +177,7 @@ return strdup(value); } -#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) + const char* GlobalizationNative_GetICUDataPathFallback(void) { NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"]; From 09d599e8df305e99e6e0523e775e18041f1e6348 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 14:42:35 +0100 Subject: [PATCH 12/25] Native functions only for apple --- src/native/libs/System.Globalization.Native/entrypoints.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 9560aac0e87ff9..387c868c7be4e0 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -58,8 +58,10 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_ToAscii) DllImportEntry(GlobalizationNative_ToUnicode) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) DllImportEntry(NativeGetLocaleName) DllImportEntry(NativeGetLocaleInfoString) +#endif }; EXTERN_C const void* GlobalizationResolveDllImport(const char* name); From bacc22745e7c03dc2cd1557b835dfe2409213446 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 16:53:49 +0100 Subject: [PATCH 13/25] build native functions only for ios --- .../src/System.Private.CoreLib.Shared.projitems | 2 +- .../src/System/Globalization/CultureData.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index b05612194915a3..0c6d8c116279f7 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -346,7 +346,7 @@ - + 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 b1478b64482ef2..ff6540b913f1cc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2303,10 +2303,12 @@ private string GetLocaleInfoCoreUserOverride(LocaleStringData type) // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; - +#if TARGET_IOS return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) : IcuGetLocaleInfo(type); +#endif + return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); } private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = null) @@ -2314,10 +2316,12 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; - +#if TARGET_IOS return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); +#endif + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); } private string GetLocaleInfoCore(string localeName, LocaleStringData type, string? uiCultureName = null) @@ -2325,10 +2329,12 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; - +#if TARGET_IOS return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(localeName, type, uiCultureName) : IcuGetLocaleInfo(localeName, type, uiCultureName); +#endif + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); } private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) From e844a4092c3d27e9ab3c95987fc40b501ad224b6 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 2 Mar 2023 17:14:33 +0100 Subject: [PATCH 14/25] Include ios file only for ios --- .../src/System.Private.CoreLib.Shared.projitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 0c6d8c116279f7..f0dbeac4d39d90 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1278,7 +1278,7 @@ Common\Interop\Interop.Locale.cs - + Common\Interop\Interop.Locale.iOS.cs From 46c9e689280943ad81ba2152e3a0237b803d4a00 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 15 Mar 2023 18:30:07 +0100 Subject: [PATCH 15/25] refactored --- docs/workflow/trimming/feature-switches.md | 2 +- .../Common/src/Interop/Interop.Locale.iOS.cs | 8 ++-- .../TestUtilities/System/PlatformDetection.cs | 4 -- .../ILLink/ILLink.Substitutions.Shared.xml | 2 +- .../src/System/Globalization/CultureData.cs | 27 +++++------ .../System/Globalization/CultureData.iOS.cs | 20 ++++---- .../System/Globalization/GlobalizationMode.cs | 4 ++ .../System.Globalization.Native/entrypoints.c | 6 +-- .../System.Globalization.Native/pal_locale.h | 2 +- .../System.Globalization.Native/pal_locale.m | 46 +++++-------------- .../pal_localeStringData.h | 2 +- .../pal_locale_internal.h | 12 ++--- 12 files changed, 54 insertions(+), 81 deletions(-) diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index d8a46f517248bf..c8182f9ff04306 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -13,8 +13,8 @@ configurations but their defaults might vary as any SDK can set the defaults dif | EnableUnsafeBinaryFormatterSerialization | System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization | BinaryFormatter serialization support is trimmed when set to false | | EventSourceSupport | System.Diagnostics.Tracing.EventSource.IsSupported | Any EventSource related code or logic is trimmed when set to false | | InvariantGlobalization | System.Globalization.Invariant | All globalization specific code and data is trimmed when set to true | -| PredefinedCulturesOnly | System.Globalization.PredefinedCulturesOnly | Don't allow creating a culture for which the platform does not have data | | HybridGlobalization | System.Globalization.Hybrid | Loading ICU + native implementations | +| PredefinedCulturesOnly | System.Globalization.PredefinedCulturesOnly | Don't allow creating a culture for which the platform does not have data | | UseSystemResourceKeys | System.Resources.UseSystemResourceKeys | Any localizable resources for system assemblies is trimmed when set to true | | HttpActivityPropagationSupport | System.Net.Http.EnableActivityPropagation | Any dependency related to diagnostics support for System.Net.Http is trimmed when set to false | | UseNativeHttpHandler | System.Net.Http.UseNativeHttpHandler | HttpClient uses by default platform native implementation of HttpMessageHandler if set to true. | diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index ff4dcb506dcffc..74ff348fdf9e01 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -8,10 +8,10 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "NativeGetLocaleName", StringMarshalling = StringMarshalling.Utf16)] - internal static unsafe partial string NativeGetLocaleName(string localeName, int valueLength); + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial string GetLocaleNameNative(string localeName, int valueLength); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "NativeGetLocaleInfoString", StringMarshalling = StringMarshalling.Utf8)] - internal static unsafe partial string NativeGetLocaleInfoString(string localeName, uint localeStringData, int valueLength, string? uiLocaleName = null); + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] + internal static unsafe partial string GetLocaleInfoStringNative(string localeName, uint localeStringData, int valueLength, string? uiLocaleName = null); } } diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 74378ce652ec58..6e43ad25bc6b50 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -348,9 +348,6 @@ public static string GetDistroVersionString() private static readonly Lazy m_isInvariant = new Lazy(() => (bool?)Type.GetType("System.Globalization.GlobalizationMode")?.GetProperty("Invariant", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) == true); - private static readonly Lazy m_isHybrid = new Lazy(() - => (bool?)Type.GetType("System.Globalization.GlobalizationMode")?.GetProperty("Hybrid", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) == true); - private static readonly Lazy m_icuVersion = new Lazy(GetICUVersion); public static Version ICUVersion => m_icuVersion.Value; @@ -358,7 +355,6 @@ public static string GetDistroVersionString() public static bool IsNotInvariantGlobalization => !IsInvariantGlobalization; public static bool IsIcuGlobalization => ICUVersion > new Version(0, 0, 0, 0); public static bool IsNlsGlobalization => IsNotInvariantGlobalization && !IsIcuGlobalization; - public static bool IsHybridGlobalization => m_isHybrid.Value; public static bool IsSubstAvailable { diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml index f919b0fe6d6f74..09b8a2f61e299e 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml @@ -15,7 +15,7 @@ - + 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 ff6540b913f1cc..91bfa183b8f05d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2303,12 +2303,11 @@ private string GetLocaleInfoCoreUserOverride(LocaleStringData type) // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; -#if TARGET_IOS - return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) - : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type) - : IcuGetLocaleInfo(type); -#endif +#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST + return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); +#else return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); +#endif } private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = null) @@ -2316,12 +2315,11 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; -#if TARGET_IOS - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) - : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(type, uiCultureName) - : IcuGetLocaleInfo(type, uiCultureName); -#endif +#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST + return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); +#else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); +#endif } private string GetLocaleInfoCore(string localeName, LocaleStringData type, string? uiCultureName = null) @@ -2329,12 +2327,11 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; -#if TARGET_IOS - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) - : GlobalizationMode.Hybrid ? NativeGetLocaleInfo(localeName, type, uiCultureName) - : IcuGetLocaleInfo(localeName, type, uiCultureName); -#endif +#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST + return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type, uiCultureName) : IcuGetLocaleInfo(localeName, type, uiCultureName); +#else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); +#endif } private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index dce75758c9cf67..cd1b4190063a93 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -26,33 +26,31 @@ private bool InitNativeCultureDataCore() string realNameBuffer = _sRealName; // Get the locale name - NativeGetLocaleName(realNameBuffer, out _sWindowsName); + GetLocaleNameNative(realNameBuffer, out _sWindowsName); return true; } - internal static unsafe bool NativeGetLocaleName(string localeName, out string? windowsName) + internal static unsafe bool GetLocaleNameNative(string localeName, out string? windowsName) { - windowsName = Interop.Globalization.NativeGetLocaleName(localeName, Native_ULOC_FULLNAME_CAPACITY); + windowsName = Interop.Globalization.GetLocaleNameNative(localeName, Native_ULOC_FULLNAME_CAPACITY); return true; } - private string NativeGetLocaleInfo(LocaleStringData type, string? uiCultureName = null) + private string GetLocaleInfoNative(LocaleStringData type, string? uiCultureName = null) { Debug.Assert(!GlobalizationMode.Invariant); - Debug.Assert(!GlobalizationMode.UseNls); - Debug.Assert(_sWindowsName != null, "[CultureData.NativeGetLocaleInfo] Expected _sWindowsName to be populated already"); + Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfoNative] Expected _sWindowsName to be populated already"); - return NativeGetLocaleInfo(_sWindowsName, type, uiCultureName); + return GetLocaleInfoNative(_sWindowsName, type, uiCultureName); } // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the // "windows" name, which can be specific for downlevel (< windows 7) os's. - private static unsafe string NativeGetLocaleInfo(string localeName, LocaleStringData type, string? uiCultureName = null) + private static unsafe string GetLocaleInfoNative(string localeName, LocaleStringData type, string? uiCultureName = null) { - Debug.Assert(!GlobalizationMode.UseNls); - Debug.Assert(localeName != null, "[CultureData.NativeGetLocaleInfo] Expected localeName to be not be null"); + Debug.Assert(localeName != null, "[CultureData.GetLocaleInfoNative] Expected localeName to be not be null"); - string result = Interop.Globalization.NativeGetLocaleInfoString(localeName, (uint)type, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); + string result = Interop.Globalization.GetLocaleInfoStringNative(localeName, (uint)type, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); return result; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index 9b0d9429e5ba18..8734573065344a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -13,7 +13,9 @@ internal static partial class GlobalizationMode private static partial class Settings { internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); +#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); +#endif internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", GlobalizationMode.Invariant); } @@ -21,7 +23,9 @@ private static partial class Settings // This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings // static cctor (on Unix) to be preserved when Invariant=false. internal static bool Invariant => Settings.Invariant; +#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST internal static bool Hybrid => Settings.Hybrid; +#endif internal static bool PredefinedCulturesOnly => Settings.PredefinedCulturesOnly; private static bool TryGetAppLocalIcuSwitchValue([NotNullWhen(true)] out string? value) => diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 387c868c7be4e0..10254d6256db4a 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -58,9 +58,9 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_ToAscii) DllImportEntry(GlobalizationNative_ToUnicode) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) -#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) - DllImportEntry(NativeGetLocaleName) - DllImportEntry(NativeGetLocaleInfoString) +#ifdef __APPLE__ + DllImportEntry(GlobalizationNative_GetLocaleNameNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoStringNative) #endif }; diff --git a/src/native/libs/System.Globalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_locale.h index bfd721e6ddde0d..983069490d9349 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_locale.h @@ -9,7 +9,7 @@ PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLeng PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); -PALEXPORT const char* NativeGetLocaleName(const char* localeName, int32_t valueLength); +PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, int32_t valueLength); PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 6affceb6609b5e..ce0806abe41813 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -7,8 +7,6 @@ #import #import -#include "pal_localeStringData.h" - char* DetectDefaultAppleLocaleName() { NSLocale *currentLocale = [NSLocale currentLocale]; @@ -33,7 +31,7 @@ #if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) -const char* NativeGetLocaleName(const char* localeName, +const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, int32_t valueLength) { NSString *locName = [NSString stringWithFormat:@"%s", localeName]; @@ -42,7 +40,7 @@ return strdup(value); } -const char* NativeGetLocaleInfoString(const char* localeName, +const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, int32_t valueLength, const char* uiLocaleName) @@ -61,8 +59,6 @@ { ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) case LocaleString_LocalizedDisplayName: - value = [[gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier] UTF8String]; - break; /// Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME) case LocaleString_EnglishDisplayName: value = [[gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier] UTF8String]; @@ -73,8 +69,6 @@ break; /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) case LocaleString_LocalizedLanguageName: - value = [[gbLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; - break; /// English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME) case LocaleString_EnglishLanguageName: value = [[gbLocale localizedStringForLanguageCode:currentLocale.languageCode] UTF8String]; @@ -98,10 +92,6 @@ value = [currentLocale.decimalSeparator UTF8String]; // or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String]; break; - case LocaleString_Digits: - // TODO find mapping for Digits - value = "0123456789"; - break; case LocaleString_MonetarySymbol: value = [currentLocale.currencySymbol UTF8String]; break; @@ -115,14 +105,6 @@ case LocaleString_CurrencyNativeName: value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String]; break; - case LocaleString_MonetaryDecimalSeparator: - // TODO find mapping for MonetaryDecimalSeparator - value = ""; - break; - case LocaleString_MonetaryThousandSeparator: - // TODO find mapping for MonetaryThousandSeparator - value = ""; - break; case LocaleString_AMDesignator: value = [dateFormatter.AMSymbol UTF8String]; break; @@ -139,18 +121,9 @@ // check if this is correct value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String]; break; - case LocaleString_Iso639LanguageThreeLetterName: - // TODO find mapping for Iso639LanguageThreeLetterName - // check ISOLanguageCodes - value = [currentLocale.languageCode UTF8String]; - break; case LocaleString_Iso3166CountryName: value = [currentLocale.countryCode UTF8String]; break; - case LocaleString_Iso3166CountryName2: - // TODO find mapping for Iso3166CountryName2 - value = [currentLocale.countryCode UTF8String]; - break; case LocaleString_NaNSymbol: value = [numberFormatter.notANumberSymbol UTF8String]; break; @@ -160,20 +133,25 @@ case LocaleString_NegativeInfinitySymbol: value = [numberFormatter.negativeInfinitySymbol UTF8String]; break; - case LocaleString_ParentName: - // TODO find mapping for ParentName - value = ""; - break; case LocaleString_PercentSymbol: value = [numberFormatter.percentSymbol UTF8String]; break; case LocaleString_PerMilleSymbol: value = [numberFormatter.perMillSymbol UTF8String]; break; + // TODO find mapping for below cases + case LocaleString_Digits: + case LocaleString_MonetaryDecimalSeparator: + case LocaleString_MonetaryThousandSeparator: + case LocaleString_Iso639LanguageThreeLetterName: + case LocaleString_ParentName: + case LocaleString_Iso3166CountryName2: + value = ""; + break; default: break; } - NSLog(@"Globalization nativeGetLocaleInfo value: %s", value); + NSLog(@"Globalization GlobalizationNative_GetLocaleInfoStringNative value: %s", value); return strdup(value); } diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index c3a7082e4039ca..bb8cd4a8bc56c3 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -51,7 +51,7 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeNam int32_t valueLength, const UChar* uiLocaleName); -PALEXPORT const char* NativeGetLocaleInfoString(const char* localeName, +PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, int32_t valueLength, const char* uiLocaleName); diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index fa9d49ae153fa5..3e96e550271c0c 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -64,20 +64,20 @@ char* DetectDefaultAppleLocaleName(void); /* Function: -NativeGetLocaleName +GlobalizationNative_GetLocaleNameNative -NativeGetLocaleName for Apple platforms +GlobalizationNative_GetLocaleNameNative for Apple platforms */ -const char* NativeGetLocaleName(const char* localeName, +const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, int32_t valueLength); /* Function: -NativeGetLocaleInfoString +GlobalizationNative_GetLocaleInfoStringNative -NativeGetLocaleInfoString for Apple platforms +GlobalizationNative_GetLocaleInfoStringNative for Apple platforms */ -const char* NativeGetLocaleInfoString(const char* localeName, +const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, int32_t valueLength, const char* uiLocaleName); From 1b7aa373b7b4f2c3a6ca3b7593fc69059cfb7180 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 16 Mar 2023 14:21:59 +0100 Subject: [PATCH 16/25] Run hybrid tests only for ioslike platforms --- .../System.Globalization/tests/Hybrid/Hybrid.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj index 85b9cc33534896..4e1dfbc90a0ec5 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj +++ b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj @@ -1,6 +1,6 @@ - $(NetCoreAppCurrent) + $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst true true false From 789613b13b33c5bad982deaaf40c49e11c92319e Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 16 Mar 2023 15:39:04 +0100 Subject: [PATCH 17/25] done updates requested by review --- .../System.Globalization/tests/Hybrid/HybridMode.cs | 6 +++--- .../src/System/Globalization/CultureData.cs | 2 +- src/native/libs/System.Globalization.Native/pal_locale.m | 2 ++ .../libs/System.Globalization.Native/pal_localeStringData.h | 1 - 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs index 26ca0af5a34ca5..c57fa9a6a614f7 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs +++ b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs @@ -55,9 +55,9 @@ public void TwoLetterISOLanguageName(string name, string expected) [InlineData("de-DE", "Deutsch (Deutschland)", "de (DE)")] public void TestDisplayName(string cultureName, string nativeName, string englishDisplayName) { - CultureInfo ci = CultureInfo.GetCultureInfo(cultureName); - Assert.Equal(nativeName, ci.NativeName); - Assert.Equal(englishDisplayName, ci.DisplayName); + CultureInfo ci = CultureInfo.GetCultureInfo(cultureName); + Assert.Equal(nativeName, ci.NativeName); + Assert.Equal(englishDisplayName, ci.DisplayName); } } } 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 91bfa183b8f05d..d9402e652f05b5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2318,7 +2318,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = #if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); #else - return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); + return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); #endif } diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index ce0806abe41813..5dbeee5d619919 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -3,6 +3,7 @@ #include #include "pal_locale_internal.h" +#include "pal_localeStringData.h" #import #import @@ -140,6 +141,7 @@ value = [numberFormatter.perMillSymbol UTF8String]; break; // TODO find mapping for below cases + // https://github.com/dotnet/runtime/issues/83514 case LocaleString_Digits: case LocaleString_MonetaryDecimalSeparator: case LocaleString_MonetaryThousandSeparator: diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index bb8cd4a8bc56c3..f297293d7c5808 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -6,7 +6,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -#include "pal_localeStringData.h" // Enum that corresponds to managed enum CultureData.LocaleStringData. // The numeric values of the enum members match their Win32 counterparts. From 0b9f32d24307584f0ded0753abcee626b00dbda9 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 16 Mar 2023 15:44:07 +0100 Subject: [PATCH 18/25] space refactoring --- .../src/System/Globalization/CultureData.cs | 3 +++ 1 file changed, 3 insertions(+) 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 d9402e652f05b5..d2a354edee88cb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2303,6 +2303,7 @@ private string GetLocaleInfoCoreUserOverride(LocaleStringData type) // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; + #if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); #else @@ -2315,6 +2316,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; + #if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); #else @@ -2327,6 +2329,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return null!; + #if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type, uiCultureName) : IcuGetLocaleInfo(localeName, type, uiCultureName); #else From 1aee1e06390caeead6f5e084df1718395bbd00b4 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 17 Mar 2023 13:21:12 +0100 Subject: [PATCH 19/25] Fix osx build issue --- .../System.Globalization/tests/Hybrid/Hybrid.Tests.csproj | 2 +- .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- .../src/System/Globalization/CultureData.cs | 6 +++--- .../src/System/Globalization/GlobalizationMode.cs | 4 ++-- src/native/libs/System.Globalization.Native/pal_locale.m | 5 +++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj index 4e1dfbc90a0ec5..2cf04190466db5 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj +++ b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj @@ -1,6 +1,6 @@ - $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst + $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst;$(NetCoreAppCurrent)-osx true true false diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 0817f381754cff..425898126b0ffb 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1269,7 +1269,7 @@ Common\Interop\Interop.ICU.cs - + Common\Interop\Interop.ICU.iOS.cs @@ -1278,7 +1278,7 @@ Common\Interop\Interop.Locale.cs - + Common\Interop\Interop.Locale.iOS.cs 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 d2a354edee88cb..b6308767ac8163 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2304,7 +2304,7 @@ private string GetLocaleInfoCoreUserOverride(LocaleStringData type) if (GlobalizationMode.Invariant) return null!; -#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST +#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); #else return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); @@ -2317,7 +2317,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = if (GlobalizationMode.Invariant) return null!; -#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST +#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); @@ -2330,7 +2330,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin if (GlobalizationMode.Invariant) return null!; -#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST +#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type, uiCultureName) : IcuGetLocaleInfo(localeName, type, uiCultureName); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index 8734573065344a..b04985eedfc1a2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -13,7 +13,7 @@ internal static partial class GlobalizationMode private static partial class Settings { internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); -#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST +#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); #endif internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", GlobalizationMode.Invariant); @@ -23,7 +23,7 @@ private static partial class Settings // This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings // static cctor (on Unix) to be preserved when Invariant=false. internal static bool Invariant => Settings.Invariant; -#if TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST +#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS internal static bool Hybrid => Settings.Hybrid; #endif internal static bool PredefinedCulturesOnly => Settings.PredefinedCulturesOnly; diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 5dbeee5d619919..f6a1d795f99360 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -30,7 +30,7 @@ return strdup([localeName UTF8String]); } -#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) +#if defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, int32_t valueLength) @@ -156,8 +156,9 @@ NSLog(@"Globalization GlobalizationNative_GetLocaleInfoStringNative value: %s", value); return strdup(value); } +#endif - +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) const char* GlobalizationNative_GetICUDataPathFallback(void) { NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"]; From b382101f2272a910a1f6b284f0e68e5f64175852 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 17 Mar 2023 14:08:11 +0100 Subject: [PATCH 20/25] fix osx build --- .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 425898126b0ffb..6a24bb4fdae35b 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -346,7 +346,7 @@ - + @@ -1269,7 +1269,7 @@ Common\Interop\Interop.ICU.cs - + Common\Interop\Interop.ICU.iOS.cs From 1556d179e429b175dbfaec4f2ba35830dff28694 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 20 Mar 2023 13:38:35 +0100 Subject: [PATCH 21/25] Changes requested by review --- .../Common/src/Interop/Interop.Locale.iOS.cs | 4 ++-- .../tests/Hybrid/HybridMode.cs | 9 -------- .../src/System/Globalization/CultureData.cs | 4 ++-- .../System/Globalization/CultureData.iOS.cs | 21 +++++++------------ .../System.Globalization.Native/pal_locale.h | 4 +++- .../System.Globalization.Native/pal_locale.m | 13 ++++-------- .../pal_localeStringData.h | 7 +++---- .../pal_locale_internal.h | 13 +++++------- 8 files changed, 26 insertions(+), 49 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index 74ff348fdf9e01..bc29fa92a94b33 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -9,9 +9,9 @@ internal static partial class Interop internal static partial class Globalization { [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf16)] - internal static unsafe partial string GetLocaleNameNative(string localeName, int valueLength); + internal static unsafe partial string GetLocaleNameNative(string localeName); [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] - internal static unsafe partial string GetLocaleInfoStringNative(string localeName, uint localeStringData, int valueLength, string? uiLocaleName = null); + internal static unsafe partial string GetLocaleInfoStringNative(string localeName, uint localeStringData); } } diff --git a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs index c57fa9a6a614f7..86ba6846300887 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs +++ b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs @@ -50,14 +50,5 @@ public void TwoLetterISOLanguageName(string name, string expected) { Assert.Equal(expected, new CultureInfo(name).TwoLetterISOLanguageName); } - - [Theory] - [InlineData("de-DE", "Deutsch (Deutschland)", "de (DE)")] - public void TestDisplayName(string cultureName, string nativeName, string englishDisplayName) - { - CultureInfo ci = CultureInfo.GetCultureInfo(cultureName); - Assert.Equal(nativeName, ci.NativeName); - Assert.Equal(englishDisplayName, ci.DisplayName); - } } } 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 b6308767ac8163..92037366b63891 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2318,7 +2318,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = return null!; #if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName); + return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type, uiCultureName); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); #endif @@ -2331,7 +2331,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin return null!; #if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type, uiCultureName) : IcuGetLocaleInfo(localeName, type, uiCultureName); + return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index cd1b4190063a93..cf0b1a141e87d7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -11,10 +11,6 @@ namespace System.Globalization { internal sealed partial class CultureData { - // Native constants, check if we need this for native - private const int Native_ULOC_KEYWORD_AND_VALUES_CAPACITY = 100; // max size of keyword or value - private const int Native_ULOC_FULLNAME_CAPACITY = 157; // max size of locale name - /// /// This method uses the sRealName field (which is initialized by the constructor before this is called) to /// initialize the rest of the state of CultureData based on the underlying OS globalization library. @@ -25,33 +21,30 @@ private bool InitNativeCultureDataCore() Debug.Assert(!GlobalizationMode.Invariant); string realNameBuffer = _sRealName; - // Get the locale name - GetLocaleNameNative(realNameBuffer, out _sWindowsName); + _sWindowsName = GetLocaleNameNative(realNameBuffer); return true; } - internal static unsafe bool GetLocaleNameNative(string localeName, out string? windowsName) + internal static unsafe string GetLocaleNameNative(string localeName) { - windowsName = Interop.Globalization.GetLocaleNameNative(localeName, Native_ULOC_FULLNAME_CAPACITY); - return true; + return Interop.Globalization.GetLocaleNameNative(localeName); } - private string GetLocaleInfoNative(LocaleStringData type, string? uiCultureName = null) + private string GetLocaleInfoNative(LocaleStringData type) { Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfoNative] Expected _sWindowsName to be populated already"); - return GetLocaleInfoNative(_sWindowsName, type, uiCultureName); + return GetLocaleInfoNative(_sWindowsName, type); } // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the // "windows" name, which can be specific for downlevel (< windows 7) os's. - private static unsafe string GetLocaleInfoNative(string localeName, LocaleStringData type, string? uiCultureName = null) + private static unsafe string GetLocaleInfoNative(string localeName, LocaleStringData type) { Debug.Assert(localeName != null, "[CultureData.GetLocaleInfoNative] Expected localeName to be not be null"); - string result = Interop.Globalization.GetLocaleInfoStringNative(localeName, (uint)type, Native_ULOC_KEYWORD_AND_VALUES_CAPACITY, uiCultureName); - return result; + return Interop.Globalization.GetLocaleInfoStringNative(localeName, (uint)type); } } } diff --git a/src/native/libs/System.Globalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_locale.h index 983069490d9349..7ee6d1e7ee56e1 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_locale.h @@ -9,7 +9,9 @@ PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLeng PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); -PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, int32_t valueLength); +#ifdef __APPLE__ +PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); +#endif PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index f6a1d795f99360..e6a75e6f1a16cf 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -32,8 +32,7 @@ #if defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) -const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, - int32_t valueLength) +const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) { NSString *locName = [NSString stringWithFormat:@"%s", localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; @@ -41,10 +40,7 @@ return strdup(value); } -const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, - LocaleStringData localeStringData, - int32_t valueLength, - const char* uiLocaleName) +const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData) { const char* value; NSString *locName = [NSString stringWithFormat:@"%s", localeName]; @@ -147,10 +143,9 @@ case LocaleString_MonetaryThousandSeparator: case LocaleString_Iso639LanguageThreeLetterName: case LocaleString_ParentName: - case LocaleString_Iso3166CountryName2: - value = ""; - break; + case LocaleString_Iso3166CountryName2: default: + value = ""; break; } NSLog(@"Globalization GlobalizationNative_GetLocaleInfoStringNative value: %s", value); diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index f297293d7c5808..e6030d8a4cf86e 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -50,10 +50,9 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeNam int32_t valueLength, const UChar* uiLocaleName); -PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, - LocaleStringData localeStringData, - int32_t valueLength, - const char* uiLocaleName); +#ifdef __APPLE__ +PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData); +#endif PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, int shortFormat, UChar* value, diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index 3e96e550271c0c..1f9edb7640cbfb 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -66,19 +66,16 @@ char* DetectDefaultAppleLocaleName(void); Function: GlobalizationNative_GetLocaleNameNative -GlobalizationNative_GetLocaleNameNative for Apple platforms +Returns native locale name for Apple platforms */ -const char* GlobalizationNative_GetLocaleNameNative(const char* localeName, - int32_t valueLength); +const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); /* Function: GlobalizationNative_GetLocaleInfoStringNative -GlobalizationNative_GetLocaleInfoStringNative for Apple platforms +Returns string locale information if found for the specified locale name for Apple platforms. +Returns empty string if not found. */ -const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, - LocaleStringData localeStringData, - int32_t valueLength, - const char* uiLocaleName); +const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData); #endif From 50280458cb0c9d462c152540844757fb90c11ad4 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 20 Mar 2023 14:19:28 +0100 Subject: [PATCH 22/25] Rename .iOS files to OSX --- .../{Interop.Locale.iOS.cs => Interop.Locale.OSX.cs} | 1 - .../src/System.Private.CoreLib.Shared.projitems | 6 +++--- .../{CultureData.iOS.cs => CultureData.OSX.cs} | 3 --- 3 files changed, 3 insertions(+), 7 deletions(-) rename src/libraries/Common/src/Interop/{Interop.Locale.iOS.cs => Interop.Locale.OSX.cs} (98%) rename src/libraries/System.Private.CoreLib/src/System/Globalization/{CultureData.iOS.cs => CultureData.OSX.cs} (95%) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs similarity index 98% rename from src/libraries/Common/src/Interop/Interop.Locale.iOS.cs rename to src/libraries/Common/src/Interop/Interop.Locale.OSX.cs index bc29fa92a94b33..02159c7725d92b 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.InteropServices; -using System; internal static partial class Interop { diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 133d0eb284399f..d8d5a97bf3c0fe 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -346,7 +346,7 @@ - + @@ -1279,8 +1279,8 @@ Common\Interop\Interop.Locale.cs - - Common\Interop\Interop.Locale.iOS.cs + + Common\Interop\Interop.Locale.OSX.cs Common\Interop\Interop.Normalization.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs similarity index 95% rename from src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs rename to src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs index cf0b1a141e87d7..a0b499efcd1089 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs @@ -1,11 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Text; -using System.Runtime.InteropServices; namespace System.Globalization { From ad4c98ba4eb51d3a7565b0144b3991c877b7bc1c Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 20 Mar 2023 17:46:18 +0100 Subject: [PATCH 23/25] Remove logging --- src/native/libs/System.Globalization.Native/pal_locale.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index e6a75e6f1a16cf..7400c48b1c9ba6 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -148,7 +148,7 @@ value = ""; break; } - NSLog(@"Globalization GlobalizationNative_GetLocaleInfoStringNative value: %s", value); + return strdup(value); } #endif From 3eb5cae97804c80ca598906ad1a60ffcfc9d6917 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 21 Mar 2023 11:15:44 +0100 Subject: [PATCH 24/25] Removed not used code lines --- src/libraries/Common/src/Interop/Interop.Locale.OSX.cs | 2 +- .../System.Globalization/tests/Hybrid/Hybrid.Tests.csproj | 3 --- .../System.Globalization/tests/Hybrid/HybridMode.cs | 6 ------ .../src/ILLink/ILLink.Substitutions.Shared.xml | 1 - .../src/System/Globalization/CultureData.OSX.cs | 1 - 5 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs b/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs index 02159c7725d92b..52882346b63222 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs @@ -7,7 +7,7 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] internal static unsafe partial string GetLocaleNameNative(string localeName); [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] diff --git a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj index 2cf04190466db5..5854a557a529cf 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj +++ b/src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj @@ -2,9 +2,6 @@ $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst;$(NetCoreAppCurrent)-osx true - true - false - false true diff --git a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs index 86ba6846300887..f5443f8c2c3c01 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs +++ b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs @@ -1,13 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Buffers; -using System.Reflection; -using System.Buffers.Binary; using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; using Xunit; namespace System.Globalization.Tests diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml index 09b8a2f61e299e..45f6e1c918c7a5 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml @@ -15,7 +15,6 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs index a0b499efcd1089..870d8504fb9678 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; namespace System.Globalization { From 27424bf3bf9b45961373c4ed317e1517e2d8f87b Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 24 Mar 2023 15:10:47 +0100 Subject: [PATCH 25/25] Remove from linker hybrid mode --- .../src/ILLink/ILLink.Substitutions.Shared.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml index 45f6e1c918c7a5..9765f3ab4f662e 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml @@ -10,7 +10,6 @@ to be trimmed when Invariant=true, and allows for the Settings static cctor (on Unix) to be preserved when Invariant=false. --> -