diff options
Diffstat (limited to 'src/mscorlib/shared/Interop/Unix/System.Globalization.Native')
8 files changed, 237 insertions, 0 deletions
diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs new file mode 100644 index 0000000000..7b3caeabdd --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Globalization; +using System.Runtime.InteropServices; +using System.Text; + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + internal delegate void EnumCalendarInfoCallback( + [MarshalAs(UnmanagedType.LPWStr)] string calendarString, + IntPtr context); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")] + internal static extern int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")] + internal static extern ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, [Out] StringBuilder result, int resultCapacity); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] + internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); + + [DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")] + internal static extern int GetLatestJapaneseEra(); + + [DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")] + internal static extern bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay); + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs new file mode 100644 index 0000000000..769506b8f6 --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")] + internal unsafe static extern void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")] + internal unsafe static extern void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")] + internal unsafe static extern void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper); + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs new file mode 100644 index 0000000000..43c72281ae --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + internal const int AllowUnassigned = 0x1; + internal const int UseStd3AsciiRules = 0x2; + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")] + internal static unsafe extern int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")] + internal static unsafe extern int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs new file mode 100644 index 0000000000..fcea708ee8 --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Text; + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")] + [return: MarshalAs(UnmanagedType.Bool)] + internal unsafe static extern bool GetLocaleName(string localeName, [Out] StringBuilder value, int valueLength); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoString")] + [return: MarshalAs(UnmanagedType.Bool)] + internal unsafe static extern bool GetLocaleInfoString(string localeName, uint localeStringData, [Out] StringBuilder value, int valueLength); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetDefaultLocaleName")] + [return: MarshalAs(UnmanagedType.Bool)] + internal unsafe static extern bool GetDefaultLocaleName([Out] StringBuilder value, int valueLength); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat")] + [return: MarshalAs(UnmanagedType.Bool)] + internal unsafe static extern bool GetLocaleTimeFormat(string localeName, bool shortFormat, [Out] StringBuilder value, int valueLength); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoInt")] + [return: MarshalAs(UnmanagedType.Bool)] + internal unsafe static extern bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")] + [return: MarshalAs(UnmanagedType.Bool)] + internal unsafe static extern bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")] + internal unsafe static extern int GetLocales([Out] Char[] value, int valueLength); + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs new file mode 100644 index 0000000000..c4cb9fb851 --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs @@ -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. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Text; + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")] + internal static extern int IsNormalized(NormalizationForm normalizationForm, string src, int srcLen); + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_NormalizeString")] + internal static extern int NormalizeString(NormalizationForm normalizationForm, string src, int srcLen, [Out] char[] dstBuffer, int dstBufferCapacity); + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs new file mode 100644 index 0000000000..cca6ae4dcb --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + // needs to be kept in sync with ResultCode in System.Globalization.Native + internal enum ResultCode + { + Success = 0, + UnknownError = 1, + InsufficentBuffer = 2, + OutOfMemory = 3 + } + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs new file mode 100644 index 0000000000..26a9fe0579 --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.InteropServices; +using System.Text; + +internal static partial class Interop +{ + internal static partial class GlobalizationInterop + { + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Ansi, EntryPoint = "GlobalizationNative_ReadLink")] // readlink requires char* + internal static extern bool ReadLink(string filePath, [Out] StringBuilder result, uint resultCapacity); + + // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native + internal enum TimeZoneDisplayNameType + { + Generic = 0, + Standard = 1, + DaylightSavings = 2, + } + + [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayName")] + internal static extern ResultCode GetTimeZoneDisplayName( + string localeName, + string timeZoneId, + TimeZoneDisplayNameType type, + [Out] StringBuilder result, + int resultLength); + } +} diff --git a/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs new file mode 100644 index 0000000000..33b10c0d74 --- /dev/null +++ b/src/mscorlib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text; + +internal static partial class Interop +{ + /// <summary> + /// Helper for making interop calls that return a string, but we don't know + /// the correct size of buffer to make. So invoke the interop call with an + /// increasing buffer until the size is big enough. + /// </summary> + internal static bool CallStringMethod<TArg1, TArg2, TArg3>( + Func<TArg1, TArg2, TArg3, StringBuilder, GlobalizationInterop.ResultCode> interopCall, + TArg1 arg1, + TArg2 arg2, + TArg3 arg3, + out string result) + { + const int initialStringSize = 80; + const int maxDoubleAttempts = 5; + + StringBuilder stringBuilder = StringBuilderCache.Acquire(initialStringSize); + + for (int i = 0; i < maxDoubleAttempts; i++) + { + GlobalizationInterop.ResultCode resultCode = interopCall(arg1, arg2, arg3, stringBuilder); + + if (resultCode == GlobalizationInterop.ResultCode.Success) + { + result = StringBuilderCache.GetStringAndRelease(stringBuilder); + return true; + } + else if (resultCode == GlobalizationInterop.ResultCode.InsufficentBuffer) + { + // increase the string size and loop + stringBuilder.EnsureCapacity(stringBuilder.Capacity * 2); + } + else + { + // if there is an unknown error, don't proceed + break; + } + } + + StringBuilderCache.Release(stringBuilder); + result = null; + return false; + } +} |