[Mono-list] [patch] integer formatting -- finally

Daniel Stodden stodden@in.tum.de
21 Feb 2002 00:11:16 +0100


--=-90mltn9ZbTEqjQIHWnhi
Content-Type: multipart/mixed; boundary="=-PjSpYbaYFkwZTm8jFbBk"


--=-PjSpYbaYFkwZTm8jFbBk
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Wed, 2002-02-20 at 22:51, Daniel Stodden wrote:
>=20
> hi.
>=20
> i've got a few modifications to
> System.Globalization.(Number|DateTime)FormatInfo which i think should
> correct part/most of the //LAMESPEC uncertainties as described in
> http://lists.ximian.com/archives/public/mono-list/2001-July/000794.html
>=20
> plus some related cleanup for the simple types.


hat to recover this manually. hope i didn't miss anything...

daniel

--=20
___________________________________________________________________________
 mailto:stodden@in.tum.de

--=-PjSpYbaYFkwZTm8jFbBk
Content-Disposition: attachment; filename=corlib2.patch
Content-Type: text/x-patch; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

diff -u 'System.Globalization/DateTimeFormatInfo.cs' './System.Globalizatio=
n/DateTimeFormatInfo.cs'
Index: ./System.Globalization/DateTimeFormatInfo.cs
--- ./System.Globalization/DateTimeFormatInfo.cs	Sun Nov  4 14:00:36 2001
+++ ./System.Globalization/DateTimeFormatInfo.cs	Wed Feb 20 20:40:14 2002
@@ -81,21 +81,19 @@
 			_MonthNames =3D INVARIANT_MONTH_NAMES;
 		}
 			=09
-		// LAMESPEC: this is not in ECMA specs=0D
-		public static DateTimeFormatInfo GetInstance(IFormatProvider provider)=0D
-		{=0D
-			if (provider !=3D null)=20=0D
-			{=0D
-				if (provider is DateTimeFormatInfo) return (DateTimeFormatInfo) provid=
er;=0D
-				if (provider is CultureInfo) return ((CultureInfo) provider).DateTimeF=
ormat;=0D
-				return null;=0D
-			}=0D
-			else=20=0D
-			{=0D
-				return CurrentInfo;=0D
-			}=0D
-		}=0D
-=0D
+		// LAMESPEC: this is not in ECMA specs
+		public static DateTimeFormatInfo GetInstance(IFormatProvider provider)
+		{
+			if (provider !=3D null) {
+				DateTimeFormatInfo dtfi;
+				dtfi =3D (DateTimeFormatInfo)provider.GetFormat(typeof(DateTimeFormatI=
nfo));
+				if (dtfi !=3D null)
+					return dtfi;
+			}
+		=09
+			return CurrentInfo;
+		}
+
 		public bool IsReadOnly {
 			get {
 				return readOnly;
diff -u 'System.Globalization/NumberFormatInfo.cs' './System.Globalization/=
NumberFormatInfo.cs'
Index: ./System.Globalization/NumberFormatInfo.cs
--- ./System.Globalization/NumberFormatInfo.cs	Thu Dec  6 06:00:39 2001
+++ ./System.Globalization/NumberFormatInfo.cs	Wed Feb 20 20:38:24 2002
@@ -636,22 +636,7 @@
=20
 		public object GetFormat (Type formatType)=20
 		{
-			// LAMESPEC: ECMA says we implement IFormatProvider, but doesn't define=
 this
-			//
-			// From the .NET Framework SDK
-			//
-			// Parameters: formatType The Type of the formatting service required.=20
-			//
-			// Return Value: The current instance of the NumberFormatInfo class, if=
 formatType=20
-			// is the same as the type of the current instance; otherwise, a null r=
eference
-			//
-			// Remarks: This method is invoked by the Format(String, IFormatProvide=
r) method 		=09
-			// supported by the base data types when this instance is passed as the=
=20
-			// IFormatProvider parameter. It implements IFormatProvider.GetFormat.
-
-			if (formatType.Equals(this)) // LAMESPEC: Should this be IsInstanceOfTy=
pe?
-				return this;
-			else return null;
+			return (formatType =3D=3D GetType()) ? this : null;
 		}
 	=09
 		public object Clone ()=20
@@ -669,12 +654,16 @@
 			return copy;
 		}		=09
