From 751e84fc6d0d66412ada1cc1086c2070afb7bca3 Mon Sep 17 00:00:00 2001 From: GoldenCrystal Date: Thu, 7 Sep 2017 23:10:17 +0200 Subject: [PATCH] Add DebuggerDisplay attributes. Format some code to C# 7.0. Remove useless using directives. --- .gitignore | 3 +- UnicodeInformation.Builder/EnumHelper.cs | 33 ++++++++++ UnicodeInformation/BidirectionalClass.cs | 7 +-- UnicodeInformation/CjkRadicalInfo.cs | 7 +-- UnicodeInformation/CodePointEnumerable.cs | 32 ++-------- UnicodeInformation/CodePointEnumerator.cs | 10 +-- .../CompatibilityFormattingTag.cs | 7 +-- UnicodeInformation/ContributoryProperties.cs | 7 +-- UnicodeInformation/CoreProperties.cs | 7 +-- UnicodeInformation/EnumHelper.cs | 32 +++++----- UnicodeInformation/HangulInfo.cs | 8 +-- .../PermissiveCodePointEnumerable.cs | 32 ++-------- .../PermissiveCodePointEnumerator.cs | 8 +-- UnicodeInformation/StringExtensions.cs | 8 +-- UnicodeInformation/UcdFields.cs | 8 +-- UnicodeInformation/UnicodeBlock.cs | 11 ++-- .../UnicodeCategoryExtensions.cs | 7 +-- UnicodeInformation/UnicodeCategoryInfo.cs | 62 +++++-------------- UnicodeInformation/UnicodeCharInfo.cs | 7 +-- UnicodeInformation/UnicodeCodePointRange.cs | 6 +- UnicodeInformation/UnicodeInfo.cs | 23 +++---- UnicodeInformation/UnicodeNameAlias.cs | 8 ++- .../UnicodeNameAliasCollection.cs | 6 +- UnicodeInformation/UnicodeNumericType.cs | 8 +-- .../UnicodeRadicalStrokeCount.cs | 39 +++++------- .../UnicodeRadicalStrokeCountCollection.cs | 6 +- UnicodeInformation/UnicodeRationalNumber.cs | 8 +-- UnicodeInformation/UnihanFields.cs | 8 +-- UnicodeInformation/UnihanNumericType.cs | 8 +-- UnicodeInformation/ValueNameAttribute.cs | 8 +-- 30 files changed, 144 insertions(+), 280 deletions(-) create mode 100644 UnicodeInformation.Builder/EnumHelper.cs diff --git a/.gitignore b/.gitignore index 7964536..725c238 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ bld/ # Roslyn cache directories *.ide/ +.vs/ # MSTest test Results [Tt]est[Rr]esult*/ @@ -186,4 +187,4 @@ FakesAssemblies/ # LightSwitch generated files GeneratedArtifacts/ _Pvt_Extensions/ -ModelManifest.xml \ No newline at end of file +ModelManifest.xml diff --git a/UnicodeInformation.Builder/EnumHelper.cs b/UnicodeInformation.Builder/EnumHelper.cs new file mode 100644 index 0000000..add87e1 --- /dev/null +++ b/UnicodeInformation.Builder/EnumHelper.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace System.Unicode.Builder +{ + internal static class EnumHelper + where T : struct + { + private static readonly Dictionary namedValueDictionary = CreateNamedValueDictionary(); + + private static Dictionary CreateNamedValueDictionary() + { + var type = typeof(T).GetTypeInfo(); + + if (!type.IsEnum) throw new InvalidOperationException(); + + return + ( + from field in type.DeclaredFields + where field.IsPublic && field.IsLiteral + from attr in field.GetCustomAttributes() + where attr.Name != null + select new KeyValuePair(attr.Name, (T)field.GetValue(null)) + ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase); + } + + public static bool TryGetNamedValue(string name, out T value) + { + return namedValueDictionary.TryGetValue(name, out value); + } + } +} diff --git a/UnicodeInformation/BidirectionalClass.cs b/UnicodeInformation/BidirectionalClass.cs index 8e8f716..244e0be 100644 --- a/UnicodeInformation/BidirectionalClass.cs +++ b/UnicodeInformation/BidirectionalClass.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; namespace System.Unicode { diff --git a/UnicodeInformation/CjkRadicalInfo.cs b/UnicodeInformation/CjkRadicalInfo.cs index f64a3ae..d752f13 100644 --- a/UnicodeInformation/CjkRadicalInfo.cs +++ b/UnicodeInformation/CjkRadicalInfo.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics; namespace System.Unicode { /// Provides information on a specific CJK radical. + [DebuggerDisplay("{RadicalIndex} - {TraditionalRadicalCodePoint.ToString(),nq} / {SimplifiedRadicalCodePoint.ToString(),nq}")] public struct CjkRadicalInfo { private readonly byte radicalIndex; diff --git a/UnicodeInformation/CodePointEnumerable.cs b/UnicodeInformation/CodePointEnumerable.cs index 34a3aaa..b08093e 100644 --- a/UnicodeInformation/CodePointEnumerable.cs +++ b/UnicodeInformation/CodePointEnumerable.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { @@ -14,34 +10,18 @@ namespace System.Unicode /// public struct CodePointEnumerable : IEnumerable { - private readonly string text; - /// Initializes a new instance of the struct . /// The string whose code points must be enumerated. - public CodePointEnumerable(string text) - { - if (text == null) throw new ArgumentNullException(nameof(text)); - - this.text = text; - } + public CodePointEnumerable(string text) => Text = text ?? throw new ArgumentNullException(nameof(text)); /// Gets the text whose code points are being enumerated. - public string Text { get { return text; } } + public string Text { get; } /// Gets an enumerator which can be used to enumerate the code points in the text. - public CodePointEnumerator GetEnumerator() - { - return new CodePointEnumerator(text); - } + public CodePointEnumerator GetEnumerator() => new CodePointEnumerator(Text); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/UnicodeInformation/CodePointEnumerator.cs b/UnicodeInformation/CodePointEnumerator.cs index 58d6a02..ae87abe 100644 --- a/UnicodeInformation/CodePointEnumerator.cs +++ b/UnicodeInformation/CodePointEnumerator.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { @@ -28,9 +24,9 @@ namespace System.Unicode /// Gets the element in the collection at the current position of the enumerator.. /// The element in the collection at the current position of the enumerator. - public int Current { get { return current; } } + public int Current => current; - object IEnumerator.Current { get { return current; } } + object IEnumerator.Current => current; void IDisposable.Dispose() { } diff --git a/UnicodeInformation/CompatibilityFormattingTag.cs b/UnicodeInformation/CompatibilityFormattingTag.cs index 045bf87..c015af7 100644 --- a/UnicodeInformation/CompatibilityFormattingTag.cs +++ b/UnicodeInformation/CompatibilityFormattingTag.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; namespace System.Unicode { diff --git a/UnicodeInformation/ContributoryProperties.cs b/UnicodeInformation/ContributoryProperties.cs index 7947a2a..4793bc1 100644 --- a/UnicodeInformation/ContributoryProperties.cs +++ b/UnicodeInformation/ContributoryProperties.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; namespace System.Unicode { diff --git a/UnicodeInformation/CoreProperties.cs b/UnicodeInformation/CoreProperties.cs index e2c2e36..27ea665 100644 --- a/UnicodeInformation/CoreProperties.cs +++ b/UnicodeInformation/CoreProperties.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; namespace System.Unicode { diff --git a/UnicodeInformation/EnumHelper.cs b/UnicodeInformation/EnumHelper.cs index 595f0be..b54cd34 100644 --- a/UnicodeInformation/EnumHelper.cs +++ b/UnicodeInformation/EnumHelper.cs @@ -1,19 +1,15 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { - internal sealed class EnumHelper + internal static class EnumHelper where T : struct { - private static readonly Dictionary namedValueDictionary = CreateNamedValueDictionary(); + private static readonly Dictionary valueNameDictionary = CreateValueNameDictionary(); - private static Dictionary CreateNamedValueDictionary() + private static Dictionary CreateValueNameDictionary() { var type = typeof(T).GetTypeInfo(); @@ -22,15 +18,19 @@ namespace System.Unicode return ( from field in type.DeclaredFields - from attr in field.GetCustomAttributes() - where attr.Name != null - select new KeyValuePair(attr.Name, (T)field.GetValue(null)) - ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase); + where field.IsPublic && field.IsLiteral + select new KeyValuePair + ( + (T)field.GetValue(null), + ( + from attr in field.GetCustomAttributes() + where attr.Name != null + select attr.Name + ).ToArray() + ) + ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } - public static bool TryGetNamedValue(string name, out T value) - { - return namedValueDictionary.TryGetValue(name, out value); - } + public static string[] GetValueNames(T value) => valueNameDictionary.TryGetValue(value, out string[] names) ? names : null; } } diff --git a/UnicodeInformation/HangulInfo.cs b/UnicodeInformation/HangulInfo.cs index 3e6cf2c..0164a19 100644 --- a/UnicodeInformation/HangulInfo.cs +++ b/UnicodeInformation/HangulInfo.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { internal static class HangulInfo { diff --git a/UnicodeInformation/PermissiveCodePointEnumerable.cs b/UnicodeInformation/PermissiveCodePointEnumerable.cs index c068ca1..43ac705 100644 --- a/UnicodeInformation/PermissiveCodePointEnumerable.cs +++ b/UnicodeInformation/PermissiveCodePointEnumerable.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { @@ -14,35 +10,19 @@ namespace System.Unicode /// public struct PermissiveCodePointEnumerable : IEnumerable { - private readonly string text; - /// Initializes a new instance of the struct . /// The string whose code points must be enumerated. - public PermissiveCodePointEnumerable(string text) - { - if (text == null) throw new ArgumentNullException(nameof(text)); - - this.text = text; - } + public PermissiveCodePointEnumerable(string text) => Text = text ?? throw new ArgumentNullException(nameof(text)); /// Gets the text whose code points are being enumerated. - public string Text { get { return text; } } + public string Text { get; } /// Gets an enumerator which can be used to enumerate the code points in the text. /// - public PermissiveCodePointEnumerator GetEnumerator() - { - return new PermissiveCodePointEnumerator(text); - } + public PermissiveCodePointEnumerator GetEnumerator() => new PermissiveCodePointEnumerator(Text); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/UnicodeInformation/PermissiveCodePointEnumerator.cs b/UnicodeInformation/PermissiveCodePointEnumerator.cs index 6c30e57..e3f2f1d 100644 --- a/UnicodeInformation/PermissiveCodePointEnumerator.cs +++ b/UnicodeInformation/PermissiveCodePointEnumerator.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { @@ -41,7 +37,7 @@ namespace System.Unicode if (index < text.Length && (index += current > 0xFFFF ? 2 : 1) < text.Length) { current = GetUtf32(text, index); - return true; + return true; } else { diff --git a/UnicodeInformation/StringExtensions.cs b/UnicodeInformation/StringExtensions.cs index 172529a..5c212d6 100644 --- a/UnicodeInformation/StringExtensions.cs +++ b/UnicodeInformation/StringExtensions.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { /// Contains extension methods applicable to the type. public static class StringExtensions diff --git a/UnicodeInformation/UcdFields.cs b/UnicodeInformation/UcdFields.cs index e0959d4..b4c71a4 100644 --- a/UnicodeInformation/UcdFields.cs +++ b/UnicodeInformation/UcdFields.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { /// Represents the fields available for an UCD entry. /// Not all the enumeration member directly map to a field. diff --git a/UnicodeInformation/UnicodeBlock.cs b/UnicodeInformation/UnicodeBlock.cs index ace18d2..940e6d0 100644 --- a/UnicodeInformation/UnicodeBlock.cs +++ b/UnicodeInformation/UnicodeBlock.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics; namespace System.Unicode { /// Represents a Unicode block. + [DebuggerDisplay("[{CodePointRange.ToString(),nq}] {Name,nq}")] public struct UnicodeBlock { /// The code point range of this block. @@ -16,8 +13,8 @@ namespace System.Unicode internal UnicodeBlock(UnicodeCodePointRange codePointRange, string name) { - this.CodePointRange = codePointRange; - this.Name = name; + CodePointRange = codePointRange; + Name = name; } } } diff --git a/UnicodeInformation/UnicodeCategoryExtensions.cs b/UnicodeInformation/UnicodeCategoryExtensions.cs index 903a71d..3a11c82 100644 --- a/UnicodeInformation/UnicodeCategoryExtensions.cs +++ b/UnicodeInformation/UnicodeCategoryExtensions.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Globalization; namespace System.Unicode { diff --git a/UnicodeInformation/UnicodeCategoryInfo.cs b/UnicodeInformation/UnicodeCategoryInfo.cs index 67a87ff..65234cc 100644 --- a/UnicodeInformation/UnicodeCategoryInfo.cs +++ b/UnicodeInformation/UnicodeCategoryInfo.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { @@ -84,26 +80,17 @@ namespace System.Unicode /// Gets an value providing information on the specified unicode category. /// The category on which information should be retrieved. /// Information on the specified category. - public static UnicodeCategoryInfo Get(UnicodeCategory category) - { - return categories[(int)category]; - } + public static UnicodeCategoryInfo Get(UnicodeCategory category) => categories[(int)category]; /// Gets an value providing information on the unicode category, accessed by its short name, as per the Unicode standard. /// The short name for which information should be retrieved . /// Information on the specified category. - public static UnicodeCategoryInfo FromShortName(string name) - { - return Get(GetCategoryFromShortName(name)); - } + public static UnicodeCategoryInfo FromShortName(string name) => Get(GetCategoryFromShortName(name)); /// Gets an value providing information on the unicode category, accessed by its long name, as per the Unicode standard. /// The long name for which information should be retrieved . /// Information on the specified category. - public static UnicodeCategoryInfo FromLongName(string name) - { - return Get(GetCategoryFromLongName(name)); - } + public static UnicodeCategoryInfo FromLongName(string name) => Get(GetCategoryFromLongName(name)); /// The unicode category described. public readonly UnicodeCategory Category; @@ -114,47 +101,32 @@ namespace System.Unicode private UnicodeCategoryInfo(UnicodeCategory category, string shortName, string longName) { - this.Category = category; - this.ShortName = shortName; - this.LongName = longName; + Category = category; + ShortName = shortName; + LongName = longName; } - /// Returns a that represents this instance. - /// A that represents this instance. - public override string ToString() - { - return Category.ToString(); - } + /// Returns a that represents this instance. + /// A that represents this instance. + public override string ToString() => Category.ToString(); - /// Determines whether the specified , is equal to this instance. - /// The to compare with this instance. - /// if the specified is equal to this instance; otherwise, . - public override bool Equals(object obj) - { - return obj is UnicodeCategoryInfo && Equals((UnicodeCategoryInfo)obj); - } + /// Determines whether the specified , is equal to this instance. + /// The to compare with this instance. + /// if the specified is equal to this instance; otherwise, . + public override bool Equals(object obj) => obj is UnicodeCategoryInfo && Equals((UnicodeCategoryInfo)obj); /// Indicates whether the current object is equal to another object of the same type. /// An object to compare with this object. /// if the current object is equal to the other parameter; otherwise, . - public bool Equals(UnicodeCategoryInfo other) - { - return other.Category == Category && (other.Category != 0 || other.ShortName != null); - } + public bool Equals(UnicodeCategoryInfo other) => other.Category == Category && (other.Category != 0 || other.ShortName != null); /// Returns a hash code for this instance. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. - public override int GetHashCode() - { - return (int)Category; - } + public override int GetHashCode() => (int)Category; /// Performs an implicit conversion from to . /// The information. /// The result of the conversion. - public static implicit operator UnicodeCategory(UnicodeCategoryInfo info) - { - return info.Category; - } + public static implicit operator UnicodeCategory(UnicodeCategoryInfo info) => info.Category; } } diff --git a/UnicodeInformation/UnicodeCharInfo.cs b/UnicodeInformation/UnicodeCharInfo.cs index a1601c9..a716eea 100644 --- a/UnicodeInformation/UnicodeCharInfo.cs +++ b/UnicodeInformation/UnicodeCharInfo.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { /// Provides information on a specific unicode code point. + [DebuggerDisplay(@"{CodePoint.ToString(""X4""),nq} - {Name,nq}")] public struct UnicodeCharInfo { /// The code point. diff --git a/UnicodeInformation/UnicodeCodePointRange.cs b/UnicodeInformation/UnicodeCodePointRange.cs index 05afc7c..9a0eb64 100644 --- a/UnicodeInformation/UnicodeCodePointRange.cs +++ b/UnicodeInformation/UnicodeCodePointRange.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { diff --git a/UnicodeInformation/UnicodeInfo.cs b/UnicodeInformation/UnicodeInfo.cs index b768abf..6383bee 100644 --- a/UnicodeInformation/UnicodeInfo.cs +++ b/UnicodeInformation/UnicodeInfo.cs @@ -24,6 +24,7 @@ namespace System.Unicode private static readonly UnicodeBlock[] blocks; private static readonly CjkRadicalData[] radicals; private static readonly int maxContiguousIndex; + private static readonly string[] emojiSequences; static UnicodeInfo() { @@ -49,7 +50,7 @@ namespace System.Unicode if (formatVersion != 2) throw new InvalidDataException(); var fileUnicodeVersion = new Version(reader.ReadUInt16(), reader.ReadByte(), reader.ReadByte()); - + var unicodeCharacterDataEntries = new UnicodeCharacterData[ReadCodePoint(reader)]; // Allocate one extra entry to act as a dummy entry. byte[] nameBuffer = new byte[128]; int mci = 0; @@ -72,7 +73,7 @@ namespace System.Unicode for (; i < unicodeCharacterDataEntries.Length; ++i) { - ReadUnicodeCharacterDataEntry(reader, nameBuffer, out unicodeCharacterDataEntries[i]); + ReadUnicodeCharacterDataEntry(reader, nameBuffer, out unicodeCharacterDataEntries[i]); } var blockEntries = new UnicodeBlock[reader.ReadUInt16()]; @@ -430,11 +431,11 @@ namespace System.Unicode /// A display text for the code point, which may be the representation of the code point itself. public static string GetDisplayText(int codePoint) { - if (codePoint <= 0x0020) return ((char)(0x2400 + codePoint)).ToString(); // Provide a display text for control characters, including space. + if (codePoint <= 0x0020) return ((char)(0x2400 + codePoint)).ToString(); // Provide a display text for control characters, including space. else if (GetCategory(codePoint) == UnicodeCategory.NonSpacingMark) return "\u25CC" + char.ConvertFromUtf32(codePoint); - else if (codePoint >= 0xD800 && codePoint <= 0xDFFF) return "\xFFFD"; + else if (codePoint >= 0xD800 && codePoint <= 0xDFFF) return "\xFFFD"; else if (codePoint >= 0xE0020 && codePoint < 0xE007F) return char.ConvertFromUtf32(codePoint - 0xE0000); // Handle "TAG" ASCII subset by remapping it to regular ASCII - else return char.ConvertFromUtf32(codePoint); + else return char.ConvertFromUtf32(codePoint); } private static string GetDisplayText(int codePoint, int unicodeCharacterDataIndex) @@ -458,18 +459,18 @@ namespace System.Unicode HangulInfo.GetHangulName((char)codePoint) : GetNameInternal(codePoint); - private static string GetNameInternal(int codePoint) + private static string GetNameInternal(int codePoint) => FindUnicodeCodePointIndex(codePoint) is int codePointInfoIndex && codePointInfoIndex >= 0 ? GetName(codePoint, ref GetUnicodeCharacterData(codePointInfoIndex)) : null; internal static string GetName(int codePoint, ref UnicodeCharacterData characterData) { - if (characterData.CodePointRange.IsSingleCodePoint) return characterData.Name; - else if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint); - else if (characterData.Name != null) return characterData.Name + "-" + codePoint.ToString("X4"); - else return null; - } + if (characterData.CodePointRange.IsSingleCodePoint) return characterData.Name; + else if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint); + else if (characterData.Name != null) return characterData.Name + "-" + codePoint.ToString("X4"); + else return null; + } /// Returns information for a CJK radical. /// The index of the radical. Must be between 1 and . diff --git a/UnicodeInformation/UnicodeNameAlias.cs b/UnicodeInformation/UnicodeNameAlias.cs index 343ca94..bbe99b8 100644 --- a/UnicodeInformation/UnicodeNameAlias.cs +++ b/UnicodeInformation/UnicodeNameAlias.cs @@ -1,6 +1,10 @@ -namespace System.Unicode +using System.Diagnostics; +using System.Linq; + +namespace System.Unicode { /// Represents a name alias for an Unicode code point. + [DebuggerDisplay("{DisplayText,nq}")] public struct UnicodeNameAlias { internal static readonly UnicodeNameAlias[] EmptyArray = new UnicodeNameAlias[0]; @@ -12,6 +16,8 @@ /// The kind of alias. public UnicodeNameAliasKind Kind { get; } + private string DisplayText => (Kind != 0 ? "<" + EnumHelper.GetValueNames(Kind).FirstOrDefault() + "> " : string.Empty) + Name; + internal UnicodeNameAlias(string name, UnicodeNameAliasKind kind) { Name = name; diff --git a/UnicodeInformation/UnicodeNameAliasCollection.cs b/UnicodeInformation/UnicodeNameAliasCollection.cs index fa53ebc..3e381fd 100644 --- a/UnicodeInformation/UnicodeNameAliasCollection.cs +++ b/UnicodeInformation/UnicodeNameAliasCollection.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { diff --git a/UnicodeInformation/UnicodeNumericType.cs b/UnicodeInformation/UnicodeNumericType.cs index efd4ca2..e9225be 100644 --- a/UnicodeInformation/UnicodeNumericType.cs +++ b/UnicodeInformation/UnicodeNumericType.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { /// Represents the value of the Numeric_Type property. public enum UnicodeNumericType : byte diff --git a/UnicodeInformation/UnicodeRadicalStrokeCount.cs b/UnicodeInformation/UnicodeRadicalStrokeCount.cs index 62e3e6b..94e5d34 100644 --- a/UnicodeInformation/UnicodeRadicalStrokeCount.cs +++ b/UnicodeInformation/UnicodeRadicalStrokeCount.cs @@ -1,29 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics; namespace System.Unicode { /// Provides information on radical and additional stroke count for a code point. /// Values of this type are usually associated with the property kRSUnicode (aka. Unicode_Radical_Stroke). + [DebuggerDisplay(@"{IsSimplified ? ""Simplified"" : ""Traditional"",nq} Radical {Radical} + {StrokeCount} Strokes")] public struct UnicodeRadicalStrokeCount { internal static readonly UnicodeRadicalStrokeCount[] EmptyArray = new UnicodeRadicalStrokeCount[0]; - /// The radical index. - private readonly byte radical; - /// The stroke count as a 7bit signed value, together with the flag as a 1bit value. - private readonly byte strokeCount; - /// Initializes a new instance of the class from raw data. - /// The raw value to use for . - /// The raw value to use for . + /// The raw value to use for . + /// The raw value to use for . internal UnicodeRadicalStrokeCount(byte rawRadical, byte rawStrokeCount) { - radical = rawRadical; - strokeCount = rawStrokeCount; + Radical = rawRadical; + RawStrokeCount = rawStrokeCount; } /// Initializes a new instance of the class . @@ -36,23 +28,24 @@ namespace System.Unicode { if (strokeCount < -64 || strokeCount > 63) throw new ArgumentOutOfRangeException(nameof(strokeCount)); - this.radical = radical; + Radical = radical; // Pack strokeCount together with isSimplified in a single byte. - this.strokeCount = unchecked((byte)(strokeCount & 0x7F | (isSimplified ? 0x80 : 0x00))); + RawStrokeCount = unchecked((byte)(strokeCount & 0x7F | (isSimplified ? 0x80 : 0x00))); } /// Gets the index of the Kangxi radical of the character. /// The Kangxi radicals are numbered from 1 to 214 inclusive. /// The index of the Kangxi radical. - public byte Radical { get { return radical; } } + public byte Radical { get; } /// Gets the value of packed with . - /// The raw value of . - internal byte RawStrokeCount { get { return strokeCount; } } + /// The stroke count is stored as a 7bit signed value, together with the flag as a 1bit value. + /// The raw value of . + internal byte RawStrokeCount { get; } /// Gets the additional stroke count. /// The additional stroke count. - public sbyte StrokeCount { get { return unchecked((sbyte)(strokeCount & 0x7F | (strokeCount & 0x40) << 1)); } } // To unpack the stroke count, we simply need to copy bit 6 to bit 7. - /// Gets a value indicating whether the information is based on the simplified form of the radical. - /// if the information is based on the simplified form of the radical; otherwise, . - public bool IsSimplified { get { return (strokeCount & 0x80) != 0; } } + public sbyte StrokeCount { get { return unchecked((sbyte)(RawStrokeCount & 0x7F | (RawStrokeCount & 0x40) << 1)); } } // To unpack the stroke count, we simply need to copy bit 6 to bit 7. + /// Gets a value indicating whether the information is based on the simplified form of the radical. + /// if the information is based on the simplified form of the radical; otherwise, . + public bool IsSimplified { get { return (RawStrokeCount & 0x80) != 0; } } } } diff --git a/UnicodeInformation/UnicodeRadicalStrokeCountCollection.cs b/UnicodeInformation/UnicodeRadicalStrokeCountCollection.cs index 44b2617..8cf1dca 100644 --- a/UnicodeInformation/UnicodeRadicalStrokeCountCollection.cs +++ b/UnicodeInformation/UnicodeRadicalStrokeCountCollection.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace System.Unicode { diff --git a/UnicodeInformation/UnicodeRationalNumber.cs b/UnicodeInformation/UnicodeRationalNumber.cs index fa92172..a0acee0 100644 --- a/UnicodeInformation/UnicodeRationalNumber.cs +++ b/UnicodeInformation/UnicodeRationalNumber.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { /// Represents a rational number in a format compatible with the Unicode standard. public struct UnicodeRationalNumber : IEquatable diff --git a/UnicodeInformation/UnihanFields.cs b/UnicodeInformation/UnihanFields.cs index 29edc7e..8896545 100644 --- a/UnicodeInformation/UnihanFields.cs +++ b/UnicodeInformation/UnihanFields.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { [Flags] internal enum UnihanFields : ushort diff --git a/UnicodeInformation/UnihanNumericType.cs b/UnicodeInformation/UnihanNumericType.cs index 1a93b64..aff06cb 100644 --- a/UnicodeInformation/UnihanNumericType.cs +++ b/UnicodeInformation/UnihanNumericType.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { /// Represents the different numeric types from the Unihan database. public enum UnihanNumericType : byte diff --git a/UnicodeInformation/ValueNameAttribute.cs b/UnicodeInformation/ValueNameAttribute.cs index 6de05c9..066e346 100644 --- a/UnicodeInformation/ValueNameAttribute.cs +++ b/UnicodeInformation/ValueNameAttribute.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System.Unicode +namespace System.Unicode { /// Declares a name for a specific value. ///