diff --git a/Utilities/ByteUtils/ByteWriter.cs b/Utilities/ByteUtils/ByteWriter.cs index 0de2a41..54715b3 100644 --- a/Utilities/ByteUtils/ByteWriter.cs +++ b/Utilities/ByteUtils/ByteWriter.cs @@ -134,10 +134,22 @@ namespace Utilities } } + public static void WriteUTF8String(Stream stream, string value) + { + byte[] bytes = UnicodeEncoding.UTF8.GetBytes(value); + stream.Write(bytes, 0, bytes.Length); + } + public static void WriteUTF16String(Stream stream, string value) { byte[] bytes = UnicodeEncoding.Unicode.GetBytes(value); stream.Write(bytes, 0, bytes.Length); } + + public static void WriteUTF16BEString(Stream stream, string value) + { + byte[] bytes = UnicodeEncoding.BigEndianUnicode.GetBytes(value); + stream.Write(bytes, 0, bytes.Length); + } } } diff --git a/Utilities/Generics/KeyValuePairList.cs b/Utilities/Generics/KeyValuePairList.cs index 093c6e1..fc5f093 100644 --- a/Utilities/Generics/KeyValuePairList.cs +++ b/Utilities/Generics/KeyValuePairList.cs @@ -6,6 +6,14 @@ namespace Utilities { public partial class KeyValuePairList : List> { + public KeyValuePairList() + { + } + + public KeyValuePairList(List> collection) : base(collection) + { + } + public bool ContainsKey(TKey key) { return (this.IndexOfKey(key) != -1); @@ -97,5 +105,10 @@ namespace Utilities return comparer.Compare(a.Key, b.Key); }); } + + public new KeyValuePairList GetRange(int index, int count) + { + return new KeyValuePairList(base.GetRange(index, count)); + } } } diff --git a/Utilities/Generics/Map.cs b/Utilities/Generics/Map.cs index 5a83dc5..98f0c34 100644 --- a/Utilities/Generics/Map.cs +++ b/Utilities/Generics/Map.cs @@ -35,6 +35,36 @@ namespace Utilities return m_reverse.ContainsKey(value); } + public bool TryGetKey(T2 value, out T1 key) + { + return m_reverse.TryGetValue(value, out key); + } + + public bool TryGetValue(T1 key, out T2 value) + { + return m_forward.TryGetValue(key, out value); + } + + public void RemoveKey(T1 key) + { + T2 value; + if (m_forward.TryGetValue(key, out value)) + { + m_forward.Remove(key); + m_reverse.Remove(value); + } + } + + public void RemoveValue(T2 value) + { + T1 key; + if (m_reverse.TryGetValue(value, out key)) + { + m_forward.Remove(key); + m_reverse.Remove(value); + } + } + public T2 this[T1 key] { get diff --git a/Utilities/Generics/SortedList.cs b/Utilities/Generics/SortedList.cs index b8d5f2d..492b431 100644 --- a/Utilities/Generics/SortedList.cs +++ b/Utilities/Generics/SortedList.cs @@ -105,15 +105,25 @@ namespace Utilities public static int FirstIndexOf(List list, Comparer comparer, T item) { - int insertIndex = FindIndexForSortedInsert(list, comparer, item); + return FirstIndexOf(list, comparer.Compare, item); + } + + public static int FindIndexForSortedInsert(List list, Comparer comparer, T item) + { + return FindIndexForSortedInsert(list, comparer.Compare, item); + } + + public static int FirstIndexOf(List list, Comparison compare, T item) + { + int insertIndex = FindIndexForSortedInsert(list, compare, item); if (insertIndex == list.Count) { return -1; } - if (comparer.Compare(item, list[insertIndex]) == 0) + if (compare(item, list[insertIndex]) == 0) { int index = insertIndex; - while (index > 0 && comparer.Compare(item, list[index - 1]) == 0) + while (index > 0 && compare(item, list[index - 1]) == 0) { index--; } @@ -122,7 +132,7 @@ namespace Utilities return -1; } - public static int FindIndexForSortedInsert(List list, Comparer comparer, T item) + public static int FindIndexForSortedInsert(List list, Comparison compare, T item) { if (list.Count == 0) { @@ -136,7 +146,7 @@ namespace Utilities { int middleIndex = (lowerIndex + upperIndex) / 2; T middle = list[middleIndex]; - comparisonResult = comparer.Compare(middle, item); + comparisonResult = compare(middle, item); if (comparisonResult == 0) { return middleIndex; @@ -154,7 +164,7 @@ namespace Utilities // At this point any entry following 'middle' is greater than 'item', // and any entry preceding 'middle' is lesser than 'item'. // So we either put 'item' before or after 'middle'. - comparisonResult = comparer.Compare(list[lowerIndex], item); + comparisonResult = compare(list[lowerIndex], item); if (comparisonResult < 0) // middle < item { return lowerIndex + 1; diff --git a/Utilities/IFileSystem/FileSystem.cs b/Utilities/IFileSystem/FileSystem.cs index c31231a..1245005 100644 --- a/Utilities/IFileSystem/FileSystem.cs +++ b/Utilities/IFileSystem/FileSystem.cs @@ -74,6 +74,11 @@ namespace Utilities get; } + public abstract bool SupportsNamedStreams + { + get; + } + public static string GetParentDirectory(string path) { if (path == String.Empty) diff --git a/Utilities/IFileSystem/IFileSystem.cs b/Utilities/IFileSystem/IFileSystem.cs index c1f99eb..9894ce8 100644 --- a/Utilities/IFileSystem/IFileSystem.cs +++ b/Utilities/IFileSystem/IFileSystem.cs @@ -78,5 +78,14 @@ namespace Utilities { get; } + + /// + /// Indicates support for opening named streams (alternate data streams). + /// Named streams are opened using the filename:stream syntax. + /// + bool SupportsNamedStreams + { + get; + } } }