Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
- fix some typos
- suppress some R# messages
- refactor a few minor details
  • Loading branch information
ermshiperete committed Apr 20, 2022
1 parent bb1a46e commit 546b055
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 138 deletions.
31 changes: 30 additions & 1 deletion source/icu.net.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Transliterator/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dlerror/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dlopen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=icui/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=icuin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=icuuc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=iscntrl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ispunct/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=isspace/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=libicuuc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=preallocated/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=strcoll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tolower/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=totitle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=toupper/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Transliterator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ubidi/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ubrk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ucal/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCHAR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ucnv/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ucol/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=uenum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=uloc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=umsg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unorm/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=uregex/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ures/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=uset/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=utrans/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
80 changes: 45 additions & 35 deletions source/icu.net/NativeMethods/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Copyright (c) 2013-2017 SIL International
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

// ReSharper disable once CheckNamespace
namespace Icu
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "IdentifierTypo")]
internal static partial class NativeMethods
{
private static readonly object _lock = new object();
Expand All @@ -21,7 +26,7 @@ internal static partial class NativeMethods

internal static bool Verbose { get; set; }

public static void SetMinMaxIcuVersions(int minVersion = Wrapper.MinSupportedIcuVersion,
internal static void SetMinMaxIcuVersions(int minVersion = Wrapper.MinSupportedIcuVersion,
int maxVersion = Wrapper.MaxSupportedIcuVersion)
{
Trace.WriteLineIf(Verbose, $"Setting min/max ICU versions to {minVersion} and {maxVersion}");
Expand Down Expand Up @@ -104,6 +109,7 @@ private static string dlerror()
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);

[Flags]
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private enum LoadLibraryFlags : uint
{
NONE = 0x00000000,
Expand Down Expand Up @@ -134,6 +140,7 @@ private static IntPtr IcuCommonLibHandle
get
{
if (_IcuCommonLibHandle == IntPtr.Zero)
// ReSharper disable once StringLiteralTypo
_IcuCommonLibHandle = LoadIcuLibrary("icuuc");
return _IcuCommonLibHandle;
}
Expand Down Expand Up @@ -298,7 +305,7 @@ private static IntPtr GetIcuLibHandle(string basename, int icuVersion)

IntPtr handle;
string libPath;
var lastError = 0;
int lastError;

if (IsWindows)
{
Expand Down Expand Up @@ -337,7 +344,7 @@ private static IntPtr GetIcuLibHandle(string basename, int icuVersion)
}
}

public static void Cleanup()
internal static void Cleanup()
{
Trace.WriteLineIf(Verbose, "icu.net: Cleanup");
lock (_lock)
Expand Down Expand Up @@ -438,13 +445,13 @@ private static T GetMethod<T>(IntPtr handle, string methodName, bool missingInMi

#endregion

public static string GetAnsiString(Func<IntPtr, int, Tuple<ErrorCode, int>> lambda,
internal static string GetAnsiString(Func<IntPtr, int, Tuple<ErrorCode, int>> lambda,
int initialLength = 255)
{
return GetString(lambda, false, initialLength);
}

public static string GetUnicodeString(Func<IntPtr, int, Tuple<ErrorCode, int>> lambda,
internal static string GetUnicodeString(Func<IntPtr, int, Tuple<ErrorCode, int>> lambda,
int initialLength = 255)
{
return GetString(lambda, true, initialLength);
Expand Down Expand Up @@ -492,7 +499,7 @@ private static string GetString(Func<IntPtr, int, Tuple<ErrorCode, int>> lambda,
/// This function does cleanup of the enumerator object
/// </summary>
/// <param name="en">Enumeration to be closed</param>
public static void uenum_close(IntPtr en)
internal static void uenum_close(IntPtr en)
{
if (Methods.uenum_close == null)
Methods.uenum_close = GetMethod<MethodsContainer.uenum_closeDelegate>(IcuCommonLibHandle, "uenum_close");
Expand All @@ -505,7 +512,7 @@ public static void uenum_close(IntPtr en)
/// </summary>
/// <returns>next element as string, or <c>null</c> after all elements haven been
/// enumerated</returns>
public static IntPtr uenum_unext(
internal static IntPtr uenum_unext(
SafeEnumeratorHandle en,
out int resultLength,
out ErrorCode status)
Expand All @@ -515,7 +522,7 @@ public static IntPtr uenum_unext(
return Methods.uenum_unext(en, out resultLength, out status);
}

public enum LocaleType
internal enum LocaleType
{
/// <summary>
/// This is locale the data actually comes from
Expand All @@ -527,7 +534,7 @@ public enum LocaleType
ValidLocale = 1,
}

public enum CollationAttributeValue
internal enum CollationAttributeValue
{
Default = -1, //accepted by most attributes
Primary = 0, // primary collation strength
Expand All @@ -547,7 +554,7 @@ public enum CollationAttributeValue
UpperFirst = 25 // Valid for CaseFirst - upper case sorts before lower case
}

public enum CollationAttribute
internal enum CollationAttribute
{
FrenchCollation,
AlternateHandling,
Expand All @@ -561,13 +568,14 @@ public enum CollationAttribute
AttributeCount
}

public enum CollationResult
internal enum CollationResult
{
Equal = 0,
Greater = 1,
Less = -1
}

[SuppressMessage("ReSharper", "MemberHidesStaticFromOuterClass")]
private class MethodsContainer
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
Expand Down Expand Up @@ -699,7 +707,7 @@ internal delegate int u_strToUpperDelegate(IntPtr dest, int destCapacity, string
}

/// <summary>get the name of an ICU code point</summary>
public static void u_init(out ErrorCode errorCode)
internal static void u_init(out ErrorCode errorCode)
{
IsInitialized = true;
if (Methods.u_init == null)
Expand All @@ -708,7 +716,8 @@ public static void u_init(out ErrorCode errorCode)
}

/// <summary>Clean up the ICU files that could be locked</summary>
public static void u_cleanup()
// ReSharper disable once MemberCanBePrivate.Global
internal static void u_cleanup()
{
if (Methods.u_cleanup == null)
Methods.u_cleanup = GetMethod<MethodsContainer.u_cleanupDelegate>(IcuCommonLibHandle, "u_cleanup");
Expand All @@ -717,15 +726,15 @@ public static void u_cleanup()
}

/// <summary>Return the ICU data directory</summary>
public static IntPtr u_getDataDirectory()
internal static IntPtr u_getDataDirectory()
{
if (Methods.u_getDataDirectory == null)
Methods.u_getDataDirectory = GetMethod<MethodsContainer.u_getDataDirectoryDelegate>(IcuCommonLibHandle, "u_getDataDirectory");
return Methods.u_getDataDirectory();
}

/// <summary>Set the ICU data directory</summary>
public static void u_setDataDirectory(
internal static void u_setDataDirectory(
[MarshalAs(UnmanagedType.LPStr)]string directory)
{
if (Methods.u_setDataDirectory == null)
Expand All @@ -734,7 +743,7 @@ public static void u_setDataDirectory(
}

/// <summary>get the name of an ICU code point</summary>
public static int u_charName(
internal static int u_charName(
int code,
Character.UCharNameChoice nameChoice,
IntPtr buffer,
Expand All @@ -747,7 +756,7 @@ public static int u_charName(
}

/// <summary>Returns the bidirectional category value for the code point, which is used in the Unicode bidirectional algorithm</summary>
public static int u_charDirection(int characterCode)
internal static int u_charDirection(int characterCode)
{
if (Methods.u_charDirection == null)
Methods.u_charDirection = GetMethod<MethodsContainer.u_charDirectionDelegate>(IcuCommonLibHandle, "u_charDirection");
Expand All @@ -759,7 +768,7 @@ public static int u_charDirection(int characterCode)
/// get the numeric value for the Unicode digit
/// </summary>
/// ------------------------------------------------------------------------------------
public static int u_digit(
internal static int u_digit(
int characterCode,
byte radix)
{
Expand All @@ -783,7 +792,7 @@ public static int u_digit(
/// </returns>
/// <remarks>Consider adding a specific implementation for each property!</remarks>
/// ------------------------------------------------------------------------------------
public static int u_getIntPropertyValue(
internal static int u_getIntPropertyValue(
int codePoint,
Character.UProperty which)
{
Expand All @@ -792,7 +801,7 @@ public static int u_getIntPropertyValue(
return Methods.u_getIntPropertyValue(codePoint, which);
}

public static void u_getUnicodeVersion(out VersionInfo versionArray)
internal static void u_getUnicodeVersion(out VersionInfo versionArray)
{
if (Methods.u_getUnicodeVersion == null)
Methods.u_getUnicodeVersion = GetMethod<MethodsContainer.u_getUnicodeVersionDelegate>(IcuCommonLibHandle, "u_getUnicodeVersion");
Expand All @@ -805,7 +814,7 @@ public static void u_getUnicodeVersion(out VersionInfo versionArray)
/// </summary>
/// <param name="versionArray">Stores the version information for ICU.</param>
/// ------------------------------------------------------------------------------------
public static void u_getVersion(out VersionInfo versionArray)
internal static void u_getVersion(out VersionInfo versionArray)
{
if (Methods.u_getVersion == null)
Methods.u_getVersion = GetMethod<MethodsContainer.u_getVersionDelegate>(IcuCommonLibHandle, "u_getVersion");
Expand All @@ -817,7 +826,7 @@ public static void u_getVersion(out VersionInfo versionArray)
/// </summary>
/// <param name="characterCode"></param>
/// <returns></returns>
public static sbyte u_charType(int characterCode)
internal static sbyte u_charType(int characterCode)
{
if (Methods.u_charType == null)
Methods.u_charType = GetMethod<MethodsContainer.u_charTypeDelegate>(IcuCommonLibHandle, "u_charType");
Expand All @@ -844,7 +853,7 @@ public static sbyte u_charType(int characterCode)
///<param name="characterCode">Code point to get the numeric value for</param>
///<returns>Numeric value of c, or U_NO_NUMERIC_VALUE if none is defined.</returns>
/// ------------------------------------------------------------------------------------
public static double u_getNumericValue(
internal static double u_getNumericValue(
int characterCode)
{
if (Methods.u_getNumericValue == null)
Expand All @@ -858,7 +867,7 @@ public static double u_getNumericValue(
/// </summary>
/// <param name="characterCode">the code point to be tested</param>
/// ------------------------------------------------------------------------------------
public static bool u_ispunct(
internal static bool u_ispunct(
int characterCode)
{
if (Methods.u_ispunct == null)
Expand All @@ -885,7 +894,7 @@ public static bool u_ispunct(
/// <param name="characterCode">the code point to be tested</param>
/// <returns><c>true</c> if the character has the Bidi_Mirrored property</returns>
/// ------------------------------------------------------------------------------------
public static bool u_isMirrored(
internal static bool u_isMirrored(
int characterCode)
{
if (Methods.u_isMirrored == null)
Expand All @@ -907,7 +916,7 @@ public static bool u_isMirrored(
/// </summary>
/// <param name="characterCode">the code point to be tested</param>
/// ------------------------------------------------------------------------------------
public static bool u_iscntrl(
internal static bool u_iscntrl(
int characterCode)
{
if (Methods.u_iscntrl == null)
Expand All @@ -932,7 +941,7 @@ public static bool u_iscntrl(
/// </remarks>
/// <param name="characterCode">the code point to be tested</param>
/// ------------------------------------------------------------------------------------
public static bool u_isspace(
internal static bool u_isspace(
int characterCode)
{
if (Methods.u_isspace == null)
Expand All @@ -941,39 +950,39 @@ public static bool u_isspace(
}

/// <summary>Map character to its lowercase equivalent according to UnicodeData.txt</summary>
public static int u_tolower(int characterCode)
internal static int u_tolower(int characterCode)
{
if (Methods.u_tolower == null)
Methods.u_tolower = GetMethod<MethodsContainer.u_tolowerDelegate>(IcuCommonLibHandle, "u_tolower");
return Methods.u_tolower(characterCode);
}

/// <summary>Map character to its titlecase equivalent according to UnicodeData.txt</summary>
public static int u_totitle(int characterCode)
/// <summary>Map character to its title-case equivalent according to UnicodeData.txt</summary>
internal static int u_totitle(int characterCode)
{
if (Methods.u_totitle == null)
Methods.u_totitle = GetMethod<MethodsContainer.u_totitleDelegate>(IcuCommonLibHandle, "u_totitle");
return Methods.u_totitle(characterCode);
}

/// <summary>Map character to its uppercase equivalent according to UnicodeData.txt</summary>
public static int u_toupper(int characterCode)
internal static int u_toupper(int characterCode)
{
if (Methods.u_toupper == null)
Methods.u_toupper = GetMethod<MethodsContainer.u_toupperDelegate>(IcuCommonLibHandle, "u_toupper");
return Methods.u_toupper(characterCode);
}

/// <summary>Return the lower case equivalent of the string.</summary>
public static int u_strToLower(IntPtr dest, int destCapacity, string src,
internal static int u_strToLower(IntPtr dest, int destCapacity, string src,
int srcLength, [MarshalAs(UnmanagedType.LPStr)] string locale, out ErrorCode errorCode)
{
if (Methods.u_strToLower == null)
Methods.u_strToLower = GetMethod<MethodsContainer.u_strToLowerDelegate>(IcuCommonLibHandle, "u_strToLower");
return Methods.u_strToLower(dest, destCapacity, src, srcLength, locale, out errorCode);
}

public static int u_strToTitle(IntPtr dest, int destCapacity, string src,
internal static int u_strToTitle(IntPtr dest, int destCapacity, string src,
int srcLength, [MarshalAs(UnmanagedType.LPStr)] string locale,
out ErrorCode errorCode)
{
Expand All @@ -982,7 +991,8 @@ public static int u_strToTitle(IntPtr dest, int destCapacity, string src,
}

/// <summary>Return the title case equivalent of the string.</summary>
public static int u_strToTitle(IntPtr dest, int destCapacity, string src,
// ReSharper disable once MemberCanBePrivate.Global
internal static int u_strToTitle(IntPtr dest, int destCapacity, string src,
int srcLength, IntPtr titleIter, [MarshalAs(UnmanagedType.LPStr)] string locale,
out ErrorCode errorCode)
{
Expand All @@ -993,7 +1003,7 @@ public static int u_strToTitle(IntPtr dest, int destCapacity, string src,
}

/// <summary>Return the upper case equivalent of the string.</summary>
public static int u_strToUpper(IntPtr dest, int destCapacity, string src,
internal static int u_strToUpper(IntPtr dest, int destCapacity, string src,
int srcLength, [MarshalAs(UnmanagedType.LPStr)] string locale, out ErrorCode errorCode)
{
if (Methods.u_strToUpper == null)
Expand Down
Loading

0 comments on commit 546b055

Please sign in to comment.