Exposed the name aliases and refactored argument exceptions.

This commit is contained in:
GoldenCrystal
2014-11-21 16:25:57 +01:00
parent 343dc823cf
commit d5131ef008
12 changed files with 96 additions and 23 deletions
@@ -74,8 +74,8 @@ namespace UnicodeCharacterInspector
public void CopyTo(CharacterViewModel[] array, int arrayIndex)
{
if (array == null) throw new ArgumentNullException("array");
if (arrayIndex < 0) throw new ArgumentOutOfRangeException("arrayIndex");
if (array == null) throw new ArgumentNullException(nameof(array));
if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if (array.Length < arrayIndex + owner.codePoints.Length) throw new ArgumentException();
for (int i = 0, j = arrayIndex; i < owner.codePoints.Length; ++i, ++j)
@@ -175,7 +175,7 @@ namespace UnicodeCharacterInspector
set
{
if (selectedCharacterIndex < -1 || selectedCharacterIndex >= codePoints.Length)
throw new ArgumentOutOfRangeException("value");
throw new ArgumentOutOfRangeException(nameof(value));
if (value != selectedCharacterIndex)
{
@@ -11,7 +11,7 @@ namespace System.Unicode.Builder
{
public static void WriteUInt24(this BinaryWriter writer, int value)
{
if (value < 0 || value > 0xFFFFFF) throw new ArgumentOutOfRangeException("value");
if (value < 0 || value > 0xFFFFFF) throw new ArgumentOutOfRangeException(nameof(value));
writer.Write((byte)(value));
writer.Write((byte)(value >> 8));
@@ -27,7 +27,7 @@ namespace System.Unicode.Builder
/// <param name="value">The value to write</param>
public static void WriteCodePoint(this BinaryWriter writer, int value)
{
if (value < 0 || value > 0x40407F) throw new ArgumentOutOfRangeException("value");
if (value < 0 || value > 0x40407F) throw new ArgumentOutOfRangeException(nameof(value));
if (value < 0xA0) writer.Write((byte)value);
else if (value < 0x20A0)
@@ -72,7 +72,7 @@ namespace System.Unicode.Builder
{
var bytes = Encoding.UTF8.GetBytes(name);
if (bytes.Length > 128) throw new InvalidOperationException("Did not expect UTF-8 encoded name to be longer than 128 bytes.");
writer.Write((byte)(name.Length - 1)); // The most significant bit will always be cleared, because it will be used for other cases.
writer.Write((byte)(name.Length - 1)); // The most significant bit will always be cleared, because it will be used for other cases.
writer.Write(bytes);
}
@@ -83,8 +83,8 @@ namespace System.Unicode.Builder
/// <param name="length">The length to write.</param>
public static void WritePackedLength(this BinaryWriter writer, byte extraBits, int length)
{
if (extraBits > 3) throw new ArgumentOutOfRangeException("extraBits");
if (length < 1 || length > 64) throw new ArgumentOutOfRangeException("length");
if (extraBits > 3) throw new ArgumentOutOfRangeException(nameof(extraBits));
if (length < 1 || length > 64) throw new ArgumentOutOfRangeException(nameof(length));
writer.Write((byte)((extraBits << 6) | (length - 1)));
}
@@ -46,7 +46,7 @@ namespace System.Unicode.Builder
{
if (!Enum.IsDefined(typeof(UnicodeCategory), value))
{
throw new ArgumentOutOfRangeException("value");
throw new ArgumentOutOfRangeException(nameof(value));
}
category = value;
}
+4 -4
View File
@@ -40,16 +40,16 @@ namespace System.Unicode.Builder
private void EnsureExtraCapacity(int count)
{
if (count < 0) throw new ArgumentOutOfRangeException("requiredExtraCapacity");
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
if (buffer.Length < checked(length + count))
Array.Resize(ref buffer, Math.Max(length + count, buffer.Length << 1));
}
public void Append(byte[] value, int startIndex, int count)
{
if (value == null) throw new ArgumentNullException("value");
if (startIndex >= value.Length) throw new ArgumentOutOfRangeException("startIndex");
if (checked(count += startIndex) > value.Length) throw new ArgumentOutOfRangeException("count");
if (value == null) throw new ArgumentNullException(nameof(value));
if (startIndex >= value.Length) throw new ArgumentOutOfRangeException(nameof(startIndex));
if (checked(count += startIndex) > value.Length) throw new ArgumentOutOfRangeException(nameof(count));
EnsureExtraCapacity(value.Length);
+1 -1
View File
@@ -15,7 +15,7 @@ namespace System.Unicode
public CodePointEnumerator(string text)
{
if (text == null) throw new ArgumentNullException("text");
if (text == null) throw new ArgumentNullException(nameof(text));
this.text = text;
this.current = 0;
+3 -3
View File
@@ -44,9 +44,9 @@ namespace System.Unicode
{
int sIndex = codePoint - SBase;
if (sIndex < 0 || sIndex >= SCount) throw new ArgumentOutOfRangeException("codePoint");
if (sIndex < 0 || sIndex >= SCount) throw new ArgumentOutOfRangeException(nameof(codePoint));
int lIndex = sIndex / NCount;
int lIndex = sIndex / NCount;
int vIndex = (sIndex % NCount) / TCount;
int tIndex = sIndex % TCount;
@@ -56,6 +56,6 @@ namespace System.Unicode
internal static bool IsHangul(int codePoint)
{
return codePoint >= SBase && codePoint <= SBase + SCount;
}
}
}
}
+1
View File
@@ -18,6 +18,7 @@ namespace System.Unicode
public int CodePoint { get { return codePoint; } }
public string Name { get { return name; } }
public UnicodeNameAliasCollection NameAliases { get { return new UnicodeNameAliasCollection(unicodeCharacterData?.NameAliases); } }
public UnicodeCategory Category { get { return unicodeCharacterData?.Category ?? UnicodeCategory.OtherNotAssigned; } }
public string Block { get { return block ?? UnicodeInfo.DefaultBlock; } }
+3 -3
View File
@@ -41,7 +41,7 @@ namespace System.Unicode
public UnicodeCharacterRange(int codePoint)
{
if (codePoint < 0 || codePoint > 0x10FFFF) throw new ArgumentOutOfRangeException("codePoint");
if (codePoint < 0 || codePoint > 0x10FFFF) throw new ArgumentOutOfRangeException(nameof(codePoint));
FirstCodePoint = codePoint;
LastCodePoint = codePoint;
@@ -49,8 +49,8 @@ namespace System.Unicode
public UnicodeCharacterRange(int firstCodePoint, int lastCodePoint)
{
if (firstCodePoint < 0 || firstCodePoint > 0x10FFFF) throw new ArgumentOutOfRangeException("firstCodePoint");
if (lastCodePoint < firstCodePoint || lastCodePoint > 0x10FFFF) throw new ArgumentOutOfRangeException("lastCodePoint");
if (firstCodePoint < 0 || firstCodePoint > 0x10FFFF) throw new ArgumentOutOfRangeException(nameof(firstCodePoint));
if (lastCodePoint < firstCodePoint || lastCodePoint > 0x10FFFF) throw new ArgumentOutOfRangeException(nameof(lastCodePoint));
FirstCodePoint = firstCodePoint;
LastCodePoint = lastCodePoint;
@@ -66,6 +66,7 @@
<Compile Include="CodePointEnumerator.cs" />
<Compile Include="CoreProperties.cs" />
<Compile Include="HangulInfo.cs" />
<Compile Include="UnicodeNameAliasCollection.cs" />
<Compile Include="UcdFields.cs" />
<Compile Include="EnumHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Unicode
{
public struct UnicodeNameAliasCollection : IList<UnicodeNameAlias>
{
public struct Enumerator : IEnumerator<UnicodeNameAlias>
{
private readonly UnicodeNameAlias[] items;
private int index;
internal Enumerator(UnicodeNameAlias[] items)
{
this.items = items;
this.index = -1;
}
public void Dispose() { }
public UnicodeNameAlias 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 UnicodeNameAlias[] items;
public UnicodeNameAliasCollection() { items = UnicodeNameAlias.EmptyArray; }
internal UnicodeNameAliasCollection(UnicodeNameAlias[] items) { this.items = items ?? UnicodeNameAlias.EmptyArray; }
public UnicodeNameAlias this[int index] { get { return items[index]; } }
UnicodeNameAlias IList<UnicodeNameAlias>.this[int index]
{
get { return items[index]; }
set { throw new NotSupportedException(); }
}
public int Count { get { return items.Length; } }
bool ICollection<UnicodeNameAlias>.IsReadOnly { get { return true; } }
public void Add(UnicodeNameAlias item) { throw new NotSupportedException(); }
public void Insert(int index, UnicodeNameAlias item) { throw new NotSupportedException(); }
public bool Remove(UnicodeNameAlias item) { throw new NotSupportedException(); }
public void RemoveAt(int index) { throw new NotSupportedException(); }
public void Clear() { throw new NotSupportedException(); }
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 Enumerator GetEnumerator() { return new Enumerator(items); }
IEnumerator<UnicodeNameAlias> IEnumerable<UnicodeNameAlias>.GetEnumerator() { return GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace System.Unicode
{
public static UnicodeRationalNumber Parse(string s)
{
if (s == null) throw new ArgumentNullException("s");
if (s == null) throw new ArgumentNullException(nameof(s));
if (s.Length == 0) throw new ArgumentException();
int fractionBarIndex = s.IndexOf('/');
+2 -2
View File
@@ -68,7 +68,7 @@ namespace System.Unicode
}
}
throw new ArgumentOutOfRangeException("codePoint");
throw new ArgumentOutOfRangeException(nameof(codePoint));
}
internal static int UnpackCodePoint(int packedCodePoint)
@@ -81,7 +81,7 @@ namespace System.Unicode
else if (packedCodePoint < 0x1F800) return packedCodePoint - 0xFD00;
else if (packedCodePoint < 0x20000) return packedCodePoint + 0x10000;
}
throw new ArgumentOutOfRangeException("packedCodePoint");
throw new ArgumentOutOfRangeException(nameof(packedCodePoint));
}
}
}