Explorar o código

2004-01-13 Gonzalo Paniagua Javier <[email protected]>

	* StringBuilder.cs: added checks for null in a few Append methods.

svn path=/trunk/mcs/; revision=22032
Gonzalo Paniagua Javier %!s(int64=22) %!d(string=hai) anos
pai
achega
ad730dfe6b

+ 3 - 0
mcs/class/corlib/System.Text/ChangeLog

@@ -1,3 +1,6 @@
+2004-01-13  Gonzalo Paniagua Javier <[email protected]>
+
+	* StringBuilder.cs: added checks for null in a few Append methods.
 
 Tue Jan 13 22:23:25 CET 2004 Paolo Molaro <[email protected]>
 

+ 22 - 6
mcs/class/corlib/System.Text/StringBuilder.cs

@@ -268,6 +268,9 @@ namespace System.Text {
 		/* The Append Methods */
 		public StringBuilder Append (char[] value) 
 		{
+			if (value == null)
+				return this;
+
 			int needed_cap = _length + value.Length;
 			if (null != _cached_str || _str.Length < needed_cap)
 				InternalEnsureCapacity (needed_cap);
@@ -282,6 +285,9 @@ namespace System.Text {
 		
 		public StringBuilder Append (string value) 
 		{
+			if (value == null)
+				return this;
+
 			int needed_cap = _length + value.Length;
 			if (null != _cached_str || _str.Length < needed_cap)
 				InternalEnsureCapacity (needed_cap);
@@ -324,6 +330,9 @@ namespace System.Text {
 		}
 
 		public StringBuilder Append (object value) {
+			if (value == null)
+				return this;
+
 			return Append (value.ToString());
 		}
 
@@ -378,16 +387,16 @@ namespace System.Text {
 
 		public StringBuilder Append( char[] value, int startIndex, int charCount ) 
 		{
-			if ((charCount < 0 || startIndex < 0) || (charCount + startIndex > value.Length)) 
-				throw new ArgumentOutOfRangeException();
-			
-			if (value == null) 
-			{
+			if (value == null) {
 				if (!(startIndex == 0 && charCount == 0))
-					throw new ArgumentNullException();
+					throw new ArgumentNullException ("value");
 
 				return this;
 			}
+
+			if ((charCount < 0 || startIndex < 0) || (charCount + startIndex > value.Length)) 
+				throw new ArgumentOutOfRangeException();
+			
 			
 			InternalEnsureCapacity (_length + charCount);
 			
@@ -400,6 +409,13 @@ namespace System.Text {
 
 		public StringBuilder Append (string value, int startIndex, int count) 
 		{
+			if (value == null) {
+				if (startIndex != 0 && count != 0)
+					throw new ArgumentNullException ("value");
+					
+				return this;
+			}
+
 			if ((count < 0 || startIndex < 0) || (startIndex + count > value.Length))
 				throw new ArgumentOutOfRangeException();