Exposed cross-references, and added them to the UI.

This commit is contained in:
GoldenCrystal
2014-11-24 00:24:55 +01:00
parent 95fd83cb6d
commit 4f03ba85d9
23 changed files with 169 additions and 55 deletions
+2 -1
View File
@@ -63,7 +63,7 @@ This library includes a subset of the official [Unicode Character Database](http
* Bidi_Class
* Decomposition_Type
* Decomposition_Mapping
* Numeric_Type (*)
* Numeric_Type (See also kAccountingNumeric/kOtherNumeric/kPrimaryNumeric. Those will set Numeric_Type to Numeric.)
* Numeric_Value
* Bidi_Mirrored
* Unicode_1_Name
@@ -123,6 +123,7 @@ This library includes a subset of the official [Unicode Character Database](http
* ID_Continue
* XID_Start
* XID_Continue
* Code point cross references extracted from NamesList.txt
NB: The UCD property ISO_Comment will never be included since this one is empty in all new Unicode versions.
+2
View File
@@ -7,5 +7,7 @@
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<local:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
<local:ZeroToVisibilityConverter x:Key="ZeroToVisibilityConverter" />
<local:Utf32ToDisplayTextConverter x:Key="Utf32ToStringConverter" />
<local:Utf32ToNameConverter x:Key="Utf32ToNameConverter" />
</Application.Resources>
</Application>
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace UnicodeCharacterInspector
{
@@ -67,6 +67,7 @@ namespace UnicodeCharacterInspector
NotifyPropertyChanged(nameof(NumericValue));
NotifyPropertyChanged(nameof(ContributoryProperties));
NotifyPropertyChanged(nameof(CoreProperties));
NotifyPropertyChanged(nameof(CrossReferences));
NotifyPropertyChanged(nameof(MandarinReading));
NotifyPropertyChanged(nameof(CantoneseReading));
NotifyPropertyChanged(nameof(JapaneseKunReading));
@@ -172,6 +173,11 @@ namespace UnicodeCharacterInspector
get { return character != null ? characterInfo.CoreProperties : null as CoreProperties?; }
}
public UnicodeCrossReferenceCollection CrossReferences
{
get { return character != null ? characterInfo.CrossRerefences : new UnicodeCrossReferenceCollection(); }
}
public string MandarinReading
{
get { return character != null ? characterInfo.MandarinReading : null; }
@@ -2,10 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Unicode;
namespace UnicodeCharacterInspector
+11
View File
@@ -86,6 +86,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Visibility="{Binding SelectedCharacterInfo.CodePoint, Converter={StaticResource NullToVisibilityConverter}}" Text="Code Point" />
@@ -144,6 +145,16 @@
<TextBlock Grid.Row="22" Grid.Column="1" VerticalAlignment="Top" TextWrapping="WrapWithOverflow" Visibility="{Binding SelectedCharacterInfo.ContributoryProperties, Converter={StaticResource ZeroToVisibilityConverter}}" Text="{Binding SelectedCharacterInfo.ContributoryProperties}" />
<TextBlock Grid.Row="23" Grid.Column="0" VerticalAlignment="Top" Visibility="{Binding SelectedCharacterInfo.CoreProperties, Converter={StaticResource ZeroToVisibilityConverter}}" Text="Core Properties" />
<TextBlock Grid.Row="23" Grid.Column="1" VerticalAlignment="Top" TextWrapping="WrapWithOverflow" Visibility="{Binding SelectedCharacterInfo.CoreProperties, Converter={StaticResource ZeroToVisibilityConverter}}" Text="{Binding SelectedCharacterInfo.CoreProperties}" />
<TextBlock Grid.Row="24" Grid.Column="0" VerticalAlignment="Top" Visibility="{Binding SelectedCharacterInfo.CrossReferences.Count, Converter={StaticResource ZeroToVisibilityConverter}}" Text="Cross-References" />
<ItemsControl Grid.Row="24" Grid.Column="1" Visibility="{Binding SelectedCharacterInfo.CrossReferences.Count, Converter={StaticResource ZeroToVisibilityConverter}}" ItemsSource="{Binding SelectedCharacterInfo.CrossReferences}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock TextWrapping="WrapWithOverflow">
• “<Run Text="{Binding Mode=OneTime, Converter={StaticResource Utf32ToStringConverter}}" />” U+<Run Text="{Binding Mode=OneTime, StringFormat=X4}" /> <Run Text="{Binding Mode=OneTime, Converter={StaticResource Utf32ToNameConverter}}" />
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ScrollViewer>
</Grid>
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
-4
View File
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Media;
namespace UnicodeCharacterInspector
{
@@ -77,6 +77,8 @@
<Compile Include="PlaceholderAdorner.cs">
<DependentUpon>Placeholder.cs</DependentUpon>
</Compile>
<Compile Include="Utf32ToNameConverter.cs" />
<Compile Include="Utf32ToDisplayTextConverter.cs" />
<Compile Include="ZeroToVisibilityConverter.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Unicode;
using System.Windows.Data;
namespace UnicodeCharacterInspector
{
internal sealed class Utf32ToDisplayTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null ? UnicodeInfo.GetDisplayText((int)value) : null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Unicode;
using System.Windows.Data;
namespace UnicodeCharacterInspector
{
internal sealed class Utf32ToNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null ? UnicodeInfo.GetName((int)value) : null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
+3 -1
View File
@@ -21,8 +21,10 @@ namespace System.Unicode.Builder
"UnicodeData.txt",
"PropList.txt",
"DerivedCoreProperties.txt",
//"Jamo.txt", // Not used right now, as the hangul syllable algorithm implementation takes care of this.
"NameAliases.txt",
"NamesList.txt",
"Blocks.txt",
"Jamo.txt",
};
public static readonly string[] unihanRequiredFiles = new[]
@@ -27,7 +27,7 @@ namespace System.Unicode.Builder
private CoreProperties coreProperties;
private readonly List<UnicodeNameAlias> nameAliases = new List<UnicodeNameAlias>();
private readonly List<int> relatedCodePoints = new List<int>();
private readonly List<int> crossRerefences = new List<int>();
public UnicodeCharacterRange CodePointRange { get { return codePointRange; } }
@@ -124,7 +124,7 @@ namespace System.Unicode.Builder
set { coreProperties = value; }
}
public ICollection<int> RelatedCodePoints { get { return relatedCodePoints; } }
public ICollection<int> CrossRerefences { get { return crossRerefences; } }
public UnicodeCharacterDataBuilder(int codePoint)
: this(new UnicodeCharacterRange(codePoint))
@@ -158,7 +158,7 @@ namespace System.Unicode.Builder
SimpleTitleCaseMapping,
ContributoryProperties,
CoreProperties,
RelatedCodePoints.Count > 0 ? RelatedCodePoints.ToArray() : null
CrossRerefences.Count > 0 ? CrossRerefences.ToArray() : null
);
}
@@ -184,7 +184,7 @@ namespace System.Unicode.Builder
if (simpleTitleCaseMapping != null) fields |= UcdFields.SimpleTitleCaseMapping;
if (contributoryProperties != 0) fields |= UcdFields.ContributoryProperties;
if (coreProperties != 0) fields |= UcdFields.CoreProperties;
if (relatedCodePoints.Count > 0) fields |= UcdFields.RelatedCodePoints;
if (crossRerefences.Count > 0) fields |= UcdFields.CrossRerefences;
writer.Write((ushort)fields);
@@ -232,11 +232,11 @@ namespace System.Unicode.Builder
if ((fields & UcdFields.SimpleTitleCaseMapping) != 0) writer.Write(simpleTitleCaseMapping);
if ((fields & UcdFields.ContributoryProperties) != 0) writer.Write((int)contributoryProperties);
if ((fields & UcdFields.CoreProperties) != 0) writer.WriteUInt24((int)coreProperties);
if ((fields & UcdFields.RelatedCodePoints) != 0)
if ((fields & UcdFields.CrossRerefences) != 0)
{
writer.Write(checked((byte)(relatedCodePoints.Count - 1)));
foreach (int relatedCodePoint in relatedCodePoints)
writer.WriteCodePoint(relatedCodePoint);
writer.Write(checked((byte)(crossRerefences.Count - 1)));
foreach (int crossReference in crossRerefences)
writer.WriteCodePoint(crossReference);
}
}
}
@@ -41,7 +41,7 @@ namespace System.Unicode.Builder
await ProcessDerivedCorePropertiesFile(ucdSource, builder).ConfigureAwait(false);
await ProcessNameAliasesFile(ucdSource, builder).ConfigureAwait(false);
await ProcessNamesListFile(ucdSource, builder).ConfigureAwait(false);
await ProcessBlocksFile(ucdSource, builder).ConfigureAwait(false);
await ProcessBlocksFile(ucdSource, builder).ConfigureAwait(false);
await ProcessUnihanReadings(unihanSource, builder).ConfigureAwait(false);
await ProcessUnihanVariants(unihanSource, builder).ConfigureAwait(false);
await ProcessUnihanNumericValues(unihanSource, builder).ConfigureAwait(false);
@@ -255,12 +255,12 @@ namespace System.Unicode.Builder
if (length < 0) length = line.Length;
length -= 3;
characterData.RelatedCodePoints.Add(int.Parse(line.Substring(3, length), NumberStyles.HexNumber));
characterData.CrossRerefences.Add(int.Parse(line.Substring(3, length), NumberStyles.HexNumber));
}
else if (line[3] == '(')
{
bool hasBrackets = line[4] == '<';
int codePointOffset = line.IndexOf(hasBrackets ? "> - " : "- ", 4);
int codePointOffset = line.IndexOf(hasBrackets ? "> - " : "- ", 4);
if (codePointOffset < 0) throw new InvalidDataException();
codePointOffset += hasBrackets ? 4 : 2;
@@ -269,7 +269,7 @@ namespace System.Unicode.Builder
if (length < 0) throw new InvalidDataException();
length -= codePointOffset;
characterData.RelatedCodePoints.Add(int.Parse(line.Substring(codePointOffset, length), NumberStyles.HexNumber));
characterData.CrossRerefences.Add(int.Parse(line.Substring(codePointOffset, length), NumberStyles.HexNumber));
}
else throw new InvalidDataException();
}
+1 -1
View File
@@ -26,7 +26,7 @@ namespace System.Unicode
[ValueName("CS"), ValueName("Common_Separator"), Display(Name = "Common_Separator", Description = "commas, colons, and slashes")]
CommonSeparator,
[ValueName("NSM"), ValueName("Nonspacing_Mark"), Display(Name = "Nonspacing_Mark", Description = "any nonspacing mark")]
NonspacingMark,
NonSpacingMark,
[ValueName("BN"), ValueName("Boundary_Neutral"), Display(Name = "Boundary_Neutral", Description = "most format characters, control codes, or noncharacters")]
BoundaryNeutral,
[ValueName("B"), ValueName("Paragraph_Separator"), Display(Name = "Paragraph_Separator", Description = "various newline characters")]
+1 -1
View File
@@ -36,6 +36,6 @@ namespace System.Unicode
ContributoryProperties = 8192,
CoreProperties = 16384,
RelatedCodePoints = 32768,
CrossRerefences = 32768,
}
}
+2 -1
View File
@@ -36,6 +36,7 @@ namespace System.Unicode
public string SimpleTitleCaseMapping { get { return unicodeCharacterData?.SimpleTitleCaseMapping; } }
public ContributoryProperties ContributoryProperties { get { return unicodeCharacterData?.ContributoryProperties ?? 0; } }
public CoreProperties CoreProperties { get { return unicodeCharacterData?.CoreProperties ?? 0; } }
public UnicodeCrossReferenceCollection CrossRerefences { get { return new UnicodeCrossReferenceCollection(unicodeCharacterData?.CrossRerefences); } }
public string Definition { get { return unihanCharacterData?.Definition; } }
public string MandarinReading { get { return unihanCharacterData?.MandarinReading; } }
@@ -53,7 +54,7 @@ namespace System.Unicode
{
this.codePoint = codePoint;
this.name = UnicodeInfo.GetName(codePoint, unicodeCharacterData);
this.unicodeCharacterData = unicodeCharacterData;
this.unicodeCharacterData = unicodeCharacterData;
this.unihanCharacterData = unihanCharacterData;
this.block = block;
}
+3 -3
View File
@@ -27,7 +27,7 @@ namespace System.Unicode
public readonly ContributoryProperties ContributoryProperties;
public readonly CoreProperties CoreProperties;
public readonly int[] RelatedCodePoints; // NB: It seems that parsing NamesList is required in order to provide data for this field ?
public readonly int[] CrossRerefences; // NB: It seems that parsing NamesList is required in order to provide data for this field ?
internal UnicodeCharacterData
(
@@ -48,7 +48,7 @@ namespace System.Unicode
string simpleTitleCaseMapping,
ContributoryProperties contributoryProperties,
CoreProperties coreProperties,
int[] relatedCodePoints
int[] crossRerefences
)
{
this.CodePointRange = codePointRange;
@@ -68,7 +68,7 @@ namespace System.Unicode
this.SimpleTitleCaseMapping = simpleTitleCaseMapping;
this.ContributoryProperties = contributoryProperties;
this.CoreProperties = coreProperties;
this.RelatedCodePoints = relatedCodePoints;
this.CrossRerefences = crossRerefences;
}
public UnicodeRationalNumber? NumericValue { get { return NumericType != UnicodeNumericType.None ? numericValue : null as UnicodeRationalNumber?; } }
@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Unicode
{
public struct UnicodeCrossReferenceCollection : IList<int>
{
private static int[] EmptyArray = new int[0];
public struct Enumerator : IEnumerator<int>
{
private readonly int[] items;
private int index;
internal Enumerator(int[] items)
{
this.items = items;
this.index = -1;
}
public void Dispose() { }
public int Current { get { return items[index]; } }
object IEnumerator.Current { get { return Current; } }
public bool MoveNext() { return index < items.Length && ++index < items.Length; }
void IEnumerator.Reset() { this.index = -1; }
}
private readonly int[] items;
public UnicodeCrossReferenceCollection() { items = EmptyArray; }
internal UnicodeCrossReferenceCollection(int[] items) { this.items = items ?? EmptyArray; }
public int this[int index] { get { return items[index]; } }
int IList<int>.this[int index]
{
get { return items[index]; }
set { throw new NotSupportedException(); }
}
public int Count { get { return items.Length; } }
bool ICollection<int>.IsReadOnly { get { return true; } }
public void Add(int item) { throw new NotSupportedException(); }
public void Insert(int index, int item) { throw new NotSupportedException(); }
public bool Remove(int item) { throw new NotSupportedException(); }
public void RemoveAt(int index) { throw new NotSupportedException(); }
public void Clear() { throw new NotSupportedException(); }
public int IndexOf(int item) { return Array.IndexOf(items, item); }
public bool Contains(int item) { return IndexOf(item) >= 0; }
public void CopyTo(int[] array, int arrayIndex) { items.CopyTo(array, arrayIndex); }
public Enumerator GetEnumerator() { return new Enumerator(items); }
IEnumerator<int> IEnumerable<int>.GetEnumerator() { return GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
}
+12 -12
View File
@@ -14,7 +14,7 @@ namespace System.Unicode
{
public const string DefaultBlock = "No_Block";
private static readonly Version unicodeVersion;
private static readonly Version unicodeVersion;
private static readonly UnicodeCharacterData[] unicodeCharacterData;
private static readonly UnihanCharacterData[] unihanCharacterData;
private static readonly UnicodeBlock[] blocks;
@@ -34,7 +34,7 @@ namespace System.Unicode
{
int i;
if (reader.ReadByte() != 'U'
if (reader.ReadByte() != 'U'
| reader.ReadByte() != 'C'
| reader.ReadByte() != 'D')
throw new InvalidDataException();
@@ -57,7 +57,7 @@ namespace System.Unicode
++i;
break;
}
}
}
maxContiguousIndex = mci;
@@ -102,7 +102,7 @@ namespace System.Unicode
int length = reader.ReadByte();
byte @case = (byte)(length & 0xC0);
if (@case < 0x80) // Handles the case where only the name is present.
if (@case < 0x80) // Handles the case where only the name is present.
{
length = (length & 0x7F) + 1;
if (reader.Read(nameBuffer, 0, length) != length) throw new EndOfStreamException();
@@ -143,13 +143,13 @@ namespace System.Unicode
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;
int[] relatedCodePoints = (fields & UcdFields.RelatedCodePoints) != 0 ? new int[reader.ReadByte() + 1] : null;
int[] crossReferences = (fields & UcdFields.CrossRerefences) != 0 ? new int[reader.ReadByte() + 1] : null;
if (relatedCodePoints != null)
if (crossReferences != null)
{
for (int i = 0; i < relatedCodePoints.Length; ++i)
relatedCodePoints[i] = ReadCodePoint(reader);
}
for (int i = 0; i < crossReferences.Length; ++i)
crossReferences[i] = ReadCodePoint(reader);
}
return new UnicodeCharacterData
(
@@ -170,7 +170,7 @@ namespace System.Unicode
simpleTitleCaseMapping,
contributoryProperties,
coreProperties,
relatedCodePoints
crossReferences
);
}
@@ -364,7 +364,7 @@ namespace System.Unicode
{
if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint);
else return GetName(codePoint, FindUnicodeCodePoint(codePoint));
}
}
internal static string GetName(int codePoint, UnicodeCharacterData characterData)
{
@@ -372,7 +372,7 @@ namespace System.Unicode
else if (HangulInfo.IsHangul(codePoint)) return HangulInfo.GetHangulName((char)codePoint);
else if (characterData.Name != null) return characterData.Name + "-" + codePoint.ToString("X4");
else return null;
}
}
public static UnicodeBlock[] GetBlocks()
{
@@ -66,6 +66,7 @@
<Compile Include="CodePointEnumerator.cs" />
<Compile Include="CoreProperties.cs" />
<Compile Include="HangulInfo.cs" />
<Compile Include="UnicodeCrossReferenceCollection.cs" />
<Compile Include="UnicodeNameAliasCollection.cs" />
<Compile Include="UcdFields.cs" />
<Compile Include="EnumHelper.cs" />
@@ -58,10 +58,7 @@ namespace System.Unicode
public int IndexOf(UnicodeNameAlias item) { return Array.IndexOf(items, item); }
public bool Contains(UnicodeNameAlias item) { return IndexOf(item) >= 0; }
public void CopyTo(UnicodeNameAlias[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public void CopyTo(UnicodeNameAlias[] array, int arrayIndex) { items.CopyTo(array, arrayIndex); }
public Enumerator GetEnumerator() { return new Enumerator(items); }