String.Split(char[],int,StringSplitOptions) should remove empty entries while
[mono.git] / mcs / class / corlib / System / CStreamWriter.cs
index 5ce0af8a403eaf955f925145958fcdaaa91f5982..659e9046a6d548b13f607bee12384f051c512dc8 100644 (file)
@@ -60,39 +60,41 @@ namespace System.IO {
                        }
                        
                        lock (this) {
-                               int i = 0, j = 0;
-                               char []buf;
+                               int last = index + count;
+                               int i = index;
+                               int n = 0;
                                char c;
-                               
-                               // The idea here is that we want to limit our temp
-                               // buffer size - I picked 1k because the underlying
-                               // stream implementation seems to break writes into
-                               // 1k byte chunks.
-                               if (count > 1024)
-                                       buf = new char[1024];
-                               else
-                                       buf = new char[count];
-                               
+
                                do {
-                                       do {
-                                               c = buffer [index + i++];
-                                               
-                                               if (driver.NotifyWrite (c)) {
-                                                       buf[j++] = c;
-                                                       break;
-                                               }
-                                       } while (i < count);
-                                       
-                                       if (j == buf.Length || i == count) {
-                                               // temp buffer is full, write it out
-                                               try {
-                                                       base.Write (buf, 0, j);
-                                               } catch (IOException) {
+                                       c = buffer [i++];
+
+                                       if (driver.IsSpecialKey (c)) {
+                                               // flush what we have
+                                               if (n > 0) {
+                                                       try {
+                                                               base.Write (buffer, index, n);
+                                                       } catch (IOException) {
+                                                       }
+                                                       
+                                                       n = 0;
                                                }
-                                               
-                                               j = 0;
+
+                                               // write the special key
+                                               driver.WriteSpecialKey (c);
+
+                                               index = i;
+                                       } else {
+                                               n++;
                                        }
-                               } while (i < count);
+                               } while (i < last);
+
+                               if (n > 0) {
+                                       // write out the remainder of the buffer
+                                       try {
+                                               base.Write (buffer, index, n);
+                                       } catch (IOException) {
+                                       }
+                               }
                        }
                }
 
@@ -100,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) {
                                }
@@ -111,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);
                        }
                }
@@ -132,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);