internal static bool ValidDigit (char e, bool allowHex)
{
- if (allowHex)
- return Char.IsDigit (e) || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
-
- return Char.IsDigit (e);
+ return (e >= '0' && e <= '9') || (allowHex && (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f'));
}
internal static Exception GetFormatException ()
Assert.IsTrue (typeof (ArgumentException) == e.GetType (), "C#42");
}
+ try {
+ Int32.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+ Assert.Fail ("C#42");
+ } catch (FormatException) {
+ }
+
+ try {
+ Int32.Parse ("\xFF15\xFF15", NumberStyles.Any, CultureInfo.InvariantCulture);
+ Assert.Fail ("C#43");
+ } catch (FormatException) {
+ }
+
// Pass a DateTimeFormatInfo, it is unable to format
// numbers, but we should not crash
Int32.Parse ("2.09E1", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent);
Assert.Fail ("B#9");
} catch (OverflowException) {
- }
+ }
}
[Test]
Assert.IsTrue(typeof(OverflowException) == e.GetType(), "#20");
}
+ try {
+ Int64.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+ Assert.Fail ("C#42");
+ } catch (FormatException) {
+ }
+
// Pass a DateTimeFormatInfo, it is unable to format
// numbers, but we should not crash
try {
UInt32.Parse("$42", NumberStyles.Integer, Nfi);
Assert.Fail("Should raise a System.FormatException");
+ } catch (FormatException e) {
}
- catch (Exception e) {
- Assert.IsTrue(typeof(FormatException) == e.GetType());
+
+ try {
+ UInt32.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+ Assert.Fail ("C#42");
+ } catch (FormatException) {
}
+
// Pass a DateTimeFormatInfo, it is unable to format
- // numbers, but we should not crash
-
+ // numbers, but we should not crash
UInt32.Parse ("123", new DateTimeFormatInfo ());
Assert.AreEqual (734561, UInt32.Parse ("734561\0"), "C#43");
try {
UInt64.Parse("$42", NumberStyles.Integer, Nfi);
Assert.Fail("Should raise a System.FormatException");
+ } catch (FormatException e) {
}
- catch (Exception e) {
- Assert.IsTrue(typeof(FormatException) == e.GetType());
+
+ try {
+ UInt64.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+ Assert.Fail ("C#42");
+ } catch (FormatException) {
}
// Pass a DateTimeFormatInfo, it is unable to format
- // numbers, but we should not crash
-
+ // numbers, but we should not crash
UInt64.Parse ("123", new DateTimeFormatInfo ());
Assert.AreEqual (734561, UInt64.Parse ("734561\0"), "C#43");