Bugfixes.

This commit is contained in:
GoldenCrystal
2016-01-14 01:31:36 +01:00
parent 3cf36ec6de
commit 23823a6626
4 changed files with 69 additions and 13 deletions
+50 -2
View File
@@ -353,10 +353,58 @@ namespace UnicodeInformation.Tests
Assert.AreEqual(true, enumerator.MoveNext()); Assert.AreEqual(true, enumerator.MoveNext());
Assert.AreEqual(start, enumerator.Current); 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 #if DEBUG
[TestMethod] [TestMethod]
public void UnihanCodePointPackingTest() public void UnihanCodePointPackingTest()
{ {
for (int i = 0x3400; i < 0x4E00; ++i) for (int i = 0x3400; i < 0x4E00; ++i)
+1 -1
View File
@@ -55,7 +55,7 @@ namespace System.Unicode
internal static bool IsHangul(int codePoint) internal static bool IsHangul(int codePoint)
{ {
return codePoint >= SBase && codePoint <= SBase + SCount; return codePoint >= SBase && codePoint < SBase + SCount;
} }
} }
} }
+1 -1
View File
@@ -190,7 +190,7 @@ namespace System.Unicode
internal UnicodeCharInfo(int codePoint, UnicodeCharacterData unicodeCharacterData, UnihanCharacterData unihanCharacterData, string block) internal UnicodeCharInfo(int codePoint, UnicodeCharacterData unicodeCharacterData, UnihanCharacterData unihanCharacterData, string block)
{ {
this.codePoint = codePoint; this.codePoint = codePoint;
this.name = UnicodeInfo.GetName(codePoint, unicodeCharacterData); this.name = unicodeCharacterData != null ? UnicodeInfo.GetName(codePoint, unicodeCharacterData) : null;
this.unicodeCharacterData = unicodeCharacterData; this.unicodeCharacterData = unicodeCharacterData;
this.unihanCharacterData = unihanCharacterData; this.unihanCharacterData = unihanCharacterData;
this.block = block; this.block = block;
+17 -9
View File
@@ -433,9 +433,10 @@ namespace System.Unicode
/// <returns>A display text for the code point, which may be the representation of the code point itself.</returns> /// <returns>A display text for the code point, which may be the representation of the code point itself.</returns>
public static string GetDisplayText(int codePoint) public static string GetDisplayText(int codePoint)
{ {
if (codePoint <= 0x0020) return ((char)(0x2400 + codePoint)).ToString(); if (codePoint <= 0x0020) return ((char)(0x2400 + codePoint)).ToString();
else if (GetCategory(codePoint) == UnicodeCategory.NonSpacingMark) return "\u25CC" + char.ConvertFromUtf32(codePoint); else if (GetCategory(codePoint) == UnicodeCategory.NonSpacingMark) return "\u25CC" + char.ConvertFromUtf32(codePoint);
else return char.ConvertFromUtf32(codePoint); else if (codePoint >= 0xD800 && codePoint <= 0xDFFF) return "\xFFFD";
else return char.ConvertFromUtf32(codePoint);
} }
/// <summary>Gets the name of the specified code point.</summary> /// <summary>Gets the name of the specified code point.</summary>
@@ -448,16 +449,23 @@ namespace System.Unicode
public static string GetName(int codePoint) public static string GetName(int codePoint)
{ {
if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)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) internal static string GetName(int codePoint, UnicodeCharacterData characterData)
{ {
if (characterData.CodePointRange.IsSingleCodePoint) return characterData.Name; if (characterData.CodePointRange.IsSingleCodePoint) return characterData.Name;
else if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint); else if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint);
else if (characterData.Name != null) return characterData.Name + "-" + codePoint.ToString("X4"); else if (characterData.Name != null) return characterData.Name + "-" + codePoint.ToString("X4");
else return null; else return null;
} }
/// <summary>Returns information for a CJK radical.</summary> /// <summary>Returns information for a CJK radical.</summary>
/// <param name="radicalIndex">The index of the radical. Must be between 1 and <see cref="CjkRadicalCount"/>.</param> /// <param name="radicalIndex">The index of the radical. Must be between 1 and <see cref="CjkRadicalCount"/>.</param>