changeset 142:2100965eb97f v2

fixed JSONWriter handling Infinity, NaN and locale aware number formatting
author cin
date Wed, 04 Mar 2015 03:10:38 +0300
parents 0fa293bb1351
children 16f926ee499d
files Implab/JSON/JSONWriter.cs
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Implab/JSON/JSONWriter.cs	Tue Feb 24 00:54:22 2015 +0300
+++ b/Implab/JSON/JSONWriter.cs	Wed Mar 04 03:10:38 2015 +0300
@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Globalization;
 
 namespace Implab.JSON {
     public class JSONWriter {
@@ -35,7 +36,6 @@
 
         public JSONWriter(TextWriter writer) {
             Safe.ArgumentNotNull(writer, "writer");
-
             m_writer = writer;
         }
 
@@ -262,7 +262,14 @@
         }
 
         void Write(double value) {
-            m_writer.Write(value);
+            if (double.IsNaN(value))
+                Write("NaN");
+            else if (double.IsNegativeInfinity(value))
+                Write("-Infinity");
+            else if (double.IsPositiveInfinity(value))
+                Write("Infinity");
+            else
+                m_writer.Write(value.ToString(CultureInfo.InvariantCulture));
         }
 
         void OperationNotApplicable(string opName) {