Refactored the code a bit: renamed UnicodeData to UnicodeInfo, and exposed an intermediate UnicodeCharInfo type instead of UnicodeCharacterData.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Unicode
|
||||
{
|
||||
public struct UnicodeCharInfo
|
||||
{
|
||||
private readonly int codePoint;
|
||||
private readonly UnicodeCharacterData characterData;
|
||||
|
||||
public int CodePoint { get { return codePoint; } }
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return characterData.Name == null || characterData.CodePointRange.IsSingleCodePoint ?
|
||||
characterData.Name :
|
||||
characterData.Name + "-" + codePoint.ToString("X4");
|
||||
}
|
||||
}
|
||||
|
||||
public UnicodeCategory Category { get { return characterData.Category; } }
|
||||
public CanonicalCombiningClass CanonicalCombiningClass { get { return characterData.CanonicalCombiningClass; } }
|
||||
public BidirectionalClass BidirectionalClass { get { return characterData.BidirectionalClass; } }
|
||||
public CompatibilityFormattingTag DecompositionType { get { return characterData.DecompositionType; } }
|
||||
public string DecompositionMapping { get { return characterData.DecompositionMapping; } }
|
||||
public UnicodeNumericType NumericType { get { return characterData.NumericType; } }
|
||||
public UnicodeRationalNumber? NumericValue { get { return characterData.NumericValue; } }
|
||||
public bool BidirectionalMirrored { get { return characterData.BidirectionalMirrored; } }
|
||||
public string OldName { get { return characterData.OldName; } }
|
||||
public string SimpleUpperCaseMapping { get { return characterData.SimpleUpperCaseMapping; } }
|
||||
public string SimpleLowerCaseMapping { get { return characterData.SimpleLowerCaseMapping; } }
|
||||
public string SimpleTitleCaseMapping { get { return characterData.SimpleTitleCaseMapping; } }
|
||||
public ContributoryProperties ContributoryProperties { get { return characterData.ContributoryProperties; } }
|
||||
|
||||
internal UnicodeCharInfo(int codePoint, UnicodeCharacterData characterData)
|
||||
{
|
||||
this.codePoint = codePoint;
|
||||
this.characterData = characterData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace System.Unicode
|
||||
{
|
||||
public sealed class UnicodeCharacterData
|
||||
internal sealed class UnicodeCharacterData
|
||||
{
|
||||
public readonly UnicodeCharacterRange CodePointRange;
|
||||
public readonly string Name;
|
||||
|
||||
@@ -10,14 +10,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace System.Unicode
|
||||
{
|
||||
public sealed class UnicodeData
|
||||
public sealed class UnicodeInfo
|
||||
{
|
||||
private static readonly UnicodeData @default = ReadEmbeddedUnicodeData();
|
||||
public static UnicodeData Default { get { return @default; } }
|
||||
private static readonly UnicodeInfo @default = ReadEmbeddedUnicodeData();
|
||||
public static UnicodeInfo Default { get { return @default; } }
|
||||
|
||||
private static UnicodeData ReadEmbeddedUnicodeData()
|
||||
private static UnicodeInfo ReadEmbeddedUnicodeData()
|
||||
{
|
||||
using (var stream = new DeflateStream(typeof(UnicodeData).GetTypeInfo().Assembly.GetManifestResourceStream("System.Unicode.ucd.dat"), CompressionMode.Decompress, false))
|
||||
using (var stream = new DeflateStream(typeof(UnicodeInfo).GetTypeInfo().Assembly.GetManifestResourceStream("System.Unicode.ucd.dat"), CompressionMode.Decompress, false))
|
||||
{
|
||||
return FromStream(stream);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace System.Unicode
|
||||
private readonly Version unicodeVersion;
|
||||
private readonly UnicodeCharacterData[] characterData;
|
||||
|
||||
public static UnicodeData FromStream(Stream stream)
|
||||
public static UnicodeInfo FromStream(Stream stream)
|
||||
{
|
||||
using (var reader = new BinaryReader(stream, Encoding.UTF8))
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace System.Unicode
|
||||
entries[i] = ReadEntry(reader);
|
||||
}
|
||||
|
||||
return new UnicodeData(unicodeVersion, entries);
|
||||
return new UnicodeInfo(unicodeVersion, entries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace System.Unicode
|
||||
}
|
||||
}
|
||||
|
||||
internal UnicodeData(Version unicodeVersion, UnicodeCharacterData[] characterData)
|
||||
internal UnicodeInfo(Version unicodeVersion, UnicodeCharacterData[] characterData)
|
||||
{
|
||||
this.unicodeVersion = unicodeVersion;
|
||||
this.characterData = characterData;
|
||||
@@ -147,9 +147,9 @@ namespace System.Unicode
|
||||
return null;
|
||||
}
|
||||
|
||||
public UnicodeCharacterData Get(int codePoint)
|
||||
public UnicodeCharInfo Get(int codePoint)
|
||||
{
|
||||
return FindCodePoint(codePoint);
|
||||
return new UnicodeCharInfo(codePoint, FindCodePoint(codePoint));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,8 @@
|
||||
<Compile Include="UnicodeCategoryInfo.cs" />
|
||||
<Compile Include="UnicodeCharacterData.cs" />
|
||||
<Compile Include="UnicodeCharacterRange.cs" />
|
||||
<Compile Include="UnicodeData.cs" />
|
||||
<Compile Include="UnicodeCharInfo.cs" />
|
||||
<Compile Include="UnicodeInfo.cs" />
|
||||
<Compile Include="UnicodeNumericType.cs" />
|
||||
<Compile Include="ValueNameAttribute.cs" />
|
||||
<Compile Include="UnicodeRationalNumber.cs" />
|
||||
|
||||
Reference in New Issue
Block a user