Selaa lähdekoodia

2005-06-07 Gonzalo Paniagua Javier <[email protected]>

	* System.Threading/Thread.cs: check that the culture is valid for
	formatting (ie, (!neutral || invariant)).

	* System.Globalization/CultureInfo.cs: added internal method to check
	for a culture valid for formatting. Correctly get the calendar type.
	Before it was always type 0. Thanks to Mcs for pointing this out.


svn path=/trunk/mcs/; revision=45611
Gonzalo Paniagua Javier 20 vuotta sitten
vanhempi
sitoutus
d02b1d8a50

+ 6 - 0
mcs/class/corlib/System.Globalization/ChangeLog

@@ -1,3 +1,9 @@
+2005-06-07 Gonzalo Paniagua Javier <[email protected]>
+
+	* CultureInfo.cs: added internal method to check for a culture
+	valid for formatting. Correctly get the calendar type.  Before
+	it was always type 0. Thanks to Mcs for pointing this out.
+
 2005-05-06  Miguel de Icaza  <[email protected]>
 
 	* CultureInfo.cs: Eliminate double-check lock always init the invariant_culture_info.

+ 20 - 18
mcs/class/corlib/System.Globalization/CultureInfo.cs

@@ -42,7 +42,7 @@ namespace System.Globalization
 		static volatile CultureInfo invariant_culture_info;
 
 		const int NumOptionalCalendars = 5;
-		const int CalendarTypeMask = 0xFF;
+		const int GregorianTypeMask = 0x00FFFFFF;
 		const int CalendarTypeBits = 24;
 
 		bool m_isReadOnly;
@@ -345,15 +345,20 @@ namespace System.Globalization
 			}
 		}
 
+		internal void CheckNeutral ()
+		{
+			if (IsNeutralCulture) {
+				throw new NotSupportedException ("Culture \"" + m_name + "\" is " +
+						"a neutral culture. It can not be used in formatting " +
+						"and parsing and therefore cannot be set as the thread's " +
+						"current culture.");
+			}
+		}
+
 		public virtual NumberFormatInfo NumberFormat {
 			get {
 				if (!constructed) Construct ();
-				if (IsNeutralCulture) {
-					throw new NotSupportedException ("Culture \"" + m_name + "\" is " +
-							"a neutral culture. It can not be used in formatting " +
-							"and parsing and therefore cannot be set as the thread's " +
-							"current culture.");
-				}
+				CheckNeutral ();
 				if (numInfo == null){
 					lock (this){
 						if (numInfo == null) {
@@ -382,12 +387,7 @@ namespace System.Globalization
 			get 
 			{
 				if (!constructed) Construct ();
-				if (IsNeutralCulture) {
-					throw new NotSupportedException ("Culture \"" + m_name + "\" is " +
-							"a neutral culture. It can not be used in formatting " +
-							"and parsing and therefore cannot be set as the thread's " +
-							"current culture.");
-				}
+				CheckNeutral ();
 				if (dateTimeInfo == null)
 				{
 					lock (this)
@@ -623,11 +623,13 @@ namespace System.Globalization
 
 			for (int i=0; i<NumOptionalCalendars; i++) {
 				Calendar cal = null;
-				switch (*(calendar_data + i) & CalendarTypeMask >> CalendarTypeBits) {
+				int caldata = *(calendar_data + i);
+				int caltype = (caldata >> CalendarTypeBits);
+				switch (caltype) {
 				case 0:
-					int gt = (*(calendar_data + i) & CalendarTypeMask);
-					GregorianCalendarTypes type = (GregorianCalendarTypes) gt;
-					cal = new GregorianCalendar (type);
+					GregorianCalendarTypes greg_type;
+					greg_type = (GregorianCalendarTypes) (caldata & GregorianTypeMask);
+					cal = new GregorianCalendar (greg_type);
 					break;
 				case 1:
 					cal = new HijriCalendar ();
@@ -636,7 +638,7 @@ namespace System.Globalization
 					cal = new ThaiBuddhistCalendar ();
 					break;
 				default:
-					throw new Exception ("invalid calendar type:  " + *(calendar_data + i));
+					throw new Exception ("invalid calendar type:  " + caldata);
 				}
 				optional_calendars [i] = cal;
 			}

+ 5 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,8 @@
+2005-06-07 Gonzalo Paniagua Javier <[email protected]>
+
+	* Thread.cs: check that the culture is valid for formatting
+	(ie, (!neutral || invariant)).
+
 2005-06-07  Sebastien Pouliot  <[email protected]> 
 
 	* Thread.cs: Added _Thread interface (and members) and a few missing

+ 1 - 0
mcs/class/corlib/System.Threading/Thread.cs

@@ -392,6 +392,7 @@ namespace System.Threading {
 				if (value == null)
 					throw new ArgumentNullException ("value");
 
+				value.CheckNeutral ();
 				in_currentculture = true;
 				try {
 					BinaryFormatter bf = new BinaryFormatter();