String.Split(char[],int,StringSplitOptions) should remove empty entries while
[mono.git] / mcs / class / corlib / System / CStreamWriter.cs
index 9b9f81baed02408cfeec7b6714d3c43b2ae58eb2..659e9046a6d548b13f607bee12384f051c512dc8 100644 (file)
@@ -60,51 +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.IsSpecialKey (c)) {
-                                                       // flush what we have
+                                       c = buffer [i++];
+
+                                       if (driver.IsSpecialKey (c)) {
+                                               // flush what we have
+                                               if (n > 0) {
                                                        try {
-                                                               base.Write (buf, 0, j);
+                                                               base.Write (buffer, index, n);
                                                        } catch (IOException) {
                                                        }
+                                                       
+                                                       n = 0;
+                                               }
 
-                                                       j = 0;
+                                               // write the special key
+                                               driver.WriteSpecialKey (c);
 
-                                                       // write the special key
-                                                       driver.WriteSpecialKey (c);
-                                               } else {
-                                                       buf[j++] = c;
-                                                       break;
-                                               }
-                                       } while (i < count);
-                                       
-                                       if (j > 0 && (j == buf.Length || i == count)) {
-                                               // buffer is full or no more data to buffer
-                                               // write it out
-                                               try {
-                                                       base.Write (buf, 0, j);
-                                               } catch (IOException) {
-                                               }
-                                               
-                                               j = 0;
+                                               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) {
+                                       }
+                               }
                        }
                }
 
@@ -148,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);