=20
-		public static NumberFormatInfo GetInstance(IFormatProvider formatProvide=
r)
+		public static NumberFormatInfo GetInstance(IFormatProvider provider)
 		{
-			if (formatProvider =3D=3D null) return NumberFormatInfo.CurrentInfo;
-			NumberFormatInfo retval =3D (NumberFormatInfo)formatProvider.GetFormat(=
Type.GetType("System.Globalization.NumberFormatInfo"));
-			if (retval =3D=3D null) return NumberFormatInfo.CurrentInfo;
-			return retval;
+			if (provider !=3D null) {
+				NumberFormatInfo nfi;
+				nfi =3D (NumberFormatInfo)provider.GetFormat(typeof(NumberFormatInfo))=
;
+				if (nfi !=3D null)
+					return nfi;
+			}
+		=09
+			return CurrentInfo;
 		}
 	}
 }
diff -u 'System/Byte.cs' './System/Byte.cs'
Index: ./System/Byte.cs
--- ./System/Byte.cs	Sun Jan 20 20:57:20 2002
+++ ./System/Byte.cs	Wed Feb 20 21:29:56 2002
@@ -12,7 +12,6 @@
 namespace System {
 =09
 	public struct Byte : IComparable, IFormattable, IConvertible {
-		private static Type Type =3D typeof (byte);
 	=09
 		public const byte MinValue =3D 0;
 		public const byte MaxValue =3D 255;
@@ -133,7 +132,7 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (string format)
@@ -143,26 +142,17 @@
=20
 		public string ToString (IFormatProvider provider)
 		{
-			return ToString ("G", provider);
+			return ToString (null, provider);
 		}
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString(format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/Int16.cs' './System/Int16.cs'
Index: ./System/Int16.cs
--- ./System/Int16.cs	Sat Dec 22 04:46:42 2001
+++ ./System/Int16.cs	Wed Feb 20 21:29:39 2002
@@ -12,7 +12,6 @@
 namespace System {
 =09
 	public struct Int16 : IComparable, IFormattable { //, IConvertible {
-		private static Type Type =3D typeof (short);
=20
 		public const short MaxValue =3D  32767;
 		public const short MinValue =3D -32768;
@@ -125,12 +124,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -140,21 +139,12 @@
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString(format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/Int32.cs' './System/Int32.cs'
Index: ./System/Int32.cs
--- ./System/Int32.cs	Wed Feb 13 18:01:13 2002
+++ ./System/Int32.cs	Wed Feb 20 21:29:19 2002
@@ -12,8 +12,7 @@
 namespace System {
 =09
 	public struct Int32 : IComparable, IFormattable, IConvertible {
-		private static Type Type =3D typeof (int);
-	=09
+
 		public const int MaxValue =3D 0x7fffffff;
 		public const int MinValue =3D -2147483648;
 	=09
@@ -126,12 +125,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -139,23 +138,14 @@
 			return ToString (format, null);
 		}
=20
-		public string ToString (string format, IFormatProvider fp)
+		public string ToString (string format, IFormatProvider fp )
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
-		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
+			if ( format =3D=3D null )=20
+				format =3D "G";
=20
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString (format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/Int64.cs' './System/Int64.cs'
Index: ./System/Int64.cs
--- ./System/Int64.cs	Wed Jan  9 15:49:43 2002
+++ ./System/Int64.cs	Wed Feb 20 22:07:22 2002
@@ -12,7 +12,6 @@
 namespace System {
 =09
 	public struct Int64 : IComparable, IFormattable { //, IConvertible {
-		private static Type Type =3D typeof (long);
=20
 		public const long MaxValue =3D 0x7fffffffffffffff;
 		public const long MinValue =3D -9223372036854775808;
@@ -127,12 +126,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -142,21 +141,12 @@
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString (format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/SByte.cs' './System/SByte.cs'
Index: ./System/SByte.cs
--- ./System/SByte.cs	Fri Jan  4 20:48:22 2002
+++ ./System/SByte.cs	Wed Feb 20 21:30:09 2002
@@ -13,7 +13,6 @@
=20
 	[CLSCompliant(false)]
 	public struct SByte : IComparable, IFormattable { //, IConvertible {
-		public static Type Type =3D typeof (sbyte);
=20
 		public const sbyte MinValue =3D -128;
 		public const sbyte MaxValue =3D 127;
@@ -128,12 +127,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -143,21 +142,12 @@
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString(format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ICovnertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/UInt16.cs' './System/UInt16.cs'
Index: ./System/UInt16.cs
--- ./System/UInt16.cs	Fri Jan  4 20:48:22 2002
+++ ./System/UInt16.cs	Wed Feb 20 21:29:48 2002
@@ -13,7 +13,6 @@
=20
 	[CLSCompliant(false)]
 	public struct UInt16 : IComparable, IFormattable { //, IConvertible {
-		private static Type Type =3D typeof (ushort);
=20
 		public const ushort MaxValue =3D 0xffff;
 		public const ushort MinValue =3D 0;
@@ -114,12 +113,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -129,21 +128,12 @@
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString(format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/UInt32.cs' './System/UInt32.cs'
Index: ./System/UInt32.cs
--- ./System/UInt32.cs	Fri Jan  4 20:48:22 2002
+++ ./System/UInt32.cs	Wed Feb 20 21:29:33 2002
@@ -13,7 +13,6 @@
=20
 	[CLSCompliant(false)]
 	public struct UInt32 : IComparable, IFormattable { //, IConvertible {
-		public static Type Type =3D typeof (uint);
=20
 		public const uint MaxValue =3D 0xffffffff;
 		public const uint MinValue =3D 0;
@@ -120,12 +119,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -135,21 +134,12 @@
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString(format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //
diff -u 'System/UInt64.cs' './System/UInt64.cs'
Index: ./System/UInt64.cs
--- ./System/UInt64.cs	Sat Dec 22 04:46:42 2001
+++ ./System/UInt64.cs	Wed Feb 20 21:28:52 2002
@@ -13,8 +13,6 @@
=20
 	[CLSCompliant(false)]
 	public struct UInt64 : IComparable, IFormattable { //, IConvertible {
-		private static Type Type =3D typeof (ulong);
-
 		public const ulong MaxValue =3D 0xffffffffffffffff;
 		public const ulong MinValue =3D 0;
 	=09
@@ -126,12 +124,12 @@
=20
 		public override string ToString ()
 		{
-			return ToString ("G", null);
+			return ToString (null, null);
 		}
=20
 		public string ToString (IFormatProvider fp)
 		{
-			return ToString ("G", fp);
+			return ToString (null, fp);
 		}
=20
 		public string ToString (string format)
@@ -141,21 +139,12 @@
=20
 		public string ToString (string format, IFormatProvider fp)
 		{
-			string fmt;
-			NumberFormatInfo nfi;
+			NumberFormatInfo nfi =3D NumberFormatInfo.GetInstance( fp );
 		=09
-			fmt =3D (format =3D=3D null) ? "G" : format;
+			if ( format =3D=3D null )
+				format =3D "G";
 		=09
-			if (fp =3D=3D null)
-				nfi =3D NumberFormatInfo.CurrentInfo;
-			else {
-				nfi =3D (NumberFormatInfo) fp.GetFormat (Type);
-			=09
-				if (nfi =3D=3D null)
-					nfi =3D NumberFormatInfo.CurrentInfo;
-			}
-
-			return IntegerFormatter.NumberToString (fmt, nfi, value);
+			return IntegerFormatter.NumberToString(format, nfi, value);
 		}
=20
 		// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D //

--=-PjSpYbaYFkwZTm8jFbBk--

--=-90mltn9ZbTEqjQIHWnhi
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA8dC0USPSplX5M5nQRAsgMAJ9Gn6kz9VUIXQbmg0108ZO+sy/s6QCfXnNI
8leiiACCGVRrE0MH+5H4Sso=
=0N4j
-----END PGP SIGNATURE-----

--=-90mltn9ZbTEqjQIHWnhi--