diff --git a/eng/pipelines/common/evaluate-default-paths.yml b/eng/pipelines/common/evaluate-default-paths.yml index 42c7e53735b0b..9de3c93f71ee3 100644 --- a/eng/pipelines/common/evaluate-default-paths.yml +++ b/eng/pipelines/common/evaluate-default-paths.yml @@ -86,6 +86,7 @@ jobs: - src/libraries/System.Private.CoreLib/* - src/native/libs/Common/* - src/native/libs/System.Globalization.Native/* + - src/native/libs/System.HybridGlobalization.Native/* - src/native/libs/System.IO.Compression.Native/* exclude: - eng/Version.Details.xml @@ -109,6 +110,7 @@ jobs: - src/libraries/System.Private.CoreLib/* - src/native/libs/Common/* - src/native/libs/System.Globalization.Native/* + - src/native/libs/System.HybridGlobalization.Native/* - src/native/libs/System.IO.Compression.Native/* exclude: - ${{ parameters._const_paths._wasm_specific_only }} diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index 50f89bfef82a4..81caff243a664 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -159,8 +159,6 @@ - - true true true AppleTestRunner.dll diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 19485ec753df5..3621b815bfa19 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -115,7 +115,8 @@ The .NET Foundation licenses this file to you under the MIT license. - + + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 859f4155076df..63e2a9443ba61 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -35,6 +35,8 @@ <_pastShimFiles Include="System.Globalization.Native.dylib" /> <_pastShimFiles Include="System.Globalization.Native.so" /> + <_pastShimFiles Include="System.HybridGlobalization.Native.dylib" /> + <_pastShimFiles Include="System.HybridGlobalization.Native.so" /> <_pastShimFiles Include="System.IO.Compression.Native.a" /> <_pastShimFiles Include="System.IO.Compression.Native.dylib" /> <_pastShimFiles Include="System.IO.Compression.Native.so" /> @@ -80,6 +82,9 @@ + + + diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs b/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs index 985e55b604e4f..5decc623f458e 100644 --- a/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs @@ -9,16 +9,16 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarsNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarsNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetCalendarsNative(string localeName, CalendarId[] calendars, int calendarsCapacity); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarInfoNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarInfoNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetCalendarInfoNative(string localeName, CalendarId calendarId, CalendarDataType calendarDataType); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEraNative")] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEraNative")] internal static partial int GetLatestJapaneseEraNative(); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDateNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDateNative", StringMarshalling = StringMarshalling.Utf8)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetJapaneseEraStartDateNative(int era, out int startYear, out int startMonth, out int startDay); diff --git a/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs b/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs index 5e0140faa4c43..4d9907c2ef338 100644 --- a/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs @@ -7,10 +7,13 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int ChangeCaseNative(string localeName, int lNameLen, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, [MarshalAs(UnmanagedType.Bool)] bool bToUpper); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseInvariantNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseInvariantNative", StringMarshalling = StringMarshalling.Utf8)] internal static unsafe partial int ChangeCaseInvariantNative(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, [MarshalAs(UnmanagedType.Bool)] bool bToUpper); + + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_InitOrdinalCasingPage", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial void InitOrdinalCasingPageNative(int pageNumber, char* pTarget); } } diff --git a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs index 2dba31ddcd70e..32491721cafc9 100644 --- a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs @@ -16,21 +16,21 @@ internal struct Range internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CompareStringNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_CompareStringNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int CompareStringNative(string localeName, int lNameLen, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWithNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_EndsWithNative", StringMarshalling = StringMarshalling.Utf16)] [MethodImpl(MethodImplOptions.NoInlining)] internal static unsafe partial int EndsWithNative(string localeName, int lNameLen, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IndexOfNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_IndexOfNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial Range IndexOfNative(string localeName, int lNameLen, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, [MarshalAs(UnmanagedType.Bool)] bool fromBeginning); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWithNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_StartsWithNative", StringMarshalling = StringMarshalling.Utf16)] [MethodImpl(MethodImplOptions.NoInlining)] internal static unsafe partial int StartsWithNative(string localeName, int lNameLen, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKeyNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKeyNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int GetSortKeyNative(string localeName, int lNameLen, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options); } } diff --git a/src/libraries/Common/src/Interop/Interop.Idna.iOS.cs b/src/libraries/Common/src/Interop/Interop.Idna.iOS.cs new file mode 100644 index 0000000000000..5d72c201f4f9d --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.Idna.iOS.cs @@ -0,0 +1,17 @@ +// 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.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ToAscii", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int ToAsciiNative(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); + + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ToUnicode", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int ToUnicodeNative(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); + } +} diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index d0049b7a7a173..67de37e519c3e 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -7,31 +7,31 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetDefaultLocaleNameNative(); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetLocaleInfoStringNative(string localeName, uint localeStringData, string? uiLocaleName = null); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoIntNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoIntNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetLocaleInfoIntNative(string localeName, uint localeNumberData); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetLocaleInfoPrimaryGroupingSizeNative(string localeName, uint localeGroupingData); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetLocaleInfoSecondaryGroupingSizeNative(string localeName, uint localeGroupingData); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetLocaleNameNative(string localeName); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocalesNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocalesNative", StringMarshalling = StringMarshalling.Utf16)] internal static partial int GetLocalesNative([Out] char[]? value, int valueLength); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleTimeFormatNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleTimeFormatNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetLocaleTimeFormatNative(string localeName, [MarshalAs(UnmanagedType.Bool)] bool shortFormat); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsPredefinedLocaleNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_IsPredefinedLocaleNative", StringMarshalling = StringMarshalling.Utf8)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool IsPredefinedLocaleNative(string localeName); } diff --git a/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs b/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs index 4ba97148b4538..001335fd29bf6 100644 --- a/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs @@ -8,10 +8,10 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsNormalizedNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_IsNormalizedNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int IsNormalizedNative(NormalizationForm normalizationForm, char* src, int srcLen); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_NormalizeStringNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_NormalizeStringNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int NormalizeStringNative(NormalizationForm normalizationForm, char* src, int srcLen, char* buffer, int bufferLength); } } diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs index 9575fc3dc3359..e61c5b30cab93 100644 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayNameNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayNameNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial ResultCode GetTimeZoneDisplayNameNative( string localeName, int lNameLength, diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs index 7ec51da64f254..5a26917071b30 100644 --- a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs @@ -13,6 +13,7 @@ internal static partial class Libraries internal const string CryptoNative = "libSystem.Security.Cryptography.Native.OpenSsl"; internal const string CompressionNative = "libSystem.IO.Compression.Native"; internal const string GlobalizationNative = "libSystem.Globalization.Native"; + internal const string HybridGlobalizationNative = "libSystem.HybridGlobalization.Native"; internal const string IOPortsNative = "libSystem.IO.Ports.Native"; internal const string HostPolicy = "libhostpolicy"; } 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 e46bd04f7d695..69b76c74ac538 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 @@ -1357,6 +1357,9 @@ Common\Interop\Interop.Idna.cs + + Common\Interop\Interop.Idna.iOS.cs + Common\Interop\Interop.Locale.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs index df937e56e34fe..33982d73e8137 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs @@ -12,9 +12,12 @@ private static partial class Settings /// the GlobalizationMode.Invariant check. Globalization P/Invokes, e.g. in CompareInfo.GetSortKey, /// rely on ICU already being loaded before they are called. /// -#if !TARGET_MACCATALYST && !TARGET_IOS && !TARGET_TVOS static Settings() { +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + return; +#endif // Use GlobalizationMode.Invariant to allow ICU initialization to be trimmed when Invariant=true // and PredefinedCulturesOnly is unspecified. if (!GlobalizationMode.Invariant) @@ -33,7 +36,6 @@ static Settings() } } } -#endif private static string GetIcuLoadFailureMessage() { 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 314bb33692dc7..7884b85847aba 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -13,8 +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_MACCATALYST || TARGET_IOS || TARGET_TVOS - internal static bool Hybrid { get; } = true; + internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID", true); #elif TARGET_BROWSER internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs index bfaeb2c721e6f..c78c93510e85b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs @@ -24,7 +24,12 @@ private unsafe string IcuGetAsciiCore(string unicodeString, char* unicode, int c if (estimatedLength < StackallocThreshold) { char* outputStack = stackalloc char[estimatedLength]; - actualLength = Interop.Globalization.ToAscii(flags, unicode, count, outputStack, estimatedLength); +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + actualLength = Interop.Globalization.ToAsciiNative(flags, unicode, count, outputStack, estimatedLength); + else +#endif + actualLength = Interop.Globalization.ToAscii(flags, unicode, count, outputStack, estimatedLength); if (actualLength > 0 && actualLength <= estimatedLength) { return GetStringForOutput(unicodeString, unicode, count, outputStack, actualLength); @@ -32,7 +37,12 @@ private unsafe string IcuGetAsciiCore(string unicodeString, char* unicode, int c } else { - actualLength = Interop.Globalization.ToAscii(flags, unicode, count, null, 0); +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + actualLength = Interop.Globalization.ToAsciiNative(flags, unicode, count, null, 0); + else +#endif + actualLength = Interop.Globalization.ToAscii(flags, unicode, count, null, 0); } if (actualLength == 0) { @@ -42,6 +52,11 @@ private unsafe string IcuGetAsciiCore(string unicodeString, char* unicode, int c char[] outputHeap = new char[actualLength]; fixed (char* pOutputHeap = &outputHeap[0]) { +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + actualLength = Interop.Globalization.ToAsciiNative(flags, unicode, count, pOutputHeap, actualLength); + else +#endif actualLength = Interop.Globalization.ToAscii(flags, unicode, count, pOutputHeap, actualLength); if (actualLength == 0 || actualLength > outputHeap.Length) { @@ -82,7 +97,13 @@ private unsafe string IcuGetUnicodeCore(string asciiString, char* ascii, int cou Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(asciiString != null && asciiString.Length >= count); - int realLen = Interop.Globalization.ToUnicode(flags, ascii, count, output, outputLength); + int realLen; +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + realLen = Interop.Globalization.ToUnicodeNative(flags, ascii, count, output, outputLength); + else +#endif + realLen = Interop.Globalization.ToUnicode(flags, ascii, count, output, outputLength); if (realLen == 0) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs index 1d520c348723d..66c5cd175f084 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs @@ -434,6 +434,11 @@ private static unsafe ushort[] InitOrdinalCasingPage(int pageNumber) fixed (ushort* table = casingTable) { char* pTable = (char*)table; +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + Interop.Globalization.InitOrdinalCasingPageNative(pageNumber, pTable); + else +#endif Interop.Globalization.InitOrdinalCasingPage(pageNumber, pTable); } Volatile.Write(ref s_casingTable[pageNumber], casingTable); diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Calendars.Tests/Hybrid/System.Globalization.Calendars.IOS.Tests.csproj b/src/libraries/System.Runtime/tests/System.Globalization.Calendars.Tests/Hybrid/System.Globalization.Calendars.IOS.Tests.csproj deleted file mode 100644 index 614c0d2a47f65..0000000000000 --- a/src/libraries/System.Runtime/tests/System.Globalization.Calendars.Tests/Hybrid/System.Globalization.Calendars.IOS.Tests.csproj +++ /dev/null @@ -1,108 +0,0 @@ - - - $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/Hybrid/System.Globalization.Extensions.iOS.Tests.csproj b/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/Hybrid/System.Globalization.Extensions.iOS.Tests.csproj deleted file mode 100644 index ada1f18597f6e..0000000000000 --- a/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/Hybrid/System.Globalization.Extensions.iOS.Tests.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst - true - true - - - - - - - - NormalizationDataWin8 - - - NormalizationDataWin7 - - - diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/Hybrid/System.Globalization.IOS.Tests.csproj b/src/libraries/System.Runtime/tests/System.Globalization.Tests/ICU/System.Globalization.IOS.Tests.csproj similarity index 99% rename from src/libraries/System.Runtime/tests/System.Globalization.Tests/Hybrid/System.Globalization.IOS.Tests.csproj rename to src/libraries/System.Runtime/tests/System.Globalization.Tests/ICU/System.Globalization.IOS.Tests.csproj index e0ff97362fe7e..ca3351cbaf185 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/Hybrid/System.Globalization.IOS.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/ICU/System.Globalization.IOS.Tests.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst true - true + false true true 15.0 diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/Hybrid/System.Runtime.IOS.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/Hybrid/System.Runtime.IOS.Tests.csproj deleted file mode 100644 index 0eb9e1d6a4942..0000000000000 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/Hybrid/System.Runtime.IOS.Tests.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - $(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst - true - true - true - true - - - - $(WithoutCategories);AdditionalTimezoneChecks - - - - - - - - - - - - diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index d5374b3bca6a8..7798a1a40836e 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -712,79 +712,6 @@ if(LLVM_PREFIX) add_definitions(-DLLVM_API_VERSION=${llvm_api_version}) endif() -###################################### -# ICU CHECKS -###################################### -if(HOST_OSX OR HOST_MACCAT OR HOST_IOS OR HOST_TVOS) - # FIXME: Handle errors - execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) - - if((HOST_MACCAT OR HOST_IOS OR HOST_TVOS) AND "${CMAKE_SHARED_LINKER_FLAGS}" MATCHES "${brew_prefix}/opt/icu4c/lib") - message(FATAL_ERROR "Linker flags contain the Homebrew version of ICU which conflicts with the iOS/tvOS/MacCatalyst version: ${CMAKE_SHARED_LINKER_FLAGS}") - endif() -endif() - -set(ICU_SHIM_PATH "${CLR_SRC_NATIVE_DIR}/libs/System.Globalization.Native") -if(MONO_CROSS_COMPILE) -elseif(HOST_OSX AND NOT HOST_MACCAT) - include(FindPkgConfig) - set(ENV{PKG_CONFIG_PATH} "{$PKG_CONFIG_PATH}:${brew_prefix}/lib/pkgconfig:${brew_prefix}/opt/icu4c/lib/pkgconfig") - # Defines ICU_INCLUDEDIR/ICU_LIBDIR - pkg_check_modules(ICU icu-uc) - set(OSX_ICU_LIBRARY_PATH /usr/lib/libicucore.dylib) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) -elseif(HOST_WASI) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DU_DISABLE_RENAMING -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) - set(STATIC_ICU 1) - set(ICU_LIBS "icucore") -elseif(HOST_BROWSER) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DU_DISABLE_RENAMING -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) - set(STATIC_ICU 1) - set(ICU_LIBS "icucore") -elseif(HOST_IOS OR HOST_TVOS OR HOST_MACCAT) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - if(HOST_IOS) - string(APPEND ICU_FLAGS " -DTARGET_IOS") - elseif(HOST_TVOS) - string(APPEND ICU_FLAGS " -DTARGET_TVOS") - elseif(HOST_MACCAT) - string(APPEND ICU_FLAGS " -DTARGET_MACCATALYST") - endif() - string(APPEND ICU_FLAGS " -DAPPLE_HYBRID_GLOBALIZATION") - set(HAVE_SYS_ICU 1) - set(STATIC_ICU 1) -elseif(HOST_ANDROID) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -DTARGET_ANDROID -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) -elseif(HOST_LINUX) - include(FindPkgConfig) - if(CROSS_ROOTFS) - set(ENV{PKG_CONFIG_SYSROOT_DIR} "${CROSS_ROOTFS}") - endif(CROSS_ROOTFS) - pkg_check_modules(ICU icu-uc) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) -elseif(HOST_WIN32) - set(ICU_FLAGS "-DTARGET_WINDOWS -DPALEXPORT=EXTERN_C") - set(HAVE_SYS_ICU 1) -elseif(HOST_SOLARIS) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) -elseif(TARGET_FREEBSD) - set(ICU_FLAGS "-DTARGET_UNIX -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) - set(ICU_INCLUDEDIR "${CROSS_ROOTFS}/usr/local/include") - set(ICU_LIBDIR "${CROSS_ROOTFS}/usr/local/lib") -elseif(HOST_HAIKU) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) -else() - message(FATAL_ERROR "Unknown host") -endif() - ###################################### # GC CHECKS ###################################### diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 022da2f21f010..bbb6a3ef797e2 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -299,9 +299,6 @@ <_MonoBuildEnv Condition="'$(Platform)' == 'arm64'" Include="TARGET_BUILD_ARCH=arm64" /> <_MonoBuildEnv Condition="'$(Platform)' == 'arm'" Include="TARGET_BUILD_ARCH=arm" /> <_MonoBuildEnv Condition="'$(Platform)' == 'armv6'" Include="TARGET_BUILD_ARCH=armv6" /> - <_MonoBuildEnv Condition="'$(Platform)' == 'arm64'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/aarch64-linux-gnu/pkgconfig" /> - <_MonoBuildEnv Condition="'$(Platform)' == 'arm'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/arm-linux-gnueabihf/pkgconfig" /> - <_MonoBuildEnv Condition="'$(Platform)' == 'armv6'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/arm-linux-gnueabihf/pkgconfig" /> <_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'armv6'" Include="-march=armv6zk" /> <_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'armv6'" Include="-mcpu=arm1176jzf-s" /> <_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'armv6'" Include="-mfpu=vfp" /> @@ -316,49 +313,42 @@ <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/boot/system/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x86" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=riscv64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/riscv64-linux-gnu/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=s390x" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/s390x-linux-gnu/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=ppc64le" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/powerpc64le-linux-gnu/pkgconfig" /> @@ -836,21 +826,6 @@ <_MonoAotBuildEnv Include="TARGET_BUILD_ARCH=$(AotHostArchitecture)" /> - - - <_MonoAotBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/x86_64-linux-gnu/pkgconfig" /> - - - - - <_MonoAotBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/aarch64-linux-gnu/pkgconfig" /> - - - - - <_MonoAotBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/pkgconfig" /> - - <_MonoAOTCFLAGSOption>-DCMAKE_C_FLAGS="@(_MonoAOTCPPFLAGS, ' ') @(_MonoAOTCFLAGS, ' ')" <_MonoAOTCXXFLAGSOption>-DCMAKE_CXX_FLAGS="@(_MonoAOTCPPFLAGS, ' ') @(_MonoAOTCXXFLAGS, ' ')" diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 6692736251330..7a3588ed20229 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -47,10 +47,6 @@ static GHashTable *native_library_module_map; */ static GHashTable *native_library_module_blocklist; -#ifndef NO_GLOBALIZATION_SHIM -extern const void *GlobalizationResolveDllImport (const char *name); -#endif - static GHashTable *global_module_map; // should only be accessed with the global loader data lock static MonoDl *internal_module; // used when pinvoking `__Internal` @@ -786,25 +782,6 @@ get_dllimportsearchpath_flags (MonoCustomAttrInfo *cinfo) return flags; } -#ifndef NO_GLOBALIZATION_SHIM -#ifdef HOST_WIN32 -#define GLOBALIZATION_DLL_NAME "System.Globalization.Native" -#else -#define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" -#endif - -static gpointer -default_resolve_dllimport (const char *dll, const char *func) -{ - if (strcmp (dll, GLOBALIZATION_DLL_NAME) == 0) { - const void *method_impl = GlobalizationResolveDllImport (func); - if (method_impl) - return (gpointer)method_impl; - } - - return NULL; -} -#endif // NO_GLOBALIZATION_SHIM gpointer lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_out) @@ -881,12 +858,6 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou } #endif -#ifndef NO_GLOBALIZATION_SHIM - addr = default_resolve_dllimport (new_scope, new_import); - if (addr) - goto exit; -#endif - if (pinvoke_override) { addr = pinvoke_override (new_scope, new_import); if (addr) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 5e6ebe9ce49dc..335867bac8eff 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -45,78 +45,6 @@ if(HOST_WIN32) add_link_options(/OPT:NOICF) endif() -# ICU -if(HAVE_SYS_ICU) - if(STATIC_ICU) - set(pal_icushim_sources_base - pal_icushim_static.c) - add_definitions(-DSTATIC_ICU=1) - else() - set(pal_icushim_sources_base - pal_icushim.c) - endif() - - set(icu_shim_sources_base - pal_idna.c - pal_common.c - entrypoints.c - ${pal_icushim_sources_base}) - -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - set(icu_shim_sources_base - ${icu_shim_sources_base} - pal_calendarData.c - pal_casing.c - pal_collation.c - pal_locale.c - pal_localeNumberData.c - pal_localeStringData.c - pal_normalization.c - pal_timeZoneInfo.c - ) -endif() - -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - set(icu_shim_sources_base - ${icu_shim_sources_base} - pal_placeholders.c - ) -endif() - - addprefix(icu_shim_sources "${ICU_SHIM_PATH}" "${icu_shim_sources_base}") - - if (TARGET_DARWIN) - set(icu_shim_darwin_sources_base - pal_locale.m - pal_collation.m - pal_casing.m - pal_calendarData.m - pal_normalization.m - pal_timeZoneInfo.m) - - addprefix(icu_shim_darwin_sources "${ICU_SHIM_PATH}" "${icu_shim_darwin_sources_base}") - set(icu_shim_sources ${icu_shim_sources} ${icu_shim_darwin_sources}) - endif() - - set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_DEFINITIONS OSX_ICU_LIBRARY_PATH="${OSX_ICU_LIBRARY_PATH}") - set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_FLAGS "-I\"${ICU_INCLUDEDIR}\" -I\"${CLR_SRC_NATIVE_DIR}/libs/System.Globalization.Native/\" -I\"${CLR_SRC_NATIVE_DIR}/libs/Common/\" ${ICU_FLAGS}") - if(TARGET_DARWIN) - set_property(SOURCE ${icu_shim_darwin_sources} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") - endif() - if(TARGET_WIN32) - set_source_files_properties(${icu_shim_sources} PROPERTIES LANGUAGE CXX) - endif() - if(ICU_LIBDIR) - set(ICU_LDFLAGS "-L${ICU_LIBDIR}") - endif() - if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - set(ICU_LDFLAGS "-licucore") - endif() - - add_library(icu_shim_objects OBJECT "${icu_shim_sources}") - set(HAVE_ICU_SHIM 1) -endif() - # # MINI # diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 1959fec40a7cf..b1ffd983d0dc4 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -22,7 +22,7 @@ if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) add_compile_options(-Wno-unknown-warning-option) # The mobile configurations in particular bring their own ICU, so skip - if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT DEFINED CMAKE_ICU_DIR) + if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT DEFINED CMAKE_ICU_DIR) if (CLR_CMAKE_TARGET_OSX) execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") @@ -58,40 +58,23 @@ endif() include(configure.cmake) set(NATIVEGLOBALIZATION_SOURCES + pal_calendarData.c + pal_casing.c + pal_collation.c pal_idna.c pal_common.c -) -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - set(NATIVEGLOBALIZATION_SOURCES - ${NATIVEGLOBALIZATION_SOURCES} - pal_calendarData.c - pal_casing.c - pal_collation.c - pal_locale.c - pal_localeNumberData.c - pal_localeStringData.c - pal_normalization.c - ) -endif() - -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) - set(NATIVEGLOBALIZATION_SOURCES - ${NATIVEGLOBALIZATION_SOURCES} - pal_placeholders.c + pal_locale.c + pal_localeNumberData.c + pal_localeStringData.c + pal_normalization.c ) -endif() -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND DEFINED CMAKE_ICU_DIR) +if (DEFINED CMAKE_ICU_DIR) include_directories(${CMAKE_ICU_DIR}/include) link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) link_libraries(stdc++) endif() -if ((CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) AND NOT DEFINED CMAKE_ICU_DIR) - link_libraries(icucore) -endif() - if (CMAKE_USE_PTHREADS) add_compile_options(-pthread) add_linker_flag(-pthread) @@ -116,18 +99,13 @@ endif() if (CLR_CMAKE_TARGET_APPLE) set(NATIVEGLOBALIZATION_SOURCES_OBJC - pal_locale.m - pal_collation.m - pal_casing.m - pal_calendarData.m - pal_normalization.m - pal_timeZoneInfo.m) + pal_locale.m) set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) endif() # time zone names are filtered out of icu data for the browser and associated functionality is disabled -if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) endif() @@ -201,3 +179,102 @@ if(CLR_CMAKE_TARGET_WIN32) install_static_library(System.Globalization.Native.Aot.GuardCF aotsdk nativeaot) endif() endif() + +# System.HybridGlobalization.Native library + +project(System.HybridGlobalization.Native C) +if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + + add_compile_options(-Wno-switch-enum) + add_compile_options(-Wno-covered-switch-default) + + # Workaround for warnings produced by ICU headers + add_compile_options(-Wno-reserved-id-macro) + add_compile_options(-Wno-documentation) + add_compile_options(-Wno-documentation-unknown-command) + add_compile_options(-Wno-reserved-identifier) + + # Workaround for https://unicode-org.atlassian.net/browse/ICU-20601 + add_compile_options(-Wno-extra-semi-stmt) + add_compile_options(-Wno-unknown-warning-option) + + include(configure.cmake) + + set(NATIVEGLOBALIZATION_SOURCES + pal_idna.c + pal_common.c + ) + + link_libraries(icucore) + + if (CMAKE_USE_PTHREADS) + add_compile_options(-pthread) + add_linker_flag(-pthread) + endif() + + if (LOCAL_BUILD) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + # set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static_hybrid.c) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) + add_definitions(-DLOCAL_BUILD) + add_definitions(-DSTATIC_ICU) + add_definitions(-DPALEXPORT=EXTERN_C) + add_definitions(-DTARGET_UNIX) + # For minipal files + include_directories(../../) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + add_definitions(-DSTATIC_ICU) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) + + else() + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) + endif() + + set(NATIVEGLOBALIZATION_SOURCES_OBJC + pal_locale_hg.m + pal_locale.m + pal_collation.m + pal_casing.m + pal_calendarData.m + pal_normalization.m + pal_timeZoneInfo.m) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) + + if (MSVC) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) + endif() + + include_directories("../Common") + + if (GEN_SHARED_LIB) + include(CMakeFindFrameworks) + find_library(FOUNDATION Foundation REQUIRED) + + add_library(System.HybridGlobalization.Native + SHARED + ${NATIVEGLOBALIZATION_SOURCES} + ${VERSION_FILE_PATH} + ) + + target_link_libraries(System.HybridGlobalization.Native + PRIVATE + ${CMAKE_DL_LIBS} + ${FOUNDATION} + ) + + install_with_stripped_symbols (System.HybridGlobalization.Native PROGRAMS .) + endif() + + add_library(System.HybridGlobalization.Native-Static + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + entrypoints_hg.c + ) + + set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) + + install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) + +endif() diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index f2db315ec5452..f55eb17fcddbd 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -55,33 +55,9 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_NormalizeString) DllImportEntry(GlobalizationNative_StartsWith) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) -#if defined(APPLE_HYBRID_GLOBALIZATION) - DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative) - DllImportEntry(GlobalizationNative_ChangeCaseNative) - DllImportEntry(GlobalizationNative_CompareStringNative) - DllImportEntry(GlobalizationNative_GetDefaultLocaleNameNative) - DllImportEntry(GlobalizationNative_EndsWithNative) - DllImportEntry(GlobalizationNative_GetCalendarInfoNative) - DllImportEntry(GlobalizationNative_GetCalendarsNative) - DllImportEntry(GlobalizationNative_GetJapaneseEraStartDateNative) - DllImportEntry(GlobalizationNative_GetLatestJapaneseEraNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoIntNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoStringNative) - DllImportEntry(GlobalizationNative_GetLocaleNameNative) - DllImportEntry(GlobalizationNative_GetLocalesNative) - DllImportEntry(GlobalizationNative_GetLocaleTimeFormatNative) - DllImportEntry(GlobalizationNative_GetSortKeyNative) - DllImportEntry(GlobalizationNative_GetTimeZoneDisplayNameNative) - DllImportEntry(GlobalizationNative_IndexOfNative) - DllImportEntry(GlobalizationNative_IsNormalizedNative) - DllImportEntry(GlobalizationNative_NormalizeStringNative) - DllImportEntry(GlobalizationNative_StartsWithNative) -#endif - DllImportEntry(GlobalizationNative_ToAscii) - DllImportEntry(GlobalizationNative_ToUnicode) - DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) + DllImportEntry(GlobalizationNative_ToAscii) + DllImportEntry(GlobalizationNative_ToUnicode) + DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) }; EXTERN_C const void* GlobalizationResolveDllImport(const char* name); diff --git a/src/native/libs/System.Globalization.Native/entrypoints_hg.c b/src/native/libs/System.Globalization.Native/entrypoints_hg.c new file mode 100644 index 0000000000000..528e507e1783a --- /dev/null +++ b/src/native/libs/System.Globalization.Native/entrypoints_hg.c @@ -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. + +#include + +typedef uint16_t UChar; + +// Include System.HybridGlobalization.Native headers +#include "pal_calendarData_hg.h" +#include "pal_casing_hg.h" +#include "pal_collation_hg.h" +#include "pal_locale_hg.h" +#include "pal_icushim.h" +#include "pal_idna.h" +#include "pal_normalization_hg.h" +#include "pal_timeZoneInfo_hg.h" + +static const Entry s_globalizationNative[] = +{ + DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative) + DllImportEntry(GlobalizationNative_ChangeCaseNative) + DllImportEntry(GlobalizationNative_CompareStringNative) + DllImportEntry(GlobalizationNative_GetDefaultLocaleNameNative) + DllImportEntry(GlobalizationNative_EndsWithNative) + DllImportEntry(GlobalizationNative_GetCalendarInfoNative) + DllImportEntry(GlobalizationNative_GetCalendarsNative) + DllImportEntry(GlobalizationNative_GetJapaneseEraStartDateNative) + DllImportEntry(GlobalizationNative_GetLatestJapaneseEraNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoIntNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoStringNative) + DllImportEntry(GlobalizationNative_GetLocaleNameNative) + DllImportEntry(GlobalizationNative_GetLocalesNative) + DllImportEntry(GlobalizationNative_GetLocaleTimeFormatNative) + DllImportEntry(GlobalizationNative_GetSortKeyNative) + DllImportEntry(GlobalizationNative_GetTimeZoneDisplayNameNative) + DllImportEntry(GlobalizationNative_IndexOfNative) + DllImportEntry(GlobalizationNative_IsNormalizedNative) + DllImportEntry(GlobalizationNative_NormalizeStringNative) + DllImportEntry(GlobalizationNative_StartsWithNative) + DllImportEntry(GlobalizationNative_ToAscii) + DllImportEntry(GlobalizationNative_ToUnicode) + DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) +}; + +EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name); + +EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name) +{ + return minipal_resolve_dllimport(s_globalizationNative, ARRAY_SIZE(s_globalizationNative), name); +} diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.h b/src/native/libs/System.Globalization.Native/pal_calendarData.h index 31ce76d869395..bafe3f8d0eb10 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.h +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.h @@ -5,77 +5,11 @@ #include +#include "pal_common.h" #include "pal_locale.h" #include "pal_compiler.h" #include "pal_errors.h" -/* -* These values should be kept in sync with System.Globalization.CalendarId -*/ -enum -{ - UNINITIALIZED_VALUE = 0, - GREGORIAN = 1, // Gregorian (localized) calendar - GREGORIAN_US = 2, // Gregorian (U.S.) calendar - JAPAN = 3, // Japanese Emperor Era calendar - /* SSS_WARNINGS_OFF */ - TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */ - KOREA = 5, // Korean Tangun Era calendar - HIJRI = 6, // Hijri (Arabic Lunar) calendar - THAI = 7, // Thai calendar - HEBREW = 8, // Hebrew (Lunar) calendar - GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar - GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar - GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar - GREGORIAN_XLIT_FRENCH = 12, - // Note that all calendars after this point are MANAGED ONLY for now. - JULIAN = 13, - JAPANESELUNISOLAR = 14, - CHINESELUNISOLAR = 15, - SAKA = 16, // reserved to match Office but not implemented in our code - LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code - LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code - LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code - KOREANLUNISOLAR = 20, - TAIWANLUNISOLAR = 21, - PERSIAN = 22, - UMALQURA = 23, - LAST_CALENDAR = 23 // Last calendar ID -}; -typedef uint16_t CalendarId; - -/* -* These values should be kept in sync with System.Globalization.CalendarDataType -*/ -typedef enum -{ - CalendarData_Uninitialized = 0, - CalendarData_NativeName = 1, - CalendarData_MonthDay = 2, - CalendarData_ShortDates = 3, - CalendarData_LongDates = 4, - CalendarData_YearMonths = 5, - CalendarData_DayNames = 6, - CalendarData_AbbrevDayNames = 7, - CalendarData_MonthNames = 8, - CalendarData_AbbrevMonthNames = 9, - CalendarData_SuperShortDayNames = 10, - CalendarData_MonthGenitiveNames = 11, - CalendarData_AbbrevMonthGenitiveNames = 12, - CalendarData_EraNames = 13, - CalendarData_AbbrevEraNames = 14, -} CalendarDataType; - -#define GREGORIAN_NAME "gregorian" -#define JAPANESE_NAME "japanese" -#define BUDDHIST_NAME "buddhist" -#define HEBREW_NAME "hebrew" -#define DANGI_NAME "dangi" -#define PERSIAN_NAME "persian" -#define ISLAMIC_NAME "islamic" -#define ISLAMIC_UMALQURA_NAME "islamic-umalqura" -#define ROC_NAME "roc" - // the function pointer definition for the callback used in EnumCalendarInfo typedef void (PAL_CALLBACK_CALLTYPE *EnumCalendarInfoCallback)(const UChar*, const void*); @@ -101,19 +35,3 @@ PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetCalendarInfoNative(const char* localeName, - CalendarId calendarId, - CalendarDataType dataType); - -PALEXPORT int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, - CalendarId* calendars, - int32_t calendarsCapacity); - -PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEraNative(void); - -PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, - int32_t* startYear, - int32_t* startMonth, - int32_t* startDay); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m index 9520e17646754..203a462bd7a65 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -2,15 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. #include -#include "pal_icushim_internal.h" -#include "pal_calendarData.h" +#include "pal_calendarData_hg.h" #import #if !__has_feature(objc_arc) #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) /* Function: GetCalendarIdentifier @@ -285,4 +283,4 @@ int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, CalendarI return calendarCount; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h b/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h new file mode 100644 index 0000000000000..817e4eec48e48 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include + +#include "pal_locale_hg.h" +#include "pal_compiler.h" +#include "pal_errors.h" + +PALEXPORT const char* GlobalizationNative_GetCalendarInfoNative(const char* localeName, + CalendarId calendarId, + CalendarDataType dataType); + +PALEXPORT int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, + CalendarId* calendars, + int32_t calendarsCapacity); + +PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEraNative(void); + +PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, + int32_t* startYear, + int32_t* startMonth, + int32_t* startDay); + diff --git a/src/native/libs/System.Globalization.Native/pal_casing.h b/src/native/libs/System.Globalization.Native/pal_casing.h index 5371ba3bb0886..b49a77593e3df 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing.h +++ b/src/native/libs/System.Globalization.Native/pal_casing.h @@ -4,8 +4,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); - PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, @@ -23,18 +21,5 @@ PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpSrc, - int32_t cwSrcLength, - uint16_t* lpDst, - int32_t cwDstLength, - int32_t bToUpper); -PALEXPORT int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, - int32_t cwSrcLength, - uint16_t* lpDst, - int32_t cwDstLength, - int32_t bToUpper); -#endif +PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); diff --git a/src/native/libs/System.Globalization.Native/pal_casing.m b/src/native/libs/System.Globalization.Native/pal_casing.m index ba5c853c0b4c6..b6b20bdf02fd9 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing.m +++ b/src/native/libs/System.Globalization.Native/pal_casing.m @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#include "pal_icushim_internal.h" -#include "pal_casing.h" +#include "pal_casing_hg.h" +#include "pal_hybrid.h" #include "pal_errors.h" #import @@ -11,7 +11,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) /** * Is this code unit a lead surrogate (U+d800..U+dbff)? * @param c 16-bit code unit @@ -147,4 +146,4 @@ int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, int return Success; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_casing_hg.h b/src/native/libs/System.Globalization.Native/pal_casing_hg.h new file mode 100644 index 0000000000000..8e2f1d7b6486e --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_casing_hg.h @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "pal_locale_hg.h" +#include "pal_compiler.h" + +PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); + +PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpSrc, + int32_t cwSrcLength, + uint16_t* lpDst, + int32_t cwDstLength, + int32_t bToUpper); + +PALEXPORT int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, + int32_t cwSrcLength, + uint16_t* lpDst, + int32_t cwDstLength, + int32_t bToUpper); + diff --git a/src/native/libs/System.Globalization.Native/pal_collation.c b/src/native/libs/System.Globalization.Native/pal_collation.c index 44de265b4a196..8f5bf34daad7d 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.c +++ b/src/native/libs/System.Globalization.Native/pal_collation.c @@ -11,6 +11,7 @@ #include "pal_errors_internal.h" #include "pal_collation.h" #include "pal_atomic.h" +#include "pal_common.h" c_static_assert_msg(UCOL_EQUAL == 0, "managed side requires 0 for equal strings"); c_static_assert_msg(UCOL_LESS < 0, "managed side requires less than zero for a < b"); diff --git a/src/native/libs/System.Globalization.Native/pal_collation.h b/src/native/libs/System.Globalization.Native/pal_collation.h index b2ef6e1ed3d24..9f98cc449aa29 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.h +++ b/src/native/libs/System.Globalization.Native/pal_collation.h @@ -4,15 +4,10 @@ #pragma once #include "pal_locale.h" +#include "pal_common.h" #include "pal_compiler.h" #include "pal_errors.h" -typedef struct SortHandle SortHandle; -typedef struct _Range { - int32_t location; - int32_t length; -} Range; - PALEXPORT ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle); PALEXPORT void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle); @@ -65,46 +60,3 @@ PALEXPORT int32_t GlobalizationNative_GetSortKey(SortHandle* pSortHandle, uint8_t* sortKey, int32_t cbSortKeyLength, int32_t options); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpTarget, - int32_t cwTargetLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options); - -PALEXPORT Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpTarget, - int32_t cwTargetLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options, - int32_t fromBeginning); - -PALEXPORT int32_t GlobalizationNative_StartsWithNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpPrefix, - int32_t cwPrefixLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options); - -PALEXPORT int32_t GlobalizationNative_EndsWithNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpSuffix, - int32_t cwSuffixLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options); - -PALEXPORT int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, - int32_t lNameLength, - const UChar* lpStr, - int32_t cwStrLength, - uint8_t* sortKey, - int32_t cbSortKeyLength, - int32_t options); - -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_collation.m b/src/native/libs/System.Globalization.Native/pal_collation.m index 9a63c11be44ab..337a34494b35b 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.m +++ b/src/native/libs/System.Globalization.Native/pal_collation.m @@ -3,7 +3,7 @@ #include #include "pal_locale_internal.h" -#include "pal_collation.h" +#include "pal_collation_hg.h" #import @@ -11,7 +11,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) // Enum that corresponds to C# CompareOptions typedef enum { @@ -367,4 +366,3 @@ int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, int32_t } } -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_collation_hg.h b/src/native/libs/System.Globalization.Native/pal_collation_hg.h new file mode 100644 index 0000000000000..a0cb893a749e9 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_collation_hg.h @@ -0,0 +1,50 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_locale_hg.h" +#include "pal_compiler.h" +#include "pal_errors.h" + +PALEXPORT int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpTarget, + int32_t cwTargetLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options); + +PALEXPORT Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpTarget, + int32_t cwTargetLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options, + int32_t fromBeginning); + +PALEXPORT int32_t GlobalizationNative_StartsWithNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpPrefix, + int32_t cwPrefixLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options); + +PALEXPORT int32_t GlobalizationNative_EndsWithNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpSuffix, + int32_t cwSuffixLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options); + +PALEXPORT int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, + int32_t lNameLength, + const UChar* lpStr, + int32_t cwStrLength, + uint8_t* sortKey, + int32_t cbSortKeyLength, + int32_t options); + diff --git a/src/native/libs/System.Globalization.Native/pal_common.h b/src/native/libs/System.Globalization.Native/pal_common.h new file mode 100644 index 0000000000000..5baa335c55296 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_common.h @@ -0,0 +1,176 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_compiler.h" + +// calendarData +/* +* These values should be kept in sync with System.Globalization.CalendarId +*/ +enum +{ + UNINITIALIZED_VALUE = 0, + GREGORIAN = 1, // Gregorian (localized) calendar + GREGORIAN_US = 2, // Gregorian (U.S.) calendar + JAPAN = 3, // Japanese Emperor Era calendar + /* SSS_WARNINGS_OFF */ + TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */ + KOREA = 5, // Korean Tangun Era calendar + HIJRI = 6, // Hijri (Arabic Lunar) calendar + THAI = 7, // Thai calendar + HEBREW = 8, // Hebrew (Lunar) calendar + GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar + GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar + GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar + GREGORIAN_XLIT_FRENCH = 12, + // Note that all calendars after this point are MANAGED ONLY for now. + JULIAN = 13, + JAPANESELUNISOLAR = 14, + CHINESELUNISOLAR = 15, + SAKA = 16, // reserved to match Office but not implemented in our code + LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code + LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code + LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code + KOREANLUNISOLAR = 20, + TAIWANLUNISOLAR = 21, + PERSIAN = 22, + UMALQURA = 23, + LAST_CALENDAR = 23 // Last calendar ID +}; +typedef uint16_t CalendarId; + +/* +* These values should be kept in sync with System.Globalization.CalendarDataType +*/ +typedef enum +{ + CalendarData_Uninitialized = 0, + CalendarData_NativeName = 1, + CalendarData_MonthDay = 2, + CalendarData_ShortDates = 3, + CalendarData_LongDates = 4, + CalendarData_YearMonths = 5, + CalendarData_DayNames = 6, + CalendarData_AbbrevDayNames = 7, + CalendarData_MonthNames = 8, + CalendarData_AbbrevMonthNames = 9, + CalendarData_SuperShortDayNames = 10, + CalendarData_MonthGenitiveNames = 11, + CalendarData_AbbrevMonthGenitiveNames = 12, + CalendarData_EraNames = 13, + CalendarData_AbbrevEraNames = 14, +} CalendarDataType; + +#define GREGORIAN_NAME "gregorian" +#define JAPANESE_NAME "japanese" +#define BUDDHIST_NAME "buddhist" +#define HEBREW_NAME "hebrew" +#define DANGI_NAME "dangi" +#define PERSIAN_NAME "persian" +#define ISLAMIC_NAME "islamic" +#define ISLAMIC_UMALQURA_NAME "islamic-umalqura" +#define ROC_NAME "roc" + + +// locale data +// Enum that corresponds to managed enum CultureData.LocaleNumberData. +// The numeric values of the enum members match their Win32 counterparts. +typedef enum +{ + LocaleNumber_LanguageId = 0x01, + LocaleNumber_MeasurementSystem = 0x0D, + LocaleNumber_FractionalDigitsCount = 0x00000011, + LocaleNumber_NegativeNumberFormat = 0x00001010, + LocaleNumber_MonetaryFractionalDigitsCount = 0x00000019, + LocaleNumber_PositiveMonetaryNumberFormat = 0x0000001B, + LocaleNumber_NegativeMonetaryNumberFormat = 0x0000001C, + LocaleNumber_FirstDayofWeek = 0x0000100C, + LocaleNumber_FirstWeekOfYear = 0x0000100D, + LocaleNumber_ReadingLayout = 0x00000070, + LocaleNumber_NegativePercentFormat = 0x00000074, + LocaleNumber_PositivePercentFormat = 0x00000075, + LocaleNumber_Digit = 0x00000010, + LocaleNumber_Monetary = 0x00000018 +} LocaleNumberData; + +// Enum that corresponds to managed enum System.Globalization.CalendarWeekRule +typedef enum +{ + WeekRule_FirstDay = 0, + WeekRule_FirstFullWeek = 1, + WeekRule_FirstFourDayWeek = 2 +} CalendarWeekRule; + +// Enum that corresponds to managed enum CultureData.LocaleStringData. +// The numeric values of the enum members match their Win32 counterparts. +typedef enum +{ + LocaleString_LocalizedDisplayName = 0x02, + LocaleString_EnglishDisplayName = 0x00000072, + LocaleString_NativeDisplayName = 0x00000073, + LocaleString_LocalizedLanguageName = 0x0000006f, + LocaleString_EnglishLanguageName = 0x00001001, + LocaleString_NativeLanguageName = 0x04, + LocaleString_EnglishCountryName = 0x00001002, + LocaleString_NativeCountryName = 0x08, + LocaleString_DecimalSeparator = 0x0E, + LocaleString_ThousandSeparator = 0x0F, + LocaleString_Digits = 0x00000013, + LocaleString_MonetarySymbol = 0x00000014, + LocaleString_CurrencyEnglishName = 0x00001007, + LocaleString_CurrencyNativeName = 0x00001008, + LocaleString_Iso4217MonetarySymbol = 0x00000015, + LocaleString_MonetaryDecimalSeparator = 0x00000016, + LocaleString_MonetaryThousandSeparator = 0x00000017, + LocaleString_AMDesignator = 0x00000028, + LocaleString_PMDesignator = 0x00000029, + LocaleString_PositiveSign = 0x00000050, + LocaleString_NegativeSign = 0x00000051, + LocaleString_Iso639LanguageTwoLetterName = 0x00000059, + LocaleString_Iso639LanguageThreeLetterName = 0x00000067, + LocaleString_Iso3166CountryName = 0x0000005A, + LocaleString_Iso3166CountryName2= 0x00000068, + LocaleString_NaNSymbol = 0x00000069, + LocaleString_PositiveInfinitySymbol = 0x0000006a, + LocaleString_NegativeInfinitySymbol = 0x0000006b, + LocaleString_ParentName = 0x0000006d, + LocaleString_PercentSymbol = 0x00000076, + LocaleString_PerMilleSymbol = 0x00000077 +} LocaleStringData; + +// normalization +/* + * These values should be kept in sync with System.Text.NormalizationForm + */ +typedef enum +{ + FormC = 0x1, + FormD = 0x2, + FormKC = 0x5, + FormKD = 0x6 +} NormalizationForm; + +// timezoneinfo +/* +These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. +*/ +typedef enum +{ + TimeZoneDisplayName_Generic = 0, + TimeZoneDisplayName_Standard = 1, + TimeZoneDisplayName_DaylightSavings = 2, + TimeZoneDisplayName_GenericLocation = 3, + TimeZoneDisplayName_ExemplarCity = 4, + TimeZoneDisplayName_TimeZoneName = 5, +} TimeZoneDisplayNameType; + +// collation + +typedef struct SortHandle SortHandle; +typedef struct _Range { + int32_t location; + int32_t length; +} Range; diff --git a/src/native/libs/System.Globalization.Native/pal_hybrid.h b/src/native/libs/System.Globalization.Native/pal_hybrid.h new file mode 100644 index 0000000000000..cebcbe547b168 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_hybrid.h @@ -0,0 +1,421 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once +#include + +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) + +// All ICU headers need to be included here so that all function prototypes are +// available before the function pointers are declared below. +#include +#include +#include + +#endif + +/** + * Append a code point to a string, overwriting 1 or 2 code units. + * The offset points to the current end of the string contents + * and is advanced (post-increment). + * "Safe" macro, checks for a valid code point. + * Converts code points outside of Basic Multilingual Plane into + * corresponding surrogate pairs if sufficient space in the string. + * High surrogate range: 0xD800 - 0xDBFF + * Low surrogate range: 0xDC00 - 0xDFFF + * If the code point is not valid or a trail surrogate does not fit, + * then isError is set to true. + * + * @param buffer const uint16_t * string buffer + * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ + (isError) = InsufficientBuffer; \ + } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ + (isError) = InvalidCodePoint; \ + } else if ((uint32_t)(codePoint) <= 0xffff) { \ + (buffer)[(offset)++] = (uint16_t)(codePoint); \ + } else { \ + (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ + (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ + } \ +} + +/* ### Data tables **************************************************/ + +/** + * Table of language codes, both 2- and 3-letter, with preference + * given to 2-letter codes where possible. Includes 3-letter codes + * that lack a 2-letter equivalent. + * + * This list must be in sorted order. This list is returned directly + * to the user by some API. + * + * This list must be kept in sync with LANGUAGES_3, with corresponding + * entries matched. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The first list is visible to + * user code when this array is returned by API. The second list + * contains codes we support, but do not expose through user API. + * + * Notes + * + * Tables updated per http://lcweb.loc.gov/standards/iso639-2/ to + * include the revisions up to 2001/7/27 *CWB* + * + * The 3 character codes are the terminology codes like RFC 3066. + * + * "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in the + * table but now at the end of the table because 3 character codes are + * duplicates. This avoids bad searches going from 3 to 2 character + * codes. + * + * The range qaa-qtz is reserved for local use + */ +/* Subsequent hand addition of selected languages */ +static const char * const LANGUAGES[] = { + "aa", "ab", "ace", "ach", "ada", "ady", "ae", "aeb", + "af", "afh", "agq", "ain", "ak", "akk", "akz", "ale", + "aln", "alt", "am", "an", "ang", "anp", "ar", "arc", + "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "as", + "asa", "ase", "ast", "av", "avk", "awa", "ay", "az", + "ba", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", + "be", "bej", "bem", "bew", "bez", "bfd", "bfq", "bg", + "bgn", "bho", "bi", "bik", "bin", "bjn", "bkm", "bla", + "bm", "bn", "bo", "bpy", "bqi", "br", "bra", "brh", + "brx", "bs", "bss", "bua", "bug", "bum", "byn", "byv", + "ca", "cad", "car", "cay", "cch", "ccp", "ce", "ceb", "cgg", + "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", + "chr", "chy", "ckb", "co", "cop", "cps", "cr", "crh", + "cs", "csb", "cu", "cv", "cy", + "da", "dak", "dar", "dav", "de", "del", "den", "dgr", + "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "dv", + "dyo", "dyu", "dz", "dzg", + "ebu", "ee", "efi", "egl", "egy", "eka", "el", "elx", + "en", "enm", "eo", "es", "esu", "et", "eu", "ewo", + "ext", + "fa", "fan", "fat", "ff", "fi", "fil", "fit", "fj", + "fo", "fon", "fr", "frc", "frm", "fro", "frp", "frr", + "frs", "fur", "fy", + "ga", "gaa", "gag", "gan", "gay", "gba", "gbz", "gd", + "gez", "gil", "gl", "glk", "gmh", "gn", "goh", "gom", + "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guc", + "gur", "guz", "gv", "gwi", + "ha", "hai", "hak", "haw", "he", "hi", "hif", "hil", + "hit", "hmn", "ho", "hr", "hsb", "hsn", "ht", "hu", + "hup", "hy", "hz", + "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ik", + "ilo", "inh", "io", "is", "it", "iu", "izh", + "ja", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", + "jv", + "ka", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", + "kbl", "kcg", "kde", "kea", "ken", "kfo", "kg", "kgp", + "kha", "kho", "khq", "khw", "ki", "kiu", "kj", "kk", + "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "koi", + "kok", "kos", "kpe", "kr", "krc", "kri", "krj", "krl", + "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", + "kv", "kw", "ky", + "la", "lad", "lag", "lah", "lam", "lb", "lez", "lfn", + "lg", "li", "lij", "liv", "lkt", "lmo", "ln", "lo", + "lol", "loz", "lrc", "lt", "ltg", "lu", "lua", "lui", + "lun", "luo", "lus", "luy", "lv", "lzh", "lzz", + "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", + "mdf", "mdh", "mdr", "men", "mer", "mfe", "mg", "mga", + "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", + "ml", "mn", "mnc", "mni", "mo", + "moh", "mos", "mr", "mrj", + "ms", "mt", "mua", "mul", "mus", "mwl", "mwr", "mwv", + "my", "mye", "myv", "mzn", + "na", "nan", "nap", "naq", "nb", "nd", "nds", "ne", + "new", "ng", "nia", "niu", "njo", "nl", "nmg", "nn", + "nnh", "no", "nog", "non", "nov", "nqo", "nr", "nso", + "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", + "oc", "oj", "om", "or", "os", "osa", "ota", + "pa", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", + "pdt", "peo", "pfl", "phn", "pi", "pl", "pms", "pnt", + "pon", "prg", "pro", "ps", "pt", + "qu", "quc", "qug", + "raj", "rap", "rar", "rgn", "rif", "rm", "rn", "ro", + "rof", "rom", "rtm", "ru", "rue", "rug", "rup", + "rw", "rwk", + "sa", "sad", "sah", "sam", "saq", "sas", "sat", "saz", + "sba", "sbp", "sc", "scn", "sco", "sd", "sdc", "sdh", + "se", "see", "seh", "sei", "sel", "ses", "sg", "sga", + "sgs", "shi", "shn", "shu", "si", "sid", "sk", + "sl", "sli", "sly", "sm", "sma", "smj", "smn", "sms", + "sn", "snk", "so", "sog", "sq", "sr", "srn", "srr", + "ss", "ssy", "st", "stq", "su", "suk", "sus", "sux", + "sv", "sw", "swb", "swc", "syc", "syr", "szl", + "ta", "tcy", "te", "tem", "teo", "ter", "tet", "tg", + "th", "ti", "tig", "tiv", "tk", "tkl", "tkr", "tl", + "tlh", "tli", "tly", "tmh", "tn", "to", "tog", "tpi", + "tr", "tru", "trv", "ts", "tsd", "tsi", "tt", "ttt", + "tum", "tvl", "tw", "twq", "ty", "tyv", "tzm", + "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", + "vai", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", + "vot", "vro", "vun", + "wa", "wae", "wal", "war", "was", "wbp", "wo", "wuu", + "xal", "xh", "xmf", "xog", + "yao", "yap", "yav", "ybb", "yi", "yo", "yrl", "yue", + "za", "zap", "zbl", "zea", "zen", "zgh", "zh", "zu", + "zun", "zxx", "zza", +NULL, + "in", "iw", "ji", "jw", "sh", /* obsolete language codes */ +NULL +}; + +/** + * Table of 3-letter language codes. + * + * This is a lookup table used to convert 3-letter language codes to + * their 2-letter equivalent, where possible. It must be kept in sync + * with LANGUAGES. For all valid i, LANGUAGES[i] must refer to the + * same language as LANGUAGES_3[i]. The commented-out lines are + * copied from LANGUAGES to make eyeballing this baby easier. + * + * Where a 3-letter language code has no 2-letter equivalent, the + * 3-letter code occupies both LANGUAGES[i] and LANGUAGES_3[i]. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The two lists correspond to + * the two lists in LANGUAGES. + */ +/* Subsequent hand addition of selected languages */ +static const char * const LANGUAGES_3[] = { + "aar", "abk", "ace", "ach", "ada", "ady", "ave", "aeb", + "afr", "afh", "agq", "ain", "aka", "akk", "akz", "ale", + "aln", "alt", "amh", "arg", "ang", "anp", "ara", "arc", + "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "asm", + "asa", "ase", "ast", "ava", "avk", "awa", "aym", "aze", + "bak", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", + "bel", "bej", "bem", "bew", "bez", "bfd", "bfq", "bul", + "bgn", "bho", "bis", "bik", "bin", "bjn", "bkm", "bla", + "bam", "ben", "bod", "bpy", "bqi", "bre", "bra", "brh", + "brx", "bos", "bss", "bua", "bug", "bum", "byn", "byv", + "cat", "cad", "car", "cay", "cch", "ccp", "che", "ceb", "cgg", + "cha", "chb", "chg", "chk", "chm", "chn", "cho", "chp", + "chr", "chy", "ckb", "cos", "cop", "cps", "cre", "crh", + "ces", "csb", "chu", "chv", "cym", + "dan", "dak", "dar", "dav", "deu", "del", "den", "dgr", + "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "div", + "dyo", "dyu", "dzo", "dzg", + "ebu", "ewe", "efi", "egl", "egy", "eka", "ell", "elx", + "eng", "enm", "epo", "spa", "esu", "est", "eus", "ewo", + "ext", + "fas", "fan", "fat", "ful", "fin", "fil", "fit", "fij", + "fao", "fon", "fra", "frc", "frm", "fro", "frp", "frr", + "frs", "fur", "fry", + "gle", "gaa", "gag", "gan", "gay", "gba", "gbz", "gla", + "gez", "gil", "glg", "glk", "gmh", "grn", "goh", "gom", + "gon", "gor", "got", "grb", "grc", "gsw", "guj", "guc", + "gur", "guz", "glv", "gwi", + "hau", "hai", "hak", "haw", "heb", "hin", "hif", "hil", + "hit", "hmn", "hmo", "hrv", "hsb", "hsn", "hat", "hun", + "hup", "hye", "her", + "ina", "iba", "ibb", "ind", "ile", "ibo", "iii", "ipk", + "ilo", "inh", "ido", "isl", "ita", "iku", "izh", + "jpn", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", + "jav", + "kat", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", + "kbl", "kcg", "kde", "kea", "ken", "kfo", "kon", "kgp", + "kha", "kho", "khq", "khw", "kik", "kiu", "kua", "kaz", + "kkj", "kal", "kln", "khm", "kmb", "kan", "kor", "koi", + "kok", "kos", "kpe", "kau", "krc", "kri", "krj", "krl", + "kru", "kas", "ksb", "ksf", "ksh", "kur", "kum", "kut", + "kom", "cor", "kir", + "lat", "lad", "lag", "lah", "lam", "ltz", "lez", "lfn", + "lug", "lim", "lij", "liv", "lkt", "lmo", "lin", "lao", + "lol", "loz", "lrc", "lit", "ltg", "lub", "lua", "lui", + "lun", "luo", "lus", "luy", "lav", "lzh", "lzz", + "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", + "mdf", "mdh", "mdr", "men", "mer", "mfe", "mlg", "mga", + "mgh", "mgo", "mah", "mri", "mic", "min", "mis", "mkd", + "mal", "mon", "mnc", "mni", "mol", + "moh", "mos", "mar", "mrj", + "msa", "mlt", "mua", "mul", "mus", "mwl", "mwr", "mwv", + "mya", "mye", "myv", "mzn", + "nau", "nan", "nap", "naq", "nob", "nde", "nds", "nep", + "new", "ndo", "nia", "niu", "njo", "nld", "nmg", "nno", + "nnh", "nor", "nog", "non", "nov", "nqo", "nbl", "nso", + "nus", "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", + "oci", "oji", "orm", "ori", "oss", "osa", "ota", + "pan", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", + "pdt", "peo", "pfl", "phn", "pli", "pol", "pms", "pnt", + "pon", "prg", "pro", "pus", "por", + "que", "quc", "qug", + "raj", "rap", "rar", "rgn", "rif", "roh", "run", "ron", + "rof", "rom", "rtm", "rus", "rue", "rug", "rup", + "kin", "rwk", + "san", "sad", "sah", "sam", "saq", "sas", "sat", "saz", + "sba", "sbp", "srd", "scn", "sco", "snd", "sdc", "sdh", + "sme", "see", "seh", "sei", "sel", "ses", "sag", "sga", + "sgs", "shi", "shn", "shu", "sin", "sid", "slk", + "slv", "sli", "sly", "smo", "sma", "smj", "smn", "sms", + "sna", "snk", "som", "sog", "sqi", "srp", "srn", "srr", + "ssw", "ssy", "sot", "stq", "sun", "suk", "sus", "sux", + "swe", "swa", "swb", "swc", "syc", "syr", "szl", + "tam", "tcy", "tel", "tem", "teo", "ter", "tet", "tgk", + "tha", "tir", "tig", "tiv", "tuk", "tkl", "tkr", "tgl", + "tlh", "tli", "tly", "tmh", "tsn", "ton", "tog", "tpi", + "tur", "tru", "trv", "tso", "tsd", "tsi", "tat", "ttt", + "tum", "tvl", "twi", "twq", "tah", "tyv", "tzm", + "udm", "uig", "uga", "ukr", "umb", "und", "urd", "uzb", + "vai", "ven", "vec", "vep", "vie", "vls", "vmf", "vol", + "vot", "vro", "vun", + "wln", "wae", "wal", "war", "was", "wbp", "wol", "wuu", + "xal", "xho", "xmf", "xog", + "yao", "yap", "yav", "ybb", "yid", "yor", "yrl", "yue", + "zha", "zap", "zbl", "zea", "zen", "zgh", "zho", "zul", + "zun", "zxx", "zza", +NULL, +/* "in", "iw", "ji", "jw", "sh", */ + "ind", "heb", "yid", "jaw", "srp", +NULL +}; + +/** + * Table of 2-letter country codes. + * + * This list must be in sorted order. This list is returned directly + * to the user by some API. + * + * This list must be kept in sync with COUNTRIES_3, with corresponding + * entries matched. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The first list is visible to + * user code when this array is returned by API. The second list + * contains codes we support, but do not expose through user API. + * + * Notes: + * + * ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per + * http://www.evertype.com/standards/iso3166/iso3166-1-en.html added + * new codes keeping the old ones for compatibility updated to include + * 1999/12/03 revisions *CWB* + * + * RO(ROM) is now RO(ROU) according to + * http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html + */ +static const char * const COUNTRIES[] = { + "AD", "AE", "AF", "AG", "AI", "AL", "AM", + "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", + "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", + "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", + "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", + "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", + "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", + "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", + "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", + "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", + "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", + "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", + "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", + "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", + "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", + "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", + "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", + "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", + "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", + "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", + "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", + "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", + "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", + "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", + "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", + "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", + "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", + "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", + "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", + "WS", "YE", "YT", "ZA", "ZM", "ZW", +NULL, + "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR", /* obsolete country codes */ +NULL +}; + +/** + * Table of 3-letter country codes. + * + * This is a lookup table used to convert 3-letter country codes to + * their 2-letter equivalent. It must be kept in sync with COUNTRIES. + * For all valid i, COUNTRIES[i] must refer to the same country as + * COUNTRIES_3[i]. The commented-out lines are copied from COUNTRIES + * to make eyeballing this baby easier. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The two lists correspond to + * the two lists in COUNTRIES. + */ +static const char * const COUNTRIES_3[] = { +/* "AD", "AE", "AF", "AG", "AI", "AL", "AM", */ + "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", +/* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ + "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", +/* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ + "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", +/* "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", */ + "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", +/* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ + "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", +/* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ + "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", +/* "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", */ + "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK", +/* "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", */ + "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI", +/* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ + "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", +/* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ + "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", +/* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ + "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", +/* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ + "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", +/* "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ + "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", +/* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ + "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", +/* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ + "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", +/* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ + "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", +/* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ + "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", +/* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ + "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", +/* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ + "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", +/* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ + "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", +/* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ + "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", +/* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ + "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", +/* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ + "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", +/* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ + "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", +/* "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", */ + "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", +/* "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ + "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", +/* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ + "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", +/* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ + "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", +/* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ + "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", +/* "WS", "YE", "YT", "ZA", "ZM", "ZW", */ + "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE", +NULL, +/* "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR" */ + "ANT", "BUR", "SCG", "FXX", "ROM", "SUN", "TMP", "YMD", "YUG", "ZAR", +NULL +}; + diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h index a7bad69cef319..e62ced1015f4e 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h @@ -21,11 +21,7 @@ // All ICU headers need to be included here so that all function prototypes are // available before the function pointers are declared below. -#if defined(APPLE_HYBRID_GLOBALIZATION) -#include -#include -#include -#else + #include #include #include @@ -46,7 +42,6 @@ #include #include -#endif #endif #elif defined(TARGET_WINDOWS) @@ -352,35 +347,3 @@ const char* GlobalizationNative_GetICUDataPathFallback(void); #endif #endif // !defined(STATIC_ICU) -#if defined(APPLE_HYBRID_GLOBALIZATION) -/** - * Append a code point to a string, overwriting 1 or 2 code units. - * The offset points to the current end of the string contents - * and is advanced (post-increment). - * "Safe" macro, checks for a valid code point. - * Converts code points outside of Basic Multilingual Plane into - * corresponding surrogate pairs if sufficient space in the string. - * High surrogate range: 0xD800 - 0xDBFF - * Low surrogate range: 0xDC00 - 0xDFFF - * If the code point is not valid or a trail surrogate does not fit, - * then isError is set to true. - * - * @param buffer const uint16_t * string buffer - * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ - (isError) = InsufficientBuffer; \ - } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ - (isError) = InvalidCodePoint; \ - } else if ((uint32_t)(codePoint) <= 0xffff) { \ - (buffer)[(offset)++] = (uint16_t)(codePoint); \ - } else { \ - (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ - (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ - } \ -} -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_static.c index ecef84ab79335..a5dde7c363a3d 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_static.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim_static.c @@ -11,9 +11,7 @@ #include #include -#if !defined(APPLE_HYBRID_GLOBALIZATION) #include -#endif #if defined(TARGET_UNIX) #include @@ -21,7 +19,6 @@ #define strcasecmp _stricmp #define strncasecmp _strnicmp #endif -#if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS) static int32_t isLoaded = 0; static int32_t isDataSet = 0; @@ -250,5 +247,4 @@ int32_t GlobalizationNative_GetICUVersion(void) return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; } -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_locale.h index 8ded749d3c11c..0c6e1e6933bf3 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_locale.h @@ -16,389 +16,4 @@ PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); - -PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); - -PALEXPORT const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat); - -PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t length); - -PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); - -/* ### Data tables **************************************************/ - -/** - * Table of language codes, both 2- and 3-letter, with preference - * given to 2-letter codes where possible. Includes 3-letter codes - * that lack a 2-letter equivalent. - * - * This list must be in sorted order. This list is returned directly - * to the user by some API. - * - * This list must be kept in sync with LANGUAGES_3, with corresponding - * entries matched. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The first list is visible to - * user code when this array is returned by API. The second list - * contains codes we support, but do not expose through user API. - * - * Notes - * - * Tables updated per http://lcweb.loc.gov/standards/iso639-2/ to - * include the revisions up to 2001/7/27 *CWB* - * - * The 3 character codes are the terminology codes like RFC 3066. - * - * "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in the - * table but now at the end of the table because 3 character codes are - * duplicates. This avoids bad searches going from 3 to 2 character - * codes. - * - * The range qaa-qtz is reserved for local use - */ -/* Subsequent hand addition of selected languages */ -static const char * const LANGUAGES[] = { - "aa", "ab", "ace", "ach", "ada", "ady", "ae", "aeb", - "af", "afh", "agq", "ain", "ak", "akk", "akz", "ale", - "aln", "alt", "am", "an", "ang", "anp", "ar", "arc", - "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "as", - "asa", "ase", "ast", "av", "avk", "awa", "ay", "az", - "ba", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", - "be", "bej", "bem", "bew", "bez", "bfd", "bfq", "bg", - "bgn", "bho", "bi", "bik", "bin", "bjn", "bkm", "bla", - "bm", "bn", "bo", "bpy", "bqi", "br", "bra", "brh", - "brx", "bs", "bss", "bua", "bug", "bum", "byn", "byv", - "ca", "cad", "car", "cay", "cch", "ccp", "ce", "ceb", "cgg", - "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", - "chr", "chy", "ckb", "co", "cop", "cps", "cr", "crh", - "cs", "csb", "cu", "cv", "cy", - "da", "dak", "dar", "dav", "de", "del", "den", "dgr", - "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "dv", - "dyo", "dyu", "dz", "dzg", - "ebu", "ee", "efi", "egl", "egy", "eka", "el", "elx", - "en", "enm", "eo", "es", "esu", "et", "eu", "ewo", - "ext", - "fa", "fan", "fat", "ff", "fi", "fil", "fit", "fj", - "fo", "fon", "fr", "frc", "frm", "fro", "frp", "frr", - "frs", "fur", "fy", - "ga", "gaa", "gag", "gan", "gay", "gba", "gbz", "gd", - "gez", "gil", "gl", "glk", "gmh", "gn", "goh", "gom", - "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guc", - "gur", "guz", "gv", "gwi", - "ha", "hai", "hak", "haw", "he", "hi", "hif", "hil", - "hit", "hmn", "ho", "hr", "hsb", "hsn", "ht", "hu", - "hup", "hy", "hz", - "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ik", - "ilo", "inh", "io", "is", "it", "iu", "izh", - "ja", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", - "jv", - "ka", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", - "kbl", "kcg", "kde", "kea", "ken", "kfo", "kg", "kgp", - "kha", "kho", "khq", "khw", "ki", "kiu", "kj", "kk", - "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "koi", - "kok", "kos", "kpe", "kr", "krc", "kri", "krj", "krl", - "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", - "kv", "kw", "ky", - "la", "lad", "lag", "lah", "lam", "lb", "lez", "lfn", - "lg", "li", "lij", "liv", "lkt", "lmo", "ln", "lo", - "lol", "loz", "lrc", "lt", "ltg", "lu", "lua", "lui", - "lun", "luo", "lus", "luy", "lv", "lzh", "lzz", - "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", - "mdf", "mdh", "mdr", "men", "mer", "mfe", "mg", "mga", - "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", - "ml", "mn", "mnc", "mni", "mo", - "moh", "mos", "mr", "mrj", - "ms", "mt", "mua", "mul", "mus", "mwl", "mwr", "mwv", - "my", "mye", "myv", "mzn", - "na", "nan", "nap", "naq", "nb", "nd", "nds", "ne", - "new", "ng", "nia", "niu", "njo", "nl", "nmg", "nn", - "nnh", "no", "nog", "non", "nov", "nqo", "nr", "nso", - "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", - "oc", "oj", "om", "or", "os", "osa", "ota", - "pa", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", - "pdt", "peo", "pfl", "phn", "pi", "pl", "pms", "pnt", - "pon", "prg", "pro", "ps", "pt", - "qu", "quc", "qug", - "raj", "rap", "rar", "rgn", "rif", "rm", "rn", "ro", - "rof", "rom", "rtm", "ru", "rue", "rug", "rup", - "rw", "rwk", - "sa", "sad", "sah", "sam", "saq", "sas", "sat", "saz", - "sba", "sbp", "sc", "scn", "sco", "sd", "sdc", "sdh", - "se", "see", "seh", "sei", "sel", "ses", "sg", "sga", - "sgs", "shi", "shn", "shu", "si", "sid", "sk", - "sl", "sli", "sly", "sm", "sma", "smj", "smn", "sms", - "sn", "snk", "so", "sog", "sq", "sr", "srn", "srr", - "ss", "ssy", "st", "stq", "su", "suk", "sus", "sux", - "sv", "sw", "swb", "swc", "syc", "syr", "szl", - "ta", "tcy", "te", "tem", "teo", "ter", "tet", "tg", - "th", "ti", "tig", "tiv", "tk", "tkl", "tkr", "tl", - "tlh", "tli", "tly", "tmh", "tn", "to", "tog", "tpi", - "tr", "tru", "trv", "ts", "tsd", "tsi", "tt", "ttt", - "tum", "tvl", "tw", "twq", "ty", "tyv", "tzm", - "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", - "vai", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", - "vot", "vro", "vun", - "wa", "wae", "wal", "war", "was", "wbp", "wo", "wuu", - "xal", "xh", "xmf", "xog", - "yao", "yap", "yav", "ybb", "yi", "yo", "yrl", "yue", - "za", "zap", "zbl", "zea", "zen", "zgh", "zh", "zu", - "zun", "zxx", "zza", -NULL, - "in", "iw", "ji", "jw", "sh", /* obsolete language codes */ -NULL -}; - -/** - * Table of 3-letter language codes. - * - * This is a lookup table used to convert 3-letter language codes to - * their 2-letter equivalent, where possible. It must be kept in sync - * with LANGUAGES. For all valid i, LANGUAGES[i] must refer to the - * same language as LANGUAGES_3[i]. The commented-out lines are - * copied from LANGUAGES to make eyeballing this baby easier. - * - * Where a 3-letter language code has no 2-letter equivalent, the - * 3-letter code occupies both LANGUAGES[i] and LANGUAGES_3[i]. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The two lists correspond to - * the two lists in LANGUAGES. - */ -/* Subsequent hand addition of selected languages */ -static const char * const LANGUAGES_3[] = { - "aar", "abk", "ace", "ach", "ada", "ady", "ave", "aeb", - "afr", "afh", "agq", "ain", "aka", "akk", "akz", "ale", - "aln", "alt", "amh", "arg", "ang", "anp", "ara", "arc", - "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "asm", - "asa", "ase", "ast", "ava", "avk", "awa", "aym", "aze", - "bak", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", - "bel", "bej", "bem", "bew", "bez", "bfd", "bfq", "bul", - "bgn", "bho", "bis", "bik", "bin", "bjn", "bkm", "bla", - "bam", "ben", "bod", "bpy", "bqi", "bre", "bra", "brh", - "brx", "bos", "bss", "bua", "bug", "bum", "byn", "byv", - "cat", "cad", "car", "cay", "cch", "ccp", "che", "ceb", "cgg", - "cha", "chb", "chg", "chk", "chm", "chn", "cho", "chp", - "chr", "chy", "ckb", "cos", "cop", "cps", "cre", "crh", - "ces", "csb", "chu", "chv", "cym", - "dan", "dak", "dar", "dav", "deu", "del", "den", "dgr", - "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "div", - "dyo", "dyu", "dzo", "dzg", - "ebu", "ewe", "efi", "egl", "egy", "eka", "ell", "elx", - "eng", "enm", "epo", "spa", "esu", "est", "eus", "ewo", - "ext", - "fas", "fan", "fat", "ful", "fin", "fil", "fit", "fij", - "fao", "fon", "fra", "frc", "frm", "fro", "frp", "frr", - "frs", "fur", "fry", - "gle", "gaa", "gag", "gan", "gay", "gba", "gbz", "gla", - "gez", "gil", "glg", "glk", "gmh", "grn", "goh", "gom", - "gon", "gor", "got", "grb", "grc", "gsw", "guj", "guc", - "gur", "guz", "glv", "gwi", - "hau", "hai", "hak", "haw", "heb", "hin", "hif", "hil", - "hit", "hmn", "hmo", "hrv", "hsb", "hsn", "hat", "hun", - "hup", "hye", "her", - "ina", "iba", "ibb", "ind", "ile", "ibo", "iii", "ipk", - "ilo", "inh", "ido", "isl", "ita", "iku", "izh", - "jpn", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", - "jav", - "kat", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", - "kbl", "kcg", "kde", "kea", "ken", "kfo", "kon", "kgp", - "kha", "kho", "khq", "khw", "kik", "kiu", "kua", "kaz", - "kkj", "kal", "kln", "khm", "kmb", "kan", "kor", "koi", - "kok", "kos", "kpe", "kau", "krc", "kri", "krj", "krl", - "kru", "kas", "ksb", "ksf", "ksh", "kur", "kum", "kut", - "kom", "cor", "kir", - "lat", "lad", "lag", "lah", "lam", "ltz", "lez", "lfn", - "lug", "lim", "lij", "liv", "lkt", "lmo", "lin", "lao", - "lol", "loz", "lrc", "lit", "ltg", "lub", "lua", "lui", - "lun", "luo", "lus", "luy", "lav", "lzh", "lzz", - "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", - "mdf", "mdh", "mdr", "men", "mer", "mfe", "mlg", "mga", - "mgh", "mgo", "mah", "mri", "mic", "min", "mis", "mkd", - "mal", "mon", "mnc", "mni", "mol", - "moh", "mos", "mar", "mrj", - "msa", "mlt", "mua", "mul", "mus", "mwl", "mwr", "mwv", - "mya", "mye", "myv", "mzn", - "nau", "nan", "nap", "naq", "nob", "nde", "nds", "nep", - "new", "ndo", "nia", "niu", "njo", "nld", "nmg", "nno", - "nnh", "nor", "nog", "non", "nov", "nqo", "nbl", "nso", - "nus", "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", - "oci", "oji", "orm", "ori", "oss", "osa", "ota", - "pan", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", - "pdt", "peo", "pfl", "phn", "pli", "pol", "pms", "pnt", - "pon", "prg", "pro", "pus", "por", - "que", "quc", "qug", - "raj", "rap", "rar", "rgn", "rif", "roh", "run", "ron", - "rof", "rom", "rtm", "rus", "rue", "rug", "rup", - "kin", "rwk", - "san", "sad", "sah", "sam", "saq", "sas", "sat", "saz", - "sba", "sbp", "srd", "scn", "sco", "snd", "sdc", "sdh", - "sme", "see", "seh", "sei", "sel", "ses", "sag", "sga", - "sgs", "shi", "shn", "shu", "sin", "sid", "slk", - "slv", "sli", "sly", "smo", "sma", "smj", "smn", "sms", - "sna", "snk", "som", "sog", "sqi", "srp", "srn", "srr", - "ssw", "ssy", "sot", "stq", "sun", "suk", "sus", "sux", - "swe", "swa", "swb", "swc", "syc", "syr", "szl", - "tam", "tcy", "tel", "tem", "teo", "ter", "tet", "tgk", - "tha", "tir", "tig", "tiv", "tuk", "tkl", "tkr", "tgl", - "tlh", "tli", "tly", "tmh", "tsn", "ton", "tog", "tpi", - "tur", "tru", "trv", "tso", "tsd", "tsi", "tat", "ttt", - "tum", "tvl", "twi", "twq", "tah", "tyv", "tzm", - "udm", "uig", "uga", "ukr", "umb", "und", "urd", "uzb", - "vai", "ven", "vec", "vep", "vie", "vls", "vmf", "vol", - "vot", "vro", "vun", - "wln", "wae", "wal", "war", "was", "wbp", "wol", "wuu", - "xal", "xho", "xmf", "xog", - "yao", "yap", "yav", "ybb", "yid", "yor", "yrl", "yue", - "zha", "zap", "zbl", "zea", "zen", "zgh", "zho", "zul", - "zun", "zxx", "zza", -NULL, -/* "in", "iw", "ji", "jw", "sh", */ - "ind", "heb", "yid", "jaw", "srp", -NULL -}; - -/** - * Table of 2-letter country codes. - * - * This list must be in sorted order. This list is returned directly - * to the user by some API. - * - * This list must be kept in sync with COUNTRIES_3, with corresponding - * entries matched. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The first list is visible to - * user code when this array is returned by API. The second list - * contains codes we support, but do not expose through user API. - * - * Notes: - * - * ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per - * http://www.evertype.com/standards/iso3166/iso3166-1-en.html added - * new codes keeping the old ones for compatibility updated to include - * 1999/12/03 revisions *CWB* - * - * RO(ROM) is now RO(ROU) according to - * http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html - */ -static const char * const COUNTRIES[] = { - "AD", "AE", "AF", "AG", "AI", "AL", "AM", - "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", - "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", - "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", - "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", - "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", - "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", - "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", - "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", - "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", - "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", - "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", - "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", - "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", - "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", - "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", - "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", - "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", - "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", - "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", - "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", - "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", - "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", - "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", - "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", - "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", - "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", - "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", - "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", - "WS", "YE", "YT", "ZA", "ZM", "ZW", -NULL, - "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR", /* obsolete country codes */ -NULL -}; - -/** - * Table of 3-letter country codes. - * - * This is a lookup table used to convert 3-letter country codes to - * their 2-letter equivalent. It must be kept in sync with COUNTRIES. - * For all valid i, COUNTRIES[i] must refer to the same country as - * COUNTRIES_3[i]. The commented-out lines are copied from COUNTRIES - * to make eyeballing this baby easier. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The two lists correspond to - * the two lists in COUNTRIES. - */ -static const char * const COUNTRIES_3[] = { -/* "AD", "AE", "AF", "AG", "AI", "AL", "AM", */ - "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", -/* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ - "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", -/* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ - "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", -/* "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", */ - "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", -/* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ - "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", -/* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ - "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", -/* "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", */ - "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK", -/* "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", */ - "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI", -/* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ - "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", -/* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ - "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", -/* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ - "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", -/* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ - "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", -/* "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ - "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", -/* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ - "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", -/* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ - "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", -/* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ - "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", -/* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ - "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", -/* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ - "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", -/* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ - "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", -/* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ - "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", -/* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ - "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", -/* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ - "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", -/* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ - "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", -/* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ - "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", -/* "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", */ - "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", -/* "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ - "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", -/* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ - "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", -/* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ - "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", -/* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ - "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", -/* "WS", "YE", "YT", "ZA", "ZM", "ZW", */ - "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE", -NULL, -/* "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR" */ - "ANT", "BUR", "SCG", "FXX", "ROM", "SUN", "TMP", "YMD", "YUG", "ZAR", -NULL -}; - -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 873b56950ee3c..c36f33e53044f 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -3,9 +3,8 @@ #include #include -#include "pal_locale_internal.h" -#include "pal_localeStringData.h" -#include "pal_localeNumberData.h" +#include "pal_hybrid.h" +#include "pal_common.h" #import #import @@ -36,734 +35,6 @@ return strdup([localeName UTF8String]); } -#if defined(APPLE_HYBRID_GLOBALIZATION) -const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - const char* value = [currentLocale.localeIdentifier UTF8String]; - return strdup(value); - } -} - -/** - * Useful constant for the maximum size of the whole locale ID - * (including the terminating NULL and all keywords). - */ -#define FULLNAME_CAPACITY 157 - -static void GetParent(const char* localeID, char* parent, int32_t parentCapacity) -{ - const char *lastUnderscore; - int32_t i; - - if (localeID == NULL) - localeID = [NSLocale systemLocale].localeIdentifier.UTF8String; - - lastUnderscore = strrchr(localeID, '-'); - if (lastUnderscore != NULL) - { - i = (int32_t)(lastUnderscore - localeID); - } - else - { - i = 0; - } - - if (i > 0) - { - // primary lang subtag und (undefined). - if (strncasecmp(localeID, "und-", 4) == 0) - { - localeID += 3; - i -= 3; - memmove(parent, localeID, MIN(i, parentCapacity)); - } - else if (parent != localeID) - { - memcpy(parent, localeID, MIN(i, parentCapacity)); - } - } - - // terminate chars - if (i >= 0 && i < parentCapacity) - parent[i] = 0; -} - -/** - * Lookup 'key' in the array 'list'. The array 'list' should contain - * a NULL entry, followed by more entries, and a second NULL entry. - * - * The 'list' param should be LANGUAGES, LANGUAGES_3, COUNTRIES, or - * COUNTRIES_3. - */ -static int16_t _findIndex(const char* const* list, const char* key) -{ - const char* const* anchor = list; - int32_t pass = 0; - - /* Make two passes through two NULL-terminated arrays at 'list' */ - while (pass++ < 2) { - while (*list) { - if (strcmp(key, *list) == 0) { - return (int16_t)(list - anchor); - } - list++; - } - ++list; /* skip final NULL *CWB*/ - } - return -1; -} - -static const char* getISO3CountryByCountryCode(const char* countryCode) -{ - int16_t offset = _findIndex(COUNTRIES, countryCode); - if (offset < 0) - return ""; - - return COUNTRIES_3[offset]; -} - -static const char* getISO3LanguageByLangCode(const char* langCode) -{ - int16_t offset = _findIndex(LANGUAGES, langCode); - if (offset < 0) - return ""; - return LANGUAGES_3[offset]; -} - -const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName) -{ - @autoreleasepool - { - NSString *value; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setLocale:currentLocale]; - NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; - - switch (localeStringData) - { - ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) - case LocaleString_LocalizedDisplayName: - { - NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; - NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; - value = [currentUILocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; - 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]; - break; - /// Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME) - case LocaleString_NativeDisplayName: - value = [currentLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; - break; - /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) - case LocaleString_LocalizedLanguageName: - { - NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; - NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; - value = [currentUILocale localizedStringForLanguageCode:currentLocale.languageCode]; - break; - } - /// English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME) - case LocaleString_EnglishLanguageName: - value = [gbLocale localizedStringForLanguageCode:currentLocale.languageCode]; - break; - /// native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME) - case LocaleString_NativeLanguageName: - value = [currentLocale localizedStringForLanguageCode:currentLocale.languageCode]; - break; - /// English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME) - case LocaleString_EnglishCountryName: - value = [gbLocale localizedStringForCountryCode:currentLocale.countryCode]; - break; - /// native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME) - case LocaleString_NativeCountryName: - value = [currentLocale localizedStringForCountryCode:currentLocale.countryCode]; - break; - case LocaleString_ThousandSeparator: - value = currentLocale.groupingSeparator; - break; - case LocaleString_DecimalSeparator: - value = currentLocale.decimalSeparator; - // or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String]; - break; - case LocaleString_Digits: - { - NSString *digitsString = @"0123456789"; - NSNumberFormatter *nf1 = [[NSNumberFormatter alloc] init]; - [nf1 setLocale:currentLocale]; - - NSNumber *newNum = [nf1 numberFromString:digitsString]; - value = [newNum stringValue]; - break; - } - case LocaleString_MonetarySymbol: - value = currentLocale.currencySymbol; - break; - case LocaleString_Iso4217MonetarySymbol: - // check if this is correct, check currencyISOCode - value = currentLocale.currencyCode; - break; - case LocaleString_CurrencyEnglishName: - value = [gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; - break; - case LocaleString_CurrencyNativeName: - value = [currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; - break; - case LocaleString_MonetaryDecimalSeparator: - value = numberFormatter.currencyDecimalSeparator; - break; - case LocaleString_MonetaryThousandSeparator: - value = numberFormatter.currencyGroupingSeparator; - break; - case LocaleString_AMDesignator: - value = dateFormatter.AMSymbol; - break; - case LocaleString_PMDesignator: - value = dateFormatter.PMSymbol; - break; - case LocaleString_PositiveSign: - value = numberFormatter.plusSign; - break; - case LocaleString_NegativeSign: - value = numberFormatter.minusSign; - break; - case LocaleString_Iso639LanguageTwoLetterName: - value = [currentLocale objectForKey:NSLocaleLanguageCode]; - break; - case LocaleString_Iso639LanguageThreeLetterName: - { - NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; - return iso639_2 == nil ? strdup("") : strdup(getISO3LanguageByLangCode([iso639_2 UTF8String])); - } - case LocaleString_Iso3166CountryName: - value = [currentLocale objectForKey:NSLocaleCountryCode]; - break; - case LocaleString_Iso3166CountryName2: - { - NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; - return countryCode == nil ? strdup("") : strdup(getISO3CountryByCountryCode([countryCode UTF8String])); - } - case LocaleString_NaNSymbol: - value = numberFormatter.notANumberSymbol; - break; - case LocaleString_PositiveInfinitySymbol: - value = numberFormatter.positiveInfinitySymbol; - break; - case LocaleString_NegativeInfinitySymbol: - value = numberFormatter.negativeInfinitySymbol; - break; - case LocaleString_PercentSymbol: - value = numberFormatter.percentSymbol; - break; - case LocaleString_PerMilleSymbol: - value = numberFormatter.perMillSymbol; - break; - case LocaleString_ParentName: - { - char localeNameTemp[FULLNAME_CAPACITY]; - const char* lName = [currentLocale.localeIdentifier UTF8String]; - GetParent(lName, localeNameTemp, FULLNAME_CAPACITY); - return strdup(localeNameTemp); - } - default: - value = nil; - break; - } - - return value == nil ? strdup("") : strdup([value UTF8String]); - } -} - -// invariant character definitions -#define CHAR_CURRENCY ((char)0x00A4) // international currency -#define CHAR_SPACE ((char)0x0020) // space -#define CHAR_NBSPACE ((char)0x00A0) // no-break space -#define CHAR_DIGIT ((char)0x0023) // '#' -#define CHAR_MINUS ((char)0x002D) // '-' -#define CHAR_PERCENT ((char)0x0025) // '%' -#define CHAR_OPENPAREN ((char)0x0028) // '(' -#define CHAR_CLOSEPAREN ((char)0x0029) // ')' -#define CHAR_ZERO ((char)0x0030) // '0' - -/* -Function: -NormalizeNumericPattern - -Returns a numeric string pattern in a format that we can match against the -appropriate managed pattern. Examples: -For PositiveMonetaryNumberFormat "¤#,##0.00" becomes "Cn" -For NegativeNumberFormat "#,##0.00;(#,##0.00)" becomes "(n)" -*/ -static char* NormalizeNumericPattern(const char* srcPattern, int isNegative) -{ - int iStart = 0; - int iEnd = strlen(srcPattern); - - // ';' separates positive and negative subpatterns. - // When there is no explicit negative subpattern, - // an implicit negative subpattern is formed from the positive pattern with a prefixed '-'. - char * ptrNegativePattern = strrchr(srcPattern,';'); - if (ptrNegativePattern) - { - int32_t iNegativePatternStart = ptrNegativePattern - srcPattern; - if (isNegative) - { - iStart = iNegativePatternStart + 1; - } - else - { - iEnd = iNegativePatternStart - 1; - } - } - - int minusAdded = false; - - for (int i = iStart; i <= iEnd; i++) - { - switch (srcPattern[i]) - { - case CHAR_MINUS: - case CHAR_OPENPAREN: - case CHAR_CLOSEPAREN: - minusAdded = true; - break; - } - - if (minusAdded) - break; - } - - // international currency symbol (CHAR_CURRENCY) - // The positive pattern comes first, then an optional negative pattern - // separated by a semicolon - // A destPattern example: "(C n)" where C represents the currency symbol, and - // n is the number - char* destPattern; - int index = 0; - - // if there is no negative subpattern, prefix the minus sign - if (isNegative && !minusAdded) - { - int length = (iEnd - iStart) + 2; - destPattern = (char*)calloc((size_t)length, sizeof(char)); - if (!destPattern) - { - return NULL; - } - destPattern[index++] = '-'; - } - else - { - int length = (iEnd - iStart) + 1; - destPattern = (char*)calloc((size_t)length, sizeof(char)); - if (!destPattern) - { - return NULL; - } - } - - int digitAdded = false; - int currencyAdded = false; - int spaceAdded = false; - - for (int i = iStart; i <= iEnd; i++) - { - char ch = srcPattern[i]; - switch (ch) - { - case CHAR_DIGIT: - case CHAR_ZERO: - if (!digitAdded) - { - digitAdded = true; - destPattern[index++] = 'n'; - } - break; - - case CHAR_CURRENCY: - if (!currencyAdded) - { - currencyAdded = true; - destPattern[index++] = 'C'; - } - break; - - case CHAR_SPACE: - case CHAR_NBSPACE: - if (!spaceAdded) - { - spaceAdded = true; - destPattern[index++] = ' '; - } - break; - - case CHAR_MINUS: - case CHAR_OPENPAREN: - case CHAR_CLOSEPAREN: - case CHAR_PERCENT: - destPattern[index++] = ch; - break; - } - } - - const int MAX_DOTNET_NUMERIC_PATTERN_LENGTH = 6; // example: "(C n)" plus terminator - - if (destPattern[0] == '\0' || strlen (destPattern) >= MAX_DOTNET_NUMERIC_PATTERN_LENGTH) - { - free (destPattern); - return NULL; - } - - return destPattern; -} - -/* -Function: -GetNumericPattern - -Determines the pattern from the decimalFormat and returns the matching pattern's -index from patterns[]. -Returns index -1 if no pattern is found. -*/ -static int GetPatternIndex(char* normalizedPattern,const char* patterns[], int patternsCount) -{ - const int INVALID_FORMAT = -1; - - if (!normalizedPattern) - { - return INVALID_FORMAT; - } - - for (int i = 0; i < patternsCount; i++) - { - if (strcmp(normalizedPattern, patterns[i]) == 0) - { - free(normalizedPattern); - return i; - } - } - - assert(false); // should have found a valid pattern - - free(normalizedPattern); - return INVALID_FORMAT; -} - -static int32_t GetValueForNumberFormat(NSLocale *currentLocale, LocaleNumberData localeNumberData) -{ - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - const char *pFormat; - int32_t value; - - switch(localeNumberData) - { - case LocaleNumber_PositiveMonetaryNumberFormat: - { - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - static const char* Patterns[] = {"Cn", "nC", "C n", "n C"}; - pFormat = [[numberFormatter positiveFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, false); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_NegativeMonetaryNumberFormat: - { - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - static const char* Patterns[] = {"(Cn)", "-Cn", "C-n", "Cn-", "(nC)", "-nC", "n-C", "nC-", "-n C", - "-C n", "n C-", "C n-", "C -n", "n- C", "(C n)", "(n C)", "C- n" }; - pFormat = [[numberFormatter negativeFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, true); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_NegativeNumberFormat: - { - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - static const char* Patterns[] = {"(n)", "-n", "- n", "n-", "n -"}; - pFormat = [[numberFormatter negativeFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, true); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_NegativePercentFormat: - { - numberFormatter.numberStyle = NSNumberFormatterPercentStyle; - static const char* Patterns[] = {"-n %", "-n%", "-%n", "%-n", "%n-", "n-%", "n%-", "-% n", "n %-", "% n-", "% -n", "n- %"}; - pFormat = [[numberFormatter negativeFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, true); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_PositivePercentFormat: - { - numberFormatter.numberStyle = NSNumberFormatterPercentStyle; - static const char* Patterns[] = {"n %", "n%", "%n", "% n"}; - pFormat = [[numberFormatter positiveFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, false); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - default: - return -1; - } - - return value; -} - -int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, LocaleNumberData localeNumberData) -{ - @autoreleasepool - { -#ifndef NDEBUG - bool isSuccess = true; -#endif - int32_t value; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - - switch (localeNumberData) - { - case LocaleNumber_MeasurementSystem: - { - const char *measurementSystem = [[currentLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; - NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; - const char *us_measurementSystem = [[usLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; - value = (measurementSystem == us_measurementSystem) ? 1 : 0; - break; - } - case LocaleNumber_FractionalDigitsCount: - { - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - value = (int32_t)numberFormatter.maximumFractionDigits; - break; - } - case LocaleNumber_MonetaryFractionalDigitsCount: - { - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - value = (int32_t)numberFormatter.maximumFractionDigits; - break; - } - case LocaleNumber_PositiveMonetaryNumberFormat: - case LocaleNumber_NegativeMonetaryNumberFormat: - case LocaleNumber_NegativeNumberFormat: - case LocaleNumber_NegativePercentFormat: - case LocaleNumber_PositivePercentFormat: - { - value = GetValueForNumberFormat(currentLocale, localeNumberData); -#ifndef NDEBUG - if (value < 0) - { - isSuccess = false; - } -#endif - break; - } - case LocaleNumber_FirstWeekOfYear: - { - NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; - int minDaysInWeek = (int32_t)[calendar minimumDaysInFirstWeek]; - if (minDaysInWeek == 1) - { - value = WeekRule_FirstDay; - } - else if (minDaysInWeek == 7) - { - value = WeekRule_FirstFullWeek; - } - else if (minDaysInWeek >= 4) - { - value = WeekRule_FirstFourDayWeek; - } - else - { - value = -1; -#ifndef NDEBUG - isSuccess = false; -#endif - } - break; - } - case LocaleNumber_ReadingLayout: - { - NSLocaleLanguageDirection langDir = [NSLocale characterDirectionForLanguage:[currentLocale objectForKey:NSLocaleLanguageCode]]; - // 0 - Left to right (such as en-US) - // 1 - Right to left (such as arabic locales) - value = NSLocaleLanguageDirectionRightToLeft == langDir ? 1 : 0; - break; - } - case LocaleNumber_FirstDayofWeek: - { - NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; - value = [calendar firstWeekday] - 1; // .NET is 0-based and in Apple is 1-based; - break; - } - default: - value = -1; -#ifndef NDEBUG - isSuccess = false; -#endif - break; - } - - assert(isSuccess); - - return value; - } -} - -/* -PAL Function: -GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative - -Returns primary grouping size for decimal and currency -*/ -int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - - switch (localeGroupingData) - { - case LocaleNumber_Digit: - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - break; - case LocaleNumber_Monetary: - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - break; - default: - assert(false); - break; - } - return [numberFormatter groupingSize]; - } -} - -/* -PAL Function: -GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative - -Returns secondary grouping size for decimal and currency -*/ -int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - - switch (localeGroupingData) - { - case LocaleNumber_Digit: - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - break; - case LocaleNumber_Monetary: - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - break; - default: - assert(false); - break; - } - - return [numberFormatter secondaryGroupingSize]; - } -} - -/* -PAL Function: -GlobalizationNative_GetLocaleTimeFormatNative - -Returns time format information (in native format, it needs to be converted to .NET's format). -*/ -const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setLocale:currentLocale]; - - if (shortFormat != 0) - { - [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; - } - else - { - [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; - } - - return strdup([[dateFormatter dateFormat] UTF8String]); - } -} - -// GlobalizationNative_GetLocalesNative gets all locale names and store it in the value buffer -// in case of success, it returns the count of the characters stored in value buffer -// in case of failure, it returns negative number. -// if the input value buffer is null, it returns the length needed to store the -// locale names list. -// if the value is not null, it fills the value with locale names separated by the length -// of each name. -int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) -{ - @autoreleasepool - { - NSArray* availableLocaleIdentifiers = [NSLocale availableLocaleIdentifiers]; - int32_t index = 0; - int32_t totalLength = 0; - int32_t availableLength = (int32_t)[availableLocaleIdentifiers count]; - - if (availableLength <= 0) - return -1; // failed - - for (NSInteger i = 0; i < availableLength; i++) - { - NSString *localeIdentifier = availableLocaleIdentifiers[i]; - int32_t localeNameLength = localeIdentifier.length; - totalLength += localeNameLength + 1; // add 1 for the name length - if (value != NULL) - { - if (totalLength > length) - return -3; - - value[index++] = (UChar) localeNameLength; - - for (int j = 0; j < localeNameLength; j++) - { - if ((UChar)[localeIdentifier characterAtIndex:j] == '_') - { - value[index++] = (UChar) '-'; - } - else - { - value[index++] = (UChar) [localeIdentifier characterAtIndex:j]; - } - } - } - } - return totalLength; - } -} const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path) { @@ -785,56 +56,3 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) } } -const char* GlobalizationNative_GetDefaultLocaleNameNative(void) -{ - @autoreleasepool - { - if (NSLocale.preferredLanguages.count > 0) - { - return strdup([NSLocale.preferredLanguages[0] UTF8String]); - } - else - { - NSLocale *currentLocale = [NSLocale currentLocale]; - NSString *localeName = @""; - - if (!currentLocale) - { - return strdup([localeName UTF8String]); - } - - if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) - { - localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; - } - else - { - localeName = currentLocale.localeIdentifier; - } - - return strdup([localeName UTF8String]); - } - } -} - -// GlobalizationNative_IsPredefinedLocaleNative returns TRUE if localeName exists in availableLocaleIdentifiers. -// Otherwise it returns FALSE; - -int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName) -{ - @autoreleasepool - { - NSString *localeIdentifier = [NSString stringWithFormat:@"%s", localeName]; - NSString *localeIdentifierByRegionDesignator = [localeIdentifier stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; - NSArray *availableLocales = [NSLocale availableLocaleIdentifiers]; - - if ([availableLocales containsObject:localeIdentifier] || [availableLocales containsObject:localeIdentifierByRegionDesignator]) - { - return true; - } - - return false; - } -} -#endif - diff --git a/src/native/libs/System.Globalization.Native/pal_localeNumberData.h b/src/native/libs/System.Globalization.Native/pal_localeNumberData.h index f609c654e1292..1de613b1b6706 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeNumberData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeNumberData.h @@ -7,33 +7,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -// Enum that corresponds to managed enum CultureData.LocaleNumberData. -// The numeric values of the enum members match their Win32 counterparts. -typedef enum -{ - LocaleNumber_LanguageId = 0x01, - LocaleNumber_MeasurementSystem = 0x0D, - LocaleNumber_FractionalDigitsCount = 0x00000011, - LocaleNumber_NegativeNumberFormat = 0x00001010, - LocaleNumber_MonetaryFractionalDigitsCount = 0x00000019, - LocaleNumber_PositiveMonetaryNumberFormat = 0x0000001B, - LocaleNumber_NegativeMonetaryNumberFormat = 0x0000001C, - LocaleNumber_FirstDayofWeek = 0x0000100C, - LocaleNumber_FirstWeekOfYear = 0x0000100D, - LocaleNumber_ReadingLayout = 0x00000070, - LocaleNumber_NegativePercentFormat = 0x00000074, - LocaleNumber_PositivePercentFormat = 0x00000075, - LocaleNumber_Digit = 0x00000010, - LocaleNumber_Monetary = 0x00000018 -} LocaleNumberData; - -// Enum that corresponds to managed enum System.Globalization.CalendarWeekRule -typedef enum -{ - WeekRule_FirstDay = 0, - WeekRule_FirstFullWeek = 1, - WeekRule_FirstFourDayWeek = 2 -} CalendarWeekRule; PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName, LocaleNumberData localeNumberData, int32_t* value); @@ -42,13 +15,4 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* lo LocaleNumberData localeGroupingData, int32_t* primaryGroupSize, int32_t* secondaryGroupSize); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, - LocaleNumberData localeNumberData); - -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index 957021dffa697..3652254663ca8 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -7,48 +7,8 @@ #include "pal_locale.h" #include "pal_compiler.h" -// Enum that corresponds to managed enum CultureData.LocaleStringData. -// The numeric values of the enum members match their Win32 counterparts. -typedef enum -{ - LocaleString_LocalizedDisplayName = 0x02, - LocaleString_EnglishDisplayName = 0x00000072, - LocaleString_NativeDisplayName = 0x00000073, - LocaleString_LocalizedLanguageName = 0x0000006f, - LocaleString_EnglishLanguageName = 0x00001001, - LocaleString_NativeLanguageName = 0x04, - LocaleString_EnglishCountryName = 0x00001002, - LocaleString_NativeCountryName = 0x08, - LocaleString_DecimalSeparator = 0x0E, - LocaleString_ThousandSeparator = 0x0F, - LocaleString_Digits = 0x00000013, - LocaleString_MonetarySymbol = 0x00000014, - LocaleString_CurrencyEnglishName = 0x00001007, - LocaleString_CurrencyNativeName = 0x00001008, - LocaleString_Iso4217MonetarySymbol = 0x00000015, - LocaleString_MonetaryDecimalSeparator = 0x00000016, - LocaleString_MonetaryThousandSeparator = 0x00000017, - LocaleString_AMDesignator = 0x00000028, - LocaleString_PMDesignator = 0x00000029, - LocaleString_PositiveSign = 0x00000050, - LocaleString_NegativeSign = 0x00000051, - LocaleString_Iso639LanguageTwoLetterName = 0x00000059, - LocaleString_Iso639LanguageThreeLetterName = 0x00000067, - LocaleString_Iso3166CountryName = 0x0000005A, - LocaleString_Iso3166CountryName2= 0x00000068, - LocaleString_NaNSymbol = 0x00000069, - LocaleString_PositiveInfinitySymbol = 0x0000006a, - LocaleString_NegativeInfinitySymbol = 0x0000006b, - LocaleString_ParentName = 0x0000006d, - LocaleString_PercentSymbol = 0x00000076, - LocaleString_PerMilleSymbol = 0x00000077 -} LocaleStringData; PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); -#endif - diff --git a/src/native/libs/System.Globalization.Native/pal_locale_hg.h b/src/native/libs/System.Globalization.Native/pal_locale_hg.h new file mode 100644 index 0000000000000..da455dcd70c48 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_locale_hg.h @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_compiler.h" +#include "pal_hybrid.h" +#include "pal_common.h" + +PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, LocaleNumberData localeNumberData); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData); + +PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); + +PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); + +PALEXPORT const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat); + +PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t length); + +PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); + diff --git a/src/native/libs/System.Globalization.Native/pal_locale_hg.m b/src/native/libs/System.Globalization.Native/pal_locale_hg.m new file mode 100644 index 0000000000000..840c3392298df --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_locale_hg.m @@ -0,0 +1,797 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include +#include +#include "pal_hybrid.h" +#include "pal_locale_hg.h" +#include "pal_localeStringData.h" +#include "pal_localeNumberData.h" + +#import +#import + +#if !__has_feature(objc_arc) +#error This file relies on ARC for memory management, but ARC is not enabled. +#endif + +const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + const char* value = [currentLocale.localeIdentifier UTF8String]; + return strdup(value); + } +} + +/** + * Useful constant for the maximum size of the whole locale ID + * (including the terminating NULL and all keywords). + */ +#define FULLNAME_CAPACITY 157 + +static void GetParent(const char* localeID, char* parent, int32_t parentCapacity) +{ + const char *lastUnderscore; + int32_t i; + + if (localeID == NULL) + localeID = [NSLocale systemLocale].localeIdentifier.UTF8String; + + lastUnderscore = strrchr(localeID, '-'); + if (lastUnderscore != NULL) + { + i = (int32_t)(lastUnderscore - localeID); + } + else + { + i = 0; + } + + if (i > 0) + { + // primary lang subtag und (undefined). + if (strncasecmp(localeID, "und-", 4) == 0) + { + localeID += 3; + i -= 3; + memmove(parent, localeID, MIN(i, parentCapacity)); + } + else if (parent != localeID) + { + memcpy(parent, localeID, MIN(i, parentCapacity)); + } + } + + // terminate chars + if (i >= 0 && i < parentCapacity) + parent[i] = 0; +} + +/** + * Lookup 'key' in the array 'list'. The array 'list' should contain + * a NULL entry, followed by more entries, and a second NULL entry. + * + * The 'list' param should be LANGUAGES, LANGUAGES_3, COUNTRIES, or + * COUNTRIES_3. + */ +static int16_t _findIndex(const char* const* list, const char* key) +{ + const char* const* anchor = list; + int32_t pass = 0; + + /* Make two passes through two NULL-terminated arrays at 'list' */ + while (pass++ < 2) { + while (*list) { + if (strcmp(key, *list) == 0) { + return (int16_t)(list - anchor); + } + list++; + } + ++list; /* skip final NULL *CWB*/ + } + return -1; +} + +static const char* getISO3CountryByCountryCode(const char* countryCode) +{ + int16_t offset = _findIndex(COUNTRIES, countryCode); + if (offset < 0) + return ""; + + return COUNTRIES_3[offset]; +} + +static const char* getISO3LanguageByLangCode(const char* langCode) +{ + int16_t offset = _findIndex(LANGUAGES, langCode); + if (offset < 0) + return ""; + return LANGUAGES_3[offset]; +} + +const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName) +{ + @autoreleasepool + { + NSString *value; + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setLocale:currentLocale]; + NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; + + switch (localeStringData) + { + ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) + case LocaleString_LocalizedDisplayName: + { + NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; + NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; + value = [currentUILocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; + 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]; + break; + /// Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME) + case LocaleString_NativeDisplayName: + value = [currentLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; + break; + /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) + case LocaleString_LocalizedLanguageName: + { + NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; + NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; + value = [currentUILocale localizedStringForLanguageCode:currentLocale.languageCode]; + break; + } + /// English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME) + case LocaleString_EnglishLanguageName: + value = [gbLocale localizedStringForLanguageCode:currentLocale.languageCode]; + break; + /// native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME) + case LocaleString_NativeLanguageName: + value = [currentLocale localizedStringForLanguageCode:currentLocale.languageCode]; + break; + /// English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME) + case LocaleString_EnglishCountryName: + value = [gbLocale localizedStringForCountryCode:currentLocale.countryCode]; + break; + /// native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME) + case LocaleString_NativeCountryName: + value = [currentLocale localizedStringForCountryCode:currentLocale.countryCode]; + break; + case LocaleString_ThousandSeparator: + value = currentLocale.groupingSeparator; + break; + case LocaleString_DecimalSeparator: + value = currentLocale.decimalSeparator; + // or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String]; + break; + case LocaleString_Digits: + { + NSString *digitsString = @"0123456789"; + NSNumberFormatter *nf1 = [[NSNumberFormatter alloc] init]; + [nf1 setLocale:currentLocale]; + + NSNumber *newNum = [nf1 numberFromString:digitsString]; + value = [newNum stringValue]; + break; + } + case LocaleString_MonetarySymbol: + value = currentLocale.currencySymbol; + break; + case LocaleString_Iso4217MonetarySymbol: + // check if this is correct, check currencyISOCode + value = currentLocale.currencyCode; + break; + case LocaleString_CurrencyEnglishName: + value = [gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; + break; + case LocaleString_CurrencyNativeName: + value = [currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; + break; + case LocaleString_MonetaryDecimalSeparator: + value = numberFormatter.currencyDecimalSeparator; + break; + case LocaleString_MonetaryThousandSeparator: + value = numberFormatter.currencyGroupingSeparator; + break; + case LocaleString_AMDesignator: + value = dateFormatter.AMSymbol; + break; + case LocaleString_PMDesignator: + value = dateFormatter.PMSymbol; + break; + case LocaleString_PositiveSign: + value = numberFormatter.plusSign; + break; + case LocaleString_NegativeSign: + value = numberFormatter.minusSign; + break; + case LocaleString_Iso639LanguageTwoLetterName: + value = [currentLocale objectForKey:NSLocaleLanguageCode]; + break; + case LocaleString_Iso639LanguageThreeLetterName: + { + NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; + return iso639_2 == nil ? strdup("") : strdup(getISO3LanguageByLangCode([iso639_2 UTF8String])); + } + case LocaleString_Iso3166CountryName: + value = [currentLocale objectForKey:NSLocaleCountryCode]; + break; + case LocaleString_Iso3166CountryName2: + { + NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; + return countryCode == nil ? strdup("") : strdup(getISO3CountryByCountryCode([countryCode UTF8String])); + } + case LocaleString_NaNSymbol: + value = numberFormatter.notANumberSymbol; + break; + case LocaleString_PositiveInfinitySymbol: + value = numberFormatter.positiveInfinitySymbol; + break; + case LocaleString_NegativeInfinitySymbol: + value = numberFormatter.negativeInfinitySymbol; + break; + case LocaleString_PercentSymbol: + value = numberFormatter.percentSymbol; + break; + case LocaleString_PerMilleSymbol: + value = numberFormatter.perMillSymbol; + break; + case LocaleString_ParentName: + { + char localeNameTemp[FULLNAME_CAPACITY]; + const char* lName = [currentLocale.localeIdentifier UTF8String]; + GetParent(lName, localeNameTemp, FULLNAME_CAPACITY); + return strdup(localeNameTemp); + } + default: + value = nil; + break; + } + + return value == nil ? strdup("") : strdup([value UTF8String]); + } +} + +// invariant character definitions +#define CHAR_CURRENCY ((char)0x00A4) // international currency +#define CHAR_SPACE ((char)0x0020) // space +#define CHAR_NBSPACE ((char)0x00A0) // no-break space +#define CHAR_DIGIT ((char)0x0023) // '#' +#define CHAR_MINUS ((char)0x002D) // '-' +#define CHAR_PERCENT ((char)0x0025) // '%' +#define CHAR_OPENPAREN ((char)0x0028) // '(' +#define CHAR_CLOSEPAREN ((char)0x0029) // ')' +#define CHAR_ZERO ((char)0x0030) // '0' + +/* +Function: +NormalizeNumericPattern + +Returns a numeric string pattern in a format that we can match against the +appropriate managed pattern. Examples: +For PositiveMonetaryNumberFormat "¤#,##0.00" becomes "Cn" +For NegativeNumberFormat "#,##0.00;(#,##0.00)" becomes "(n)" +*/ +static char* NormalizeNumericPattern(const char* srcPattern, int isNegative) +{ + int iStart = 0; + int iEnd = strlen(srcPattern); + + // ';' separates positive and negative subpatterns. + // When there is no explicit negative subpattern, + // an implicit negative subpattern is formed from the positive pattern with a prefixed '-'. + char * ptrNegativePattern = strrchr(srcPattern,';'); + if (ptrNegativePattern) + { + int32_t iNegativePatternStart = ptrNegativePattern - srcPattern; + if (isNegative) + { + iStart = iNegativePatternStart + 1; + } + else + { + iEnd = iNegativePatternStart - 1; + } + } + + int minusAdded = false; + + for (int i = iStart; i <= iEnd; i++) + { + switch (srcPattern[i]) + { + case CHAR_MINUS: + case CHAR_OPENPAREN: + case CHAR_CLOSEPAREN: + minusAdded = true; + break; + } + + if (minusAdded) + break; + } + + // international currency symbol (CHAR_CURRENCY) + // The positive pattern comes first, then an optional negative pattern + // separated by a semicolon + // A destPattern example: "(C n)" where C represents the currency symbol, and + // n is the number + char* destPattern; + int index = 0; + + // if there is no negative subpattern, prefix the minus sign + if (isNegative && !minusAdded) + { + int length = (iEnd - iStart) + 2; + destPattern = (char*)calloc((size_t)length, sizeof(char)); + if (!destPattern) + { + return NULL; + } + destPattern[index++] = '-'; + } + else + { + int length = (iEnd - iStart) + 1; + destPattern = (char*)calloc((size_t)length, sizeof(char)); + if (!destPattern) + { + return NULL; + } + } + + int digitAdded = false; + int currencyAdded = false; + int spaceAdded = false; + + for (int i = iStart; i <= iEnd; i++) + { + char ch = srcPattern[i]; + switch (ch) + { + case CHAR_DIGIT: + case CHAR_ZERO: + if (!digitAdded) + { + digitAdded = true; + destPattern[index++] = 'n'; + } + break; + + case CHAR_CURRENCY: + if (!currencyAdded) + { + currencyAdded = true; + destPattern[index++] = 'C'; + } + break; + + case CHAR_SPACE: + case CHAR_NBSPACE: + if (!spaceAdded) + { + spaceAdded = true; + destPattern[index++] = ' '; + } + break; + + case CHAR_MINUS: + case CHAR_OPENPAREN: + case CHAR_CLOSEPAREN: + case CHAR_PERCENT: + destPattern[index++] = ch; + break; + } + } + + const int MAX_DOTNET_NUMERIC_PATTERN_LENGTH = 6; // example: "(C n)" plus terminator + + if (destPattern[0] == '\0' || strlen (destPattern) >= MAX_DOTNET_NUMERIC_PATTERN_LENGTH) + { + free (destPattern); + return NULL; + } + + return destPattern; +} + +/* +Function: +GetNumericPattern + +Determines the pattern from the decimalFormat and returns the matching pattern's +index from patterns[]. +Returns index -1 if no pattern is found. +*/ +static int GetPatternIndex(char* normalizedPattern,const char* patterns[], int patternsCount) +{ + const int INVALID_FORMAT = -1; + + if (!normalizedPattern) + { + return INVALID_FORMAT; + } + + for (int i = 0; i < patternsCount; i++) + { + if (strcmp(normalizedPattern, patterns[i]) == 0) + { + free(normalizedPattern); + return i; + } + } + + assert(false); // should have found a valid pattern + + free(normalizedPattern); + return INVALID_FORMAT; +} + +static int32_t GetValueForNumberFormat(NSLocale *currentLocale, LocaleNumberData localeNumberData) +{ + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + const char *pFormat; + int32_t value; + + switch(localeNumberData) + { + case LocaleNumber_PositiveMonetaryNumberFormat: + { + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + static const char* Patterns[] = {"Cn", "nC", "C n", "n C"}; + pFormat = [[numberFormatter positiveFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, false); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_NegativeMonetaryNumberFormat: + { + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + static const char* Patterns[] = {"(Cn)", "-Cn", "C-n", "Cn-", "(nC)", "-nC", "n-C", "nC-", "-n C", + "-C n", "n C-", "C n-", "C -n", "n- C", "(C n)", "(n C)", "C- n" }; + pFormat = [[numberFormatter negativeFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, true); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_NegativeNumberFormat: + { + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + static const char* Patterns[] = {"(n)", "-n", "- n", "n-", "n -"}; + pFormat = [[numberFormatter negativeFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, true); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_NegativePercentFormat: + { + numberFormatter.numberStyle = NSNumberFormatterPercentStyle; + static const char* Patterns[] = {"-n %", "-n%", "-%n", "%-n", "%n-", "n-%", "n%-", "-% n", "n %-", "% n-", "% -n", "n- %"}; + pFormat = [[numberFormatter negativeFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, true); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_PositivePercentFormat: + { + numberFormatter.numberStyle = NSNumberFormatterPercentStyle; + static const char* Patterns[] = {"n %", "n%", "%n", "% n"}; + pFormat = [[numberFormatter positiveFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, false); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + default: + return -1; + } + + return value; +} + +int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, LocaleNumberData localeNumberData) +{ + @autoreleasepool + { +#ifndef NDEBUG + bool isSuccess = true; +#endif + int32_t value; + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + + switch (localeNumberData) + { + case LocaleNumber_MeasurementSystem: + { + const char *measurementSystem = [[currentLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; + NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; + const char *us_measurementSystem = [[usLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; + value = (measurementSystem == us_measurementSystem) ? 1 : 0; + break; + } + case LocaleNumber_FractionalDigitsCount: + { + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + value = (int32_t)numberFormatter.maximumFractionDigits; + break; + } + case LocaleNumber_MonetaryFractionalDigitsCount: + { + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + value = (int32_t)numberFormatter.maximumFractionDigits; + break; + } + case LocaleNumber_PositiveMonetaryNumberFormat: + case LocaleNumber_NegativeMonetaryNumberFormat: + case LocaleNumber_NegativeNumberFormat: + case LocaleNumber_NegativePercentFormat: + case LocaleNumber_PositivePercentFormat: + { + value = GetValueForNumberFormat(currentLocale, localeNumberData); +#ifndef NDEBUG + if (value < 0) + { + isSuccess = false; + } +#endif + break; + } + case LocaleNumber_FirstWeekOfYear: + { + NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; + int minDaysInWeek = (int32_t)[calendar minimumDaysInFirstWeek]; + if (minDaysInWeek == 1) + { + value = WeekRule_FirstDay; + } + else if (minDaysInWeek == 7) + { + value = WeekRule_FirstFullWeek; + } + else if (minDaysInWeek >= 4) + { + value = WeekRule_FirstFourDayWeek; + } + else + { + value = -1; +#ifndef NDEBUG + isSuccess = false; +#endif + } + break; + } + case LocaleNumber_ReadingLayout: + { + NSLocaleLanguageDirection langDir = [NSLocale characterDirectionForLanguage:[currentLocale objectForKey:NSLocaleLanguageCode]]; + // 0 - Left to right (such as en-US) + // 1 - Right to left (such as arabic locales) + value = NSLocaleLanguageDirectionRightToLeft == langDir ? 1 : 0; + break; + } + case LocaleNumber_FirstDayofWeek: + { + NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; + value = [calendar firstWeekday] - 1; // .NET is 0-based and in Apple is 1-based; + break; + } + default: + value = -1; +#ifndef NDEBUG + isSuccess = false; +#endif + break; + } + + assert(isSuccess); + + return value; + } +} + +/* +PAL Function: +GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative + +Returns primary grouping size for decimal and currency +*/ +int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + + switch (localeGroupingData) + { + case LocaleNumber_Digit: + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + break; + case LocaleNumber_Monetary: + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + break; + default: + assert(false); + break; + } + return [numberFormatter groupingSize]; + } +} + +/* +PAL Function: +GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative + +Returns secondary grouping size for decimal and currency +*/ +int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + + switch (localeGroupingData) + { + case LocaleNumber_Digit: + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + break; + case LocaleNumber_Monetary: + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + break; + default: + assert(false); + break; + } + + return [numberFormatter secondaryGroupingSize]; + } +} + +/* +PAL Function: +GlobalizationNative_GetLocaleTimeFormatNative + +Returns time format information (in native format, it needs to be converted to .NET's format). +*/ +const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setLocale:currentLocale]; + + if (shortFormat != 0) + { + [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; + } + else + { + [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; + } + + return strdup([[dateFormatter dateFormat] UTF8String]); + } +} + +// GlobalizationNative_GetLocalesNative gets all locale names and store it in the value buffer +// in case of success, it returns the count of the characters stored in value buffer +// in case of failure, it returns negative number. +// if the input value buffer is null, it returns the length needed to store the +// locale names list. +// if the value is not null, it fills the value with locale names separated by the length +// of each name. +int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) +{ + @autoreleasepool + { + NSArray* availableLocaleIdentifiers = [NSLocale availableLocaleIdentifiers]; + int32_t index = 0; + int32_t totalLength = 0; + int32_t availableLength = (int32_t)[availableLocaleIdentifiers count]; + + if (availableLength <= 0) + return -1; // failed + + for (NSInteger i = 0; i < availableLength; i++) + { + NSString *localeIdentifier = availableLocaleIdentifiers[i]; + int32_t localeNameLength = localeIdentifier.length; + totalLength += localeNameLength + 1; // add 1 for the name length + if (value != NULL) + { + if (totalLength > length) + return -3; + + value[index++] = (UChar) localeNameLength; + + for (int j = 0; j < localeNameLength; j++) + { + if ((UChar)[localeIdentifier characterAtIndex:j] == '_') + { + value[index++] = (UChar) '-'; + } + else + { + value[index++] = (UChar) [localeIdentifier characterAtIndex:j]; + } + } + } + } + return totalLength; + } +} + +const char* GlobalizationNative_GetDefaultLocaleNameNative(void) +{ + @autoreleasepool + { + if (NSLocale.preferredLanguages.count > 0) + { + return strdup([NSLocale.preferredLanguages[0] UTF8String]); + } + else + { + NSLocale *currentLocale = [NSLocale currentLocale]; + NSString *localeName = @""; + + if (!currentLocale) + { + return strdup([localeName UTF8String]); + } + + if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) + { + localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; + } + else + { + localeName = currentLocale.localeIdentifier; + } + + return strdup([localeName UTF8String]); + } + } +} + +// GlobalizationNative_IsPredefinedLocaleNative returns TRUE if localeName exists in availableLocaleIdentifiers. +// Otherwise it returns FALSE; + +int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName) +{ + @autoreleasepool + { + NSString *localeIdentifier = [NSString stringWithFormat:@"%s", localeName]; + NSString *localeIdentifierByRegionDesignator = [localeIdentifier stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; + NSArray *availableLocales = [NSLocale availableLocaleIdentifiers]; + + if ([availableLocales containsObject:localeIdentifier] || [availableLocales containsObject:localeIdentifierByRegionDesignator]) + { + return true; + } + + return false; + } +} + 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 c754554bbfdd5..ddc0031a3ea19 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_common.h" /* Function: diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.c b/src/native/libs/System.Globalization.Native/pal_normalization.c index f421e39809bd8..d5a5078139f9e 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.c +++ b/src/native/libs/System.Globalization.Native/pal_normalization.c @@ -6,6 +6,7 @@ #include #include "pal_icushim_internal.h" +#include "pal_common.h" #include "pal_normalization.h" static const UNormalizer2* GetNormalizerForForm(NormalizationForm normalizationForm, UErrorCode* pErrorCode) diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.h b/src/native/libs/System.Globalization.Native/pal_normalization.h index a05ac2005543e..fbaa1e7334297 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.h +++ b/src/native/libs/System.Globalization.Native/pal_normalization.h @@ -7,16 +7,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -/* - * These values should be kept in sync with System.Text.NormalizationForm - */ -typedef enum -{ - FormC = 0x1, - FormD = 0x2, - FormKC = 0x5, - FormKD = 0x6 -} NormalizationForm; PALEXPORT int32_t GlobalizationNative_IsNormalized(NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength); @@ -26,14 +16,4 @@ PALEXPORT int32_t GlobalizationNative_NormalizeString(NormalizationForm normaliz int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm, - const uint16_t* lpStr, - int32_t cwStrLength); -PALEXPORT int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizationForm, - const uint16_t* lpSource, - int32_t cwSourceLength, - uint16_t* lpDst, - int32_t cwDstLength); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.m b/src/native/libs/System.Globalization.Native/pal_normalization.m index c029a16328bb2..efb436128bc85 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.m +++ b/src/native/libs/System.Globalization.Native/pal_normalization.m @@ -3,15 +3,14 @@ // #include "pal_errors.h" -#include "pal_icushim_internal.h" -#include "pal_normalization.h" +#include "pal_hybrid.h" +#include "pal_normalization_hg.h" #import #if !__has_feature(objc_arc) #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) static NSString* GetNormalizedStringForForm(NormalizationForm normalizationForm, NSString* sourceString) { switch (normalizationForm) @@ -87,5 +86,5 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio return !isError ? [normalizedString length] : 0; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_normalization_hg.h b/src/native/libs/System.Globalization.Native/pal_normalization_hg.h new file mode 100644 index 0000000000000..7eef447a769f1 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_normalization_hg.h @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_compiler.h" +#include "pal_locale_hg.h" + +PALEXPORT int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm, + const uint16_t* lpStr, + int32_t cwStrLength); + +PALEXPORT int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizationForm, + const uint16_t* lpSource, + int32_t cwSourceLength, + uint16_t* lpDst, + int32_t cwDstLength); + diff --git a/src/native/libs/System.Globalization.Native/pal_placeholders.c b/src/native/libs/System.Globalization.Native/pal_placeholders.c deleted file mode 100644 index 7d0f9624e082b..0000000000000 --- a/src/native/libs/System.Globalization.Native/pal_placeholders.c +++ /dev/null @@ -1,276 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include -#include - -#include "pal_icushim_internal.h" -#include "pal_icushim.h" -#include "pal_calendarData.h" -#include "pal_casing.h" -#include "pal_collation.h" -#include "pal_locale.h" -#include "pal_localeNumberData.h" -#include "pal_localeStringData.h" -#include "pal_normalization.h" -#include "pal_timeZoneInfo.h" - -#ifdef DEBUG -#define assert_err(cond, msg, err) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s. %s (%s failed)\n", __FILE__, __LINE__, err, msg, strerror(err), #cond); \ - assert(false && "assert_err failed"); \ - } \ -} while(0) -#define assert_msg(cond, msg, val) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s (%s failed)\n", __FILE__, __LINE__, val, msg, #cond); \ - assert(false && "assert_msg failed"); \ - } \ -} while(0) -#else // DEBUG -#define assert_err(cond, msg, err) -#define assert_msg(cond, msg, val) -#endif // DEBUG - - -// Placeholder for calendar data -int32_t GlobalizationNative_GetCalendars( - const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -ResultCode GlobalizationNative_GetCalendarInfo( - const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, UChar* result, int32_t resultCapacity) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -int32_t GlobalizationNative_EnumCalendarInfo( - EnumCalendarInfoCallback callback, const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, const void* context) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLatestJapaneseEra(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetJapaneseEraStartDate( - int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for casing data -void GlobalizationNative_ChangeCase( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -void GlobalizationNative_ChangeCaseInvariant( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -void GlobalizationNative_ChangeCaseTurkish( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -// Placeholder for collation data -ResultCode GlobalizationNative_GetSortHandle( - const char* lpLocaleName, SortHandle** pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_CompareString( - SortHandle* pSortHandle, const UChar* lpStr1, int32_t cwStr1Length, const UChar* lpStr2, int32_t cwStr2Length, int32_t options) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_IndexOf( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_LastIndexOf( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_StartsWith( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_EndsWith( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetSortKey( - SortHandle* pSortHandle, const UChar* lpStr, int32_t cwStrLength, uint8_t* sortKey, int32_t cbSortKeyLength, int32_t options) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale data -int32_t GlobalizationNative_GetLocales( - UChar *value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleName( - const UChar* localeName, UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetDefaultLocaleName( - UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_IsPredefinedLocale( - const UChar* localeName) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleTimeFormat( - const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale number data -int32_t GlobalizationNative_GetLocaleInfoInt( - const UChar* localeName, LocaleNumberData localeNumberData, int32_t* value) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleInfoGroupingSizes( - const UChar* localeName, LocaleNumberData localeGroupingData, int32_t* primaryGroupSize, int32_t* secondaryGroupSize) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for icu shim data -int32_t GlobalizationNative_LoadICU(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -void GlobalizationNative_InitICUFunctions( - void* icuuc, void* icuin, const char* version, const char* suffix) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -int32_t GlobalizationNative_GetICUVersion(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t -GlobalizationNative_LoadICUData(const char* path) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale string data -int32_t GlobalizationNative_GetLocaleInfoString( - const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -//Placeholder for normalization data -int32_t GlobalizationNative_IsNormalized( - NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_NormalizeString( - NormalizationForm normalizationForm, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for time zone data -int32_t GlobalizationNative_WindowsIdToIanaId( - const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -ResultCode GlobalizationNative_GetTimeZoneDisplayName( - const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -int32_t GlobalizationNative_IanaIdToWindowsId( - const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h index bb32c41d43db9..79fd3c0b5487a 100644 --- a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h @@ -8,22 +8,6 @@ #include "pal_compiler.h" #include "pal_errors.h" -/* -These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. -*/ -typedef enum -{ - TimeZoneDisplayName_Generic = 0, - TimeZoneDisplayName_Standard = 1, - TimeZoneDisplayName_DaylightSavings = 2, - TimeZoneDisplayName_GenericLocation = 3, - TimeZoneDisplayName_ExemplarCity = 4, - TimeZoneDisplayName_TimeZoneName = 5, -} TimeZoneDisplayNameType; PALEXPORT int32_t GlobalizationNative_WindowsIdToIanaId(const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength); PALEXPORT int32_t GlobalizationNative_IanaIdToWindowsId(const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength); PALEXPORT ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* timeZoneId, int32_t timeZoneIdLength, - TimeZoneDisplayNameType type, uint16_t* result, int32_t resultLength); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m index e5404e5cb0d4c..78b2e20d2ac44 100644 --- a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m @@ -3,15 +3,14 @@ // #include "pal_errors_internal.h" -#include "pal_icushim_internal.h" -#include "pal_timeZoneInfo.h" +#include "pal_hybrid.h" +#include "pal_timeZoneInfo_hg.h" #import #if !__has_feature(objc_arc) #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) /* Gets the localized display name that is currently in effect for the specified time zone. */ @@ -82,4 +81,4 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN return resultCode; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h new file mode 100644 index 0000000000000..67d08a58a49ba --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_compiler.h" +#include "pal_errors.h" +#include "pal_locale_hg.h" + +PALEXPORT int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* timeZoneId, int32_t timeZoneIdLength, + TimeZoneDisplayNameType type, uint16_t* result, int32_t resultLength); + + diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index bbf272365a899..f0b394604a7a2 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -16,7 +16,7 @@ <_UsePThreads /> <_UsePThreads Condition="'$(MonoWasmBuildVariant)' == 'multithread'"> usepthreads - <_IcuDir Condition="'$(TargetsAppleMobile)' != 'true' and '$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native + <_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native <_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)" <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_UsePThreads) @@ -55,7 +55,7 @@ - <_IcuArtifacts Condition="'$(_IcuDir)' != '' and '$(TargetsAppleMobile)' != 'true'" + <_IcuArtifacts Condition="'$(_IcuDir)' != ''" Include="$(_IcuDir)/lib/libicuuc.a; $(_IcuDir)/lib/libicui18n.a; $(_IcuDir)/lib/libicudata.a; diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 0e16db616d62e..42972c0d9a61d 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -155,7 +155,7 @@ public string TargetOS /// /// Forces the runtime to use hybrid(icu files + native functions) mode /// - public bool HybridGlobalization { get; set; } + public bool HybridGlobalization { get; set; } = true; /// /// Forces the runtime to use the interpreter diff --git a/src/tasks/AppleAppBuilder/Templates/main-console.m b/src/tasks/AppleAppBuilder/Templates/main-console.m index bd3a9e78ca0e1..ffd703f32a6cd 100644 --- a/src/tasks/AppleAppBuilder/Templates/main-console.m +++ b/src/tasks/AppleAppBuilder/Templates/main-console.m @@ -81,6 +81,10 @@ - (void)viewDidLoad { #if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); #endif // INVARIANT_GLOBALIZATION + +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif // HYBRID_GLOBALIZATION char **managed_argv; int managed_argc = get_managed_args (&managed_argv); int ret_val = __managed__Main (managed_argc, managed_argv); diff --git a/src/tasks/AppleAppBuilder/Templates/main-simple.m b/src/tasks/AppleAppBuilder/Templates/main-simple.m index 36bf576d51397..cb689b50b04ba 100644 --- a/src/tasks/AppleAppBuilder/Templates/main-simple.m +++ b/src/tasks/AppleAppBuilder/Templates/main-simple.m @@ -57,6 +57,10 @@ - (void)viewDidLoad { #if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); #endif + +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif char **managed_argv; int managed_argc = get_managed_args (&managed_argv); int ret_val = __managed__Main (managed_argc, managed_argv); diff --git a/src/tasks/AppleAppBuilder/Templates/runtime.m b/src/tasks/AppleAppBuilder/Templates/runtime.m index 3d825f50f0079..925e8175fc73d 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime.m @@ -261,6 +261,10 @@ static bool is_pinvoke_override_library (const char* libraryName) 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 a9bf648f8129a..b4b5180ad4e80 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -405,6 +405,13 @@ public string GenerateCMake( continue; string libName = Path.GetFileNameWithoutExtension(lib); + if((libName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicudata", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicui18n", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicuuc", StringComparison.OrdinalIgnoreCase)) && hybridGlobalization) + continue; + else if (libName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) + continue; // libmono must always be statically linked, for other librarires we can use dylibs bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib"); @@ -469,7 +476,7 @@ public string GenerateCMake( defines.AppendLine("add_definitions(-DINVARIANT_GLOBALIZATION=1)"); } - if (hybridGlobalization) + if (hybridGlobalization && !invariantGlobalization) { defines.AppendLine("add_definitions(-DHYBRID_GLOBALIZATION=1)"); } @@ -532,14 +539,27 @@ public string GenerateCMake( foreach (string aFile in Directory.GetFiles(workspace, "*.a")) { string aFileName = Path.GetFileNameWithoutExtension(aFile); + if((aFileName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) || + aFileName.StartsWith("libicudata", StringComparison.OrdinalIgnoreCase) || + aFileName.StartsWith("libicui18n", StringComparison.OrdinalIgnoreCase) || + aFileName.StartsWith("libicuuc", StringComparison.OrdinalIgnoreCase)) && hybridGlobalization) + continue; + else if (aFileName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) + continue; pinvokeOverrides.AppendLine($" \"{aFileName}\","); // also register with or without "lib" prefix aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName; pinvokeOverrides.AppendLine($" \"{aFileName}\","); } - - pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); + if (hybridGlobalization) + { + pinvokeOverrides.AppendLine($" \"System.HybridGlobalization.Native\","); + } + else + { + pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); + } File.WriteAllText(Path.Combine(binDir, "runtime.m"), Utils.GetEmbeddedResource("runtime.m") diff --git a/src/tasks/LibraryBuilder/LibraryBuilder.cs b/src/tasks/LibraryBuilder/LibraryBuilder.cs index d96b5c4d316e8..f68f65c29ff74 100644 --- a/src/tasks/LibraryBuilder/LibraryBuilder.cs +++ b/src/tasks/LibraryBuilder/LibraryBuilder.cs @@ -200,13 +200,26 @@ private void GatherSourcesAndLibs(List sources, List libs, List< foreach (ITaskItem lib in RuntimeLibraries) { string ext = Path.GetExtension(lib.ItemSpec); + string libName = Path.GetFileNameWithoutExtension(lib.ItemSpec); if (ext == ".so" || ext == ".dylib") { + // temporary solution, include only HybridGlobalization from static linking , + // until we figure out how to link it properly depending on the hybrid globalization mode + if (libName.Contains("libSystem.Globalization.Native")) + { + continue; + } libs.Add(lib.ItemSpec); } else { + // temporary solution, include only HybridGlobalization from static linking , + // until we figure out how to link it properly depending on the hybrid globalization mode + if (libName.Contains("libSystem.Globalization.Native")) + { + continue; + } sources.Add(lib.ItemSpec); } } diff --git a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj index 7f33aa52c112d..62fbe6f9b2965 100644 --- a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj @@ -14,6 +14,7 @@ shared false true + true