Handle Unicode Core Properties.

This commit is contained in:
GoldenCrystal
2014-11-08 22:00:12 +01:00
parent f4dbdd399f
commit afb4b85637
16 changed files with 203 additions and 29 deletions
+52
View File
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Unicode
{
[Flags]
public enum CoreProperties : int
{
[ValueName("Lowercase"), ValueName("Lower"), Display(Name = "Lowercase")]
Lowercase = 0x00000001,
[ValueName("Uppercase"), ValueName("Upper"), Display(Name = "Uppercase")]
Uppercase = 0x00000002,
[ValueName("Cased"), Display(Name = "Cased")]
Cased = 0x00000004,
[ValueName("Case_Ignorable"), ValueName("CI"), Display(Name = "Case_Ignorable")]
CaseIgnorable = 0x00000008,
[ValueName("Changes_When_Lowercased"), ValueName("CWL"), Display(Name = "Changes_When_Lowercased")]
ChangesWhenLowercased = 0x00000010,
[ValueName("Changes_When_Uppercased"), ValueName("CWU"), Display(Name = "Changes_When_Uppercased")]
ChangesWhenUppercased = 0x00000020,
[ValueName("Changes_When_Titlecased"), ValueName("CWT"), Display(Name = "Changes_When_Titlecased")]
ChangesWhenTitlecased = 0x00000040,
[ValueName("Changes_When_Casefolded"), ValueName("CWCF"), Display(Name = "Changes_When_Casefolded")]
ChangesWhenCasefolded = 0x00000080,
[ValueName("Changes_When_Casemapped"), ValueName("CWCM"), Display(Name = "Changes_When_Casemapped")]
ChangesWhenCasemapped = 0x00000100,
[ValueName("Alphabetic"), ValueName("Alpha"), Display(Name = "Alphabetic")]
Alphabetic = 0x00000200,
[ValueName("Default_Ignorable_Code_Point"), ValueName("DI"), Display(Name = "Default_Ignorable_Code_Point")]
DefaultIgnorableCodePoint = 0x00000400,
[ValueName("Grapheme_Base"), ValueName("Gr_Base"), Display(Name = "Grapheme_Base")]
GraphemeBase = 0x00000800,
[ValueName("Grapheme_Extend"), ValueName("Gr_Ext"), Display(Name = "Grapheme_Extend")]
GraphemeExtend = 0x00001000,
[ValueName("Grapheme_Link"), ValueName("Gr_Link"), Display(Name = "Grapheme_Link")]
GraphemeLink = 0x00002000,
[ValueName("Math"), Display(Name = "Math")]
Math = 0x00004000,
[ValueName("ID_Start"), ValueName("IDS"), Display(Name = "ID_Start")]
IdentifierStart = 0x00008000,
[ValueName("ID_Continue"), ValueName("IDC"), Display(Name = "ID_Continue")]
IdentifierContinue = 0x00010000,
[ValueName("XID_Start"), ValueName("XIDS"), Display(Name = "XID_Start")]
ExtendedIdentifierStart = 0x00020000,
[ValueName("XID_Continue"), ValueName("XIDC"), Display(Name = "XID_Continue")]
ExtendedIdentifierContinue = 0x00040000,
}
}
+2
View File
@@ -32,6 +32,8 @@ namespace System.Unicode
SimpleUpperCaseMapping = 1024,
SimpleLowerCaseMapping = 2048,
SimpleTitleCaseMapping = 4096,
ContributoryProperties = 8192,
CoreProperties = 16384,
}
}
+1
View File
@@ -39,6 +39,7 @@ namespace System.Unicode
public string SimpleLowerCaseMapping { get { return characterData.SimpleLowerCaseMapping; } }
public string SimpleTitleCaseMapping { get { return characterData.SimpleTitleCaseMapping; } }
public ContributoryProperties ContributoryProperties { get { return characterData.ContributoryProperties; } }
public CoreProperties CoreProperties { get { return characterData.CoreProperties; } }
internal UnicodeCharInfo(int codePoint, UnicodeCharacterData characterData, string block)
{
+4 -1
View File
@@ -24,8 +24,9 @@ namespace System.Unicode
public readonly string SimpleLowerCaseMapping;
public readonly string SimpleTitleCaseMapping;
public readonly ContributoryProperties ContributoryProperties;
public readonly CoreProperties CoreProperties;
public readonly int[] RelatedCodePoints;
public readonly int[] RelatedCodePoints; // NB: It seems that parsing NamesList is required in order to provide data for this field ?
internal UnicodeCharacterData
(
@@ -44,6 +45,7 @@ namespace System.Unicode
string simpleLowerCaseMapping,
string simpleTitleCaseMapping,
ContributoryProperties contributoryProperties,
CoreProperties coreProperties,
int[] relatedCodePoints
)
{
@@ -62,6 +64,7 @@ namespace System.Unicode
this.SimpleLowerCaseMapping = simpleLowerCaseMapping;
this.SimpleTitleCaseMapping = simpleTitleCaseMapping;
this.ContributoryProperties = contributoryProperties;
this.CoreProperties = coreProperties;
this.RelatedCodePoints = relatedCodePoints;
}
+8 -1
View File
@@ -83,6 +83,7 @@ namespace System.Unicode
string simpleLowerCaseMapping = (fields & UcdFields.SimpleLowerCaseMapping) != 0 ? reader.ReadString() : null;
string simpleTitleCaseMapping = (fields & UcdFields.SimpleTitleCaseMapping) != 0 ? reader.ReadString() : null;
ContributoryProperties contributoryProperties = (fields & UcdFields.ContributoryProperties) != 0 ? (ContributoryProperties)reader.ReadInt32() : 0;
CoreProperties coreProperties = (fields & UcdFields.CoreProperties) != 0 ? (CoreProperties)ReadInt24(reader) : 0;
return new UnicodeCharacterData
(
@@ -101,7 +102,8 @@ namespace System.Unicode
simpleLowerCaseMapping,
simpleTitleCaseMapping,
contributoryProperties,
null
coreProperties,
null
);
}
@@ -110,6 +112,11 @@ namespace System.Unicode
return new UnicodeBlock(new UnicodeCharacterRange(ReadCodePoint(reader), ReadCodePoint(reader)), reader.ReadString());
}
private static int ReadInt24(BinaryReader reader)
{
return reader.ReadByte() | ((reader.ReadByte() | (reader.ReadByte() << 8)) << 8);
}
#if DEBUG
internal static int ReadCodePoint(BinaryReader reader)
#else
+4 -3
View File
@@ -53,9 +53,9 @@
<Link>System.Unicode.snk</Link>
</None>
<None Include="app.config" />
<EmbeddedResource Include="ucd.dat">
<LogicalName>ucd.dat</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="ucd.dat">
<LogicalName>ucd.dat</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Include="BidirectionalClass.cs" />
@@ -64,6 +64,7 @@
<Compile Include="CanonicalCombiningClass.cs" />
<Compile Include="CodePointEnumerable.cs" />
<Compile Include="CodePointEnumerator.cs" />
<Compile Include="CoreProperties.cs" />
<Compile Include="UcdFields.cs" />
<Compile Include="EnumHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Binary file not shown.