From: Ben Maurer Date: Sun, 5 Sep 2004 17:27:23 +0000 (-0000) Subject: 2004-09-05 Ben Maurer X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=a0de536a5f91126cb04cb48257503089c3ce2908;hp=84310407a6a173af96bdddfbc9e5e24445a8d589;p=mono.git 2004-09-05 Ben Maurer * StringReader.cs (StreamReader): remove sourceChars and disposed variables (Read): Copy directly from the string, rather than a char [] (Dispose, CheckObjectDisposedException): the flag for being disposed is now source == null. svn path=/trunk/mcs/; revision=33373 --- diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index 4412e03bfe9..cf26263071a 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,11 @@ +2004-09-05 Ben Maurer + + * StringReader.cs (StreamReader): remove sourceChars and disposed + variables + (Read): Copy directly from the string, rather than a char [] + (Dispose, CheckObjectDisposedException): the flag for being + disposed is now source == null. + 2004-09-04 Gonzalo Paniagua Javier * Stream.cs: Close() does not call Flush(). Fixes bug #65340. diff --git a/mcs/class/corlib/System.IO/StringReader.cs b/mcs/class/corlib/System.IO/StringReader.cs index b66167d910b..c1b334d7296 100644 --- a/mcs/class/corlib/System.IO/StringReader.cs +++ b/mcs/class/corlib/System.IO/StringReader.cs @@ -37,12 +37,9 @@ namespace System.IO { [Serializable] public class StringReader : TextReader { - private string source; - private char[] sourceChars; - - private int nextChar; - private int sourceLength; - private bool disposed = false; + string source; + int nextChar; + int sourceLength; public StringReader( string s ) { @@ -52,17 +49,16 @@ namespace System.IO { this.source = s; nextChar = 0; sourceLength = s.Length; - sourceChars = s.ToCharArray(); } - public override void Close() { - Dispose( true ); - disposed = true; + public override void Close () + { + Dispose (true); } protected override void Dispose (bool disposing) { - sourceChars = null; + source = null; base.Dispose (disposing); } @@ -94,28 +90,26 @@ namespace System.IO { // the actual number of characters read, or zero if the end of the string // has been reached and no characters are read. - public override int Read ([In, Out] char[] buffer, int index, int count ) + public override int Read ([In, Out] char[] buffer, int index, int count) { CheckObjectDisposedException (); - if( buffer == null ) { + if (buffer == null) throw new ArgumentNullException ("buffer"); - } else if( buffer.Length - index < count ) { - throw new ArgumentException(); - } else if( index < 0 || count < 0 ) { - throw new ArgumentOutOfRangeException(); - } + if (buffer.Length - index < count) + throw new ArgumentException (); + if (index < 0 || count < 0) + throw new ArgumentOutOfRangeException (); int charsToRead; // reordered to avoir possible integer overflow - if (nextChar > sourceLength - count) { + if (nextChar > sourceLength - count) charsToRead = sourceLength - nextChar; - } else { + else charsToRead = count; - } - - Array.Copy(sourceChars, nextChar, buffer, index, charsToRead ); + + source.CopyTo (nextChar, buffer, index, charsToRead); nextChar += charsToRead; @@ -175,10 +169,9 @@ namespace System.IO { private void CheckObjectDisposedException () { - if (disposed) { + if (source == null) throw new ObjectDisposedException ("StringReader", Locale.GetText ("Cannot read from a closed StringReader")); - } } } }