Browse Source

Updated Utilities

Tal Aloni 5 years ago
parent
commit
e92c3fb85a
2 changed files with 42 additions and 0 deletions
  1. 12 0
      Utilities/ByteUtils/ByteWriter.cs
  2. 30 0
      Utilities/Generics/Map.cs

+ 12 - 0
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);
+        }
     }
 }

+ 30 - 0
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