diff --git a/UnicodeInformation.Tests/UnicodeInfoTests.cs b/UnicodeInformation.Tests/UnicodeInfoTests.cs index 9f5a4f2..36ef968 100644 --- a/UnicodeInformation.Tests/UnicodeInfoTests.cs +++ b/UnicodeInformation.Tests/UnicodeInfoTests.cs @@ -353,10 +353,58 @@ namespace UnicodeInformation.Tests Assert.AreEqual(true, enumerator.MoveNext()); Assert.AreEqual(start, enumerator.Current); } - } + } + + [TestMethod] + public void GetNameSuccessTest() + { + for (int i = 0; i <= 0x10FFFF; i++) + { + UnicodeInfo.GetName(i); + } + } + + [TestMethod] + public void GetDisplayTextSuccessTest() + { + for (int i = 0; i <= 0x10FFFF; i++) + { + UnicodeInfo.GetDisplayText(i); + } + } + + [TestMethod] + public void GetCategorySuccessTest() + { + for (int i = 0; i <= 0x10FFFF; i++) + { + UnicodeInfo.GetCategory(i); + } + } + + [TestMethod] + public void GetCharInfoSuccessTest() + { + for (int i = 0; i <= 0x10FFFF; i++) + { + UnicodeInfo.GetCharInfo(i); + } + } + + [TestMethod] + public void GetCharInfoCoherenceTest() + { + for (int i = 0; i <= 0x10FFFF; i++) + { + var charInfo = UnicodeInfo.GetCharInfo(i); + + Assert.AreEqual(charInfo.Name, UnicodeInfo.GetName(i)); + Assert.AreEqual(charInfo.Category, UnicodeInfo.GetCategory(i)); + } + } #if DEBUG - [TestMethod] + [TestMethod] public void UnihanCodePointPackingTest() { for (int i = 0x3400; i < 0x4E00; ++i) diff --git a/UnicodeInformation/HangulInfo.cs b/UnicodeInformation/HangulInfo.cs index 32aa351..3e6cf2c 100644 --- a/UnicodeInformation/HangulInfo.cs +++ b/UnicodeInformation/HangulInfo.cs @@ -55,7 +55,7 @@ namespace System.Unicode internal static bool IsHangul(int codePoint) { - return codePoint >= SBase && codePoint <= SBase + SCount; + return codePoint >= SBase && codePoint < SBase + SCount; } } } diff --git a/UnicodeInformation/UnicodeCharInfo.cs b/UnicodeInformation/UnicodeCharInfo.cs index 5ed6800..00a4815 100644 --- a/UnicodeInformation/UnicodeCharInfo.cs +++ b/UnicodeInformation/UnicodeCharInfo.cs @@ -190,7 +190,7 @@ namespace System.Unicode internal UnicodeCharInfo(int codePoint, UnicodeCharacterData unicodeCharacterData, UnihanCharacterData unihanCharacterData, string block) { this.codePoint = codePoint; - this.name = UnicodeInfo.GetName(codePoint, unicodeCharacterData); + this.name = unicodeCharacterData != null ? UnicodeInfo.GetName(codePoint, unicodeCharacterData) : null; this.unicodeCharacterData = unicodeCharacterData; this.unihanCharacterData = unihanCharacterData; this.block = block; diff --git a/UnicodeInformation/UnicodeInfo.cs b/UnicodeInformation/UnicodeInfo.cs index 5d3af74..75d1cfb 100644 --- a/UnicodeInformation/UnicodeInfo.cs +++ b/UnicodeInformation/UnicodeInfo.cs @@ -433,9 +433,10 @@ 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(); - else if (GetCategory(codePoint) == UnicodeCategory.NonSpacingMark) return "\u25CC" + char.ConvertFromUtf32(codePoint); - else return char.ConvertFromUtf32(codePoint); + if (codePoint <= 0x0020) return ((char)(0x2400 + codePoint)).ToString(); + else if (GetCategory(codePoint) == UnicodeCategory.NonSpacingMark) return "\u25CC" + char.ConvertFromUtf32(codePoint); + else if (codePoint >= 0xD800 && codePoint <= 0xDFFF) return "\xFFFD"; + else return char.ConvertFromUtf32(codePoint); } /// Gets the name of the specified code point. @@ -448,16 +449,23 @@ namespace System.Unicode public static string GetName(int codePoint) { if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint); - else return GetName(codePoint, FindUnicodeCodePoint(codePoint)); + else return GetNameInternal(codePoint); } + private static string GetNameInternal(int codePoint) + { + var codePointInfo = FindUnicodeCodePoint(codePoint); + + return codePointInfo != null ? GetName(codePoint, codePointInfo) : null; + } + internal static string GetName(int codePoint, 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 .