String.Split(char[],int,StringSplitOptions) should remove empty entries while
[mono.git] / mcs / class / corlib / System / CStreamWriter.cs
index c9d77f0ca68e23bdd3540cc3d0c87050bd360096..659e9046a6d548b13f607bee12384f051c512dc8 100644 (file)
@@ -49,22 +49,51 @@ namespace System.IO {
                {
                        if (count <= 0)
                                return;
+                       
+                       if (!driver.Initialized) {
+                               try {
+                                       base.Write (buffer, index, count);
+                               } catch (IOException) {
+                               }
+                               
+                               return;
+                       }
+                       
+                       lock (this) {
+                               int last = index + count;
+                               int i = index;
+                               int n = 0;
+                               char c;
 
-                       if (driver.Initialized){
-                               lock (this){
-                                       for (int i = 0; i < count; i++) {
-                                               try {
-                                                       char val = buffer [index + i];
-                                                       if (driver.NotifyWrite (val))
-                                                               InternalWriteChar (val);
-                                               } catch (IOException){
+                               do {
+                                       c = buffer [i++];
+
+                                       if (driver.IsSpecialKey (c)) {
+                                               // flush what we have
+                                               if (n > 0) {
+                                                       try {
+                                                               base.Write (buffer, index, n);
+                                                       } catch (IOException) {
+                                                       }
+                                                       
+                                                       n = 0;
                                                }
+
+                                               // write the special key
+                                               driver.WriteSpecialKey (c);
+
+                                               index = i;
+                                       } else {
+                                               n++;
+                                       }
+                               } while (i < last);
+
+                               if (n > 0) {
+                                       // write out the remainder of the buffer
+                                       try {
+                                               base.Write (buffer, index, n);
+                                       } catch (IOException) {
                                        }
-                               }
-                       } else {
-                               try {
-                                       base.Write (buffer, index, count);
-                               } catch (IOException){
                                }
                        }
                }
@@ -73,7 +102,9 @@ namespace System.IO {
                {
                        lock (this) {
                                try {
-                                       if (driver.NotifyWrite (val))
+                                       if (driver.IsSpecialKey (val))
+                                               driver.WriteSpecialKey (val);
+                                       else
                                                InternalWriteChar (val);
                                } catch (IOException) {
                                }
@@ -84,7 +115,9 @@ namespace System.IO {
                {
                        lock (this) {
                                ConsoleKeyInfo copy = new ConsoleKeyInfo (key);
-                               if (driver.NotifyWrite (copy))
+                               if (driver.IsSpecialKey (copy))
+                                       driver.WriteSpecialKey (copy);
+                               else
                                        InternalWriteChar (copy.KeyChar);
                        }
                }
@@ -105,6 +138,14 @@ namespace System.IO {
                        }
                }
 
+               public void InternalWriteChars (char [] buffer, int n)
+               {
+                       try {
+                               base.Write (buffer, 0, n);
+                       } catch (IOException) {
+                       }
+               }
+
                public override void Write (char [] val)
                {
                        Write (val, 0, val.Length);