From 73652124cd5a24a348acd746dd7ba1439ff4efc1 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 27 Mar 2017 22:20:47 +1300 Subject: [PATCH] -Changed double parsing back to double.TryParse --- .../Utilities/ConvertUtilsTests.cs | 2 ++ Src/Newtonsoft.Json/JsonTextReader.cs | 10 ++++++---- Src/Newtonsoft.Json/Utilities/ConvertUtils.cs | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Utilities/ConvertUtilsTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/ConvertUtilsTests.cs index 8687a910..94dd81b1 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/ConvertUtilsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/ConvertUtilsTests.cs @@ -39,6 +39,7 @@ namespace Newtonsoft.Json.Tests.Utilities [TestFixture] public class ConvertUtilsTests : TestFixtureBase { +#if HAS_CUSTOM_DOUBLE_PARSE private void AssertDoubleTryParse(string s, ParseResult expectedResult, double? expectedValue) { double d; @@ -157,6 +158,7 @@ namespace Newtonsoft.Json.Tests.Utilities AssertDoubleTryParse("4.94065645841247E+555", ParseResult.Overflow, null); } +#endif private void AssertDecimalTryParse(string s, ParseResult expectedResult, decimal? expectedValue) { diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index f15a685d..5fafa20d 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -2058,9 +2058,10 @@ namespace Newtonsoft.Json } else { + string number = _stringReference.ToString(); + double value; - ParseResult parseResult = ConvertUtils.DoubleTryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value); - if (parseResult == ParseResult.Success) + if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { numberValue = value; } @@ -2137,9 +2138,10 @@ namespace Newtonsoft.Json } else { + string number = _stringReference.ToString(); + double d; - parseResult = ConvertUtils.DoubleTryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out d); - if (parseResult == ParseResult.Success) + if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out d)) { numberValue = d; } diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index 8de7ad1a..3a8542b9 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -930,6 +930,7 @@ namespace Newtonsoft.Json.Utilities return ParseResult.Success; } +#if HAS_CUSTOM_DOUBLE_PARSE private static class IEEE754 { /// @@ -1356,6 +1357,7 @@ namespace Newtonsoft.Json.Utilities value = IEEE754.PackDouble(isNegative, mantissa, exponent); return double.IsInfinity(value) ? ParseResult.Overflow : ParseResult.Success; } +#endif public static ParseResult DecimalTryParse(char[] chars, int start, int length, out decimal value) {