changeset 84:146a8d224d86

Added ArrayUtil.Remove, fixed some exceptons
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 05 Jun 2014 00:21:02 +0200
parents 4ca44dd25a6a
children 40715b34d0d3
files Net/HTTP.cs Util/ArrayUtil.cs
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Net/HTTP.cs	Sun Feb 23 16:59:47 2014 +0100
+++ b/Net/HTTP.cs	Thu Jun 05 00:21:02 2014 +0200
@@ -156,7 +156,7 @@
 				Context.SendHeader("Transfer-Encoding", "chunked");
 				OutputStream = Context.BeginResponseData();
 				Mode = HTTPResponseStreamMode.Chunked;
-				oldbuffer.WriteTo(this);
+				if (oldbuffer != null) oldbuffer.WriteTo(this);
 			}
 
 			public override void Write(byte[] buffer, int offset, int count) {
--- a/Util/ArrayUtil.cs	Sun Feb 23 16:59:47 2014 +0100
+++ b/Util/ArrayUtil.cs	Thu Jun 05 00:21:02 2014 +0200
@@ -158,9 +158,24 @@
 			}
 		}
 		public static int AddUnique<T>(ref T[] array, T item) {
+			if (array == null) {
+				array = new T[] { item };
+				return 0;
+			} else {
+				int index = Array.IndexOf(array, item);
+				if (index == -1) index = Add(ref array, item);
+				return index;
+			}
+		}
+		public static Boolean Remove<T>(ref T[] array, T item) {
+			if (array == null) return false;
 			int index = Array.IndexOf(array, item);
-			if (index == -1) index = Add(ref array, item);
-			return index;
+			if (index == -1) return false;
+			T[] newarray = new T[array.Length - 1];
+			if (index > 0) Array.Copy(array, 0, newarray, 0, index);
+			if (index < array.Length - 1) Array.Copy(array, index + 1, newarray, index, array.Length - index - 1);
+			array = newarray;
+			return true;
 		}
 	}
 }