Parse +-Inf and NaN into JSON

This commit is contained in:
Felix Krause 2015-12-28 19:25:53 +01:00
parent b1e828eae6
commit efe15f5754
2 changed files with 13 additions and 0 deletions

View File

@ -38,6 +38,12 @@ proc jsonFromScalar(content: string, tag: TagId,
of yTypeFloat:
result.kind = JFloat
result.fnum = parseFloat(content)
of yTypeFloatInf:
result.kind = JFloat
result.fnum = if content[0] == '-': NegInf else: Inf
of yTypeFloatNaN:
result.kind = JFloat
result.fnum = NaN
of yTypeBoolTrue:
result.kind = JBool
result.bval = true

View File

@ -294,6 +294,13 @@ proc parseToJson*(s: Stream): seq[JsonNode]
## representation. The input may not contain any tags apart from those in
## ``coreTagLibrary``. Anchors and aliases will be resolved. Maps in the
## input must not contain non-scalars as keys.
##
## **Warning:** The special float values ``[+-]Inf`` and ``NaN`` will be
## parsed into Nim's JSON structure without error. However, they cannot be
## rendered to a JSON character stream, because these values are not part
## of the JSON specification. Nim's JSON implementation currently does not
## check for these values and will output invalid JSON when rendering one
## of these values into a JSON character stream.
proc parseToJson*(s: string): seq[JsonNode]
## see `parseToJson <#parseToJson,Stream,seq[JsonNode]>`_