summaryrefslogtreecommitdiff
path: root/Source/Dafny/BigIntegerParser.cs
diff options
context:
space:
mode:
authorGravatar Clément Pit--Claudel <clement.pitclaudel@live.com>2015-06-07 02:22:02 -0700
committerGravatar Clément Pit--Claudel <clement.pitclaudel@live.com>2015-06-07 02:22:02 -0700
commit1e9a9af1700f67dde62e8ceb81aa16e13de0e3fb (patch)
tree11865312bfb5cefd285fc4504153da618f700376 /Source/Dafny/BigIntegerParser.cs
parenta74ff7e873f3db35baf590c8221c2f460b49d07b (diff)
Add a compatibility layer over BigInteger.Parse
Mono currently does not implement support for BigInteger.Parse, so use Int64 if possible, and throw the same error as was previously returned otherwise. This is not too much of a problem in practice, because most of the integers that we actually come across in real-life source files seem to fit in an Int64.
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..94e842cc
--- /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) {
+ Int64 parsed;
+ if (Int64.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