summaryrefslogtreecommitdiff
path: root/Source/Dafny/BigIntegerParser.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Dafny/BigIntegerParser.cs')
-rw-r--r--Source/Dafny/BigIntegerParser.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/Dafny/BigIntegerParser.cs b/Source/Dafny/BigIntegerParser.cs
new file mode 100644
index 00000000..cd2cf314
--- /dev/null
+++ b/Source/Dafny/BigIntegerParser.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Numerics;
+using System.Globalization;
+
+namespace Microsoft.Dafny {
+ internal static class BigIntegerParser {
+ /// <summary>
+ /// Mono does not support the BigInteger.TryParse method. In practice,
+ /// we seldom actually need to parse huge integers, so it makes sense
+ /// to support most real-life cases by simply trying to parse using
+ /// Int64, and only falling back if needed.
+ /// </summary>
+ internal static BigInteger Parse(string str, NumberStyles style) {
+ UInt64 parsed;
+ if (UInt64.TryParse(str, style, NumberFormatInfo.CurrentInfo, out parsed)) {
+ return new BigInteger(parsed);
+ } else {
+ // Throws on Mono 3.2.8
+ return BigInteger.Parse(str, style);
+ }
+ }
+
+ internal static BigInteger Parse(string str) {
+ return BigIntegerParser.Parse(str, NumberStyles.Integer);
+ }
+ }
+} \ No newline at end of file