Slightly tweaked the variable length encoding used for code points.
This commit is contained in:
@@ -29,17 +29,23 @@ namespace System.Unicode.Builder
|
||||
{
|
||||
if (value < 0 || value > 0x40407F) throw new ArgumentOutOfRangeException("value");
|
||||
|
||||
if (value < 0x80) writer.Write((byte)value);
|
||||
else if (value < 0x4080)
|
||||
if (value < 0xA0) writer.Write((byte)value);
|
||||
else if (value < 0x20A0)
|
||||
{
|
||||
value -= 0x80;
|
||||
writer.Write((byte)((byte)(value >> 8) | 0x80));
|
||||
value -= 0xA0;
|
||||
writer.Write((byte)((byte)(value >> 8) | 0xA0));
|
||||
writer.Write((byte)value);
|
||||
}
|
||||
else if (value < 0x40A0)
|
||||
{
|
||||
value -= 0x20A0;
|
||||
writer.Write((byte)((byte)(value >> 8) | 0xC0));
|
||||
writer.Write((byte)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
value -= 0x4080;
|
||||
writer.Write((byte)((byte)(value >> 16) | 0xC0));
|
||||
value -= 0x40A0;
|
||||
writer.Write((byte)((byte)(value >> 16) | 0xE0));
|
||||
writer.Write((byte)(value >> 8));
|
||||
writer.Write((byte)value);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace System.Unicode.Tests
|
||||
|
||||
var data = (await UnicodeDataManager.BuildDataAsync(source)).ToUnicodeData();
|
||||
|
||||
Assert.AreEqual((int)'\t', data.GetUnicodeData('\t').CodePointRange.FirstCodePoint);
|
||||
Assert.AreEqual((int)'\t', data.Get('\t').CodePointRange.FirstCodePoint);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -91,14 +91,18 @@ namespace System.Unicode
|
||||
{
|
||||
byte b = reader.ReadByte();
|
||||
|
||||
if (b < 128) return b;
|
||||
else if ((b & 0x40) == 0)
|
||||
if (b < 0xA0) return b;
|
||||
else if (b < 0xC0)
|
||||
{
|
||||
return 128 + (((b & 0x3F) << 8) | reader.ReadByte());
|
||||
}
|
||||
return 0xA0 + (((b & 0x1F) << 8) | reader.ReadByte());
|
||||
}
|
||||
else if (b < 0xE0)
|
||||
{
|
||||
return 0x20A0 + (((b & 0x1F) << 8) | reader.ReadByte());
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0x4080 + (((((b & 0x3F) << 8) | reader.ReadByte()) << 8) | reader.ReadByte());
|
||||
return 0x40A0 + (((((b & 0x1F) << 8) | reader.ReadByte()) << 8) | reader.ReadByte());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +133,7 @@ namespace System.Unicode
|
||||
return null;
|
||||
}
|
||||
|
||||
public UnicodeCharacterData GetUnicodeData(int codePoint)
|
||||
public UnicodeCharacterData Get(int codePoint)
|
||||
{
|
||||
return FindCodePoint(codePoint);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user