mirror of https://github.com/status-im/NimYAML.git
Parse +-Inf and NaN into JSON
This commit is contained in:
parent
b1e828eae6
commit
efe15f5754
|
@ -38,6 +38,12 @@ proc jsonFromScalar(content: string, tag: TagId,
|
||||||
of yTypeFloat:
|
of yTypeFloat:
|
||||||
result.kind = JFloat
|
result.kind = JFloat
|
||||||
result.fnum = parseFloat(content)
|
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:
|
of yTypeBoolTrue:
|
||||||
result.kind = JBool
|
result.kind = JBool
|
||||||
result.bval = true
|
result.bval = true
|
||||||
|
|
|
@ -294,6 +294,13 @@ proc parseToJson*(s: Stream): seq[JsonNode]
|
||||||
## representation. The input may not contain any tags apart from those in
|
## representation. The input may not contain any tags apart from those in
|
||||||
## ``coreTagLibrary``. Anchors and aliases will be resolved. Maps in the
|
## ``coreTagLibrary``. Anchors and aliases will be resolved. Maps in the
|
||||||
## input must not contain non-scalars as keys.
|
## 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]
|
proc parseToJson*(s: string): seq[JsonNode]
|
||||||
## see `parseToJson <#parseToJson,Stream,seq[JsonNode]>`_
|
## see `parseToJson <#parseToJson,Stream,seq[JsonNode]>`_
|
||||||
|
|
Loading…
Reference in New Issue