From 890bbed5ed448c768d0f6db3374bd157b8315614 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Wed, 3 Oct 2018 19:37:36 +0200 Subject: [PATCH] further `nil` fixes in `tojson` and `serialization` --- yaml/serialization.nim | 2 +- yaml/tojson.nim | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/yaml/serialization.nim b/yaml/serialization.nim index 90e3163..79a5313 100644 --- a/yaml/serialization.nim +++ b/yaml/serialization.nim @@ -1349,7 +1349,7 @@ proc load*[K](input: Stream | string, target: var K) else: internalError("Unexpected exception: " & $e.parent.name) proc loadMultiDoc*[K](input: Stream | string, target: var seq[K]) = - if target.isNil: + if target.len == 0: target = newSeq[K]() var parser = newYamlParser(serializationTagLibrary) diff --git a/yaml/tojson.nim b/yaml/tojson.nim index d53cdbd..3e7f4a6 100644 --- a/yaml/tojson.nim +++ b/yaml/tojson.nim @@ -116,7 +116,7 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] if levels.len == 0: # parser ensures that next event will be yamlEndDocument levels.add((node: jsonFromScalar(event.scalarContent, - event.scalarTag), key: nil)) + event.scalarTag), key: "")) continue case levels[levels.high].node.kind @@ -127,7 +127,7 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] if event.scalarAnchor != yAnchorNone: anchors[event.scalarAnchor] = jsonScalar of JObject: - if isNil(levels[levels.high].key): + if levels[levels.high].key.len == 0: # JSON only allows strings as keys levels[levels.high].key = event.scalarContent if event.scalarAnchor != yAnchorNone: @@ -137,7 +137,7 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] let jsonScalar = jsonFromScalar(event.scalarContent, event.scalarTag) levels[levels.high].node[levels[levels.high].key] = jsonScalar - levels[levels.high].key = nil + levels[levels.high].key = "" if event.scalarAnchor != yAnchorNone: anchors[event.scalarAnchor] = jsonScalar else: @@ -148,12 +148,12 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] case levels[levels.high].node.kind of JArray: levels[levels.high].node.elems.add(level.node) of JObject: - if isNil(levels[levels.high].key): + if levels[levels.high].key.len == 0: raise newException(YamlConstructionError, "non-scalar as key not allowed in JSON") else: levels[levels.high].node[levels[levels.high].key] = level.node - levels[levels.high].key = nil + levels[levels.high].key = "" else: internalError("Unexpected node kind: " & $levels[levels.high].node.kind) @@ -166,13 +166,13 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] levels[levels.high].node.elems.add( anchors.getOrDefault(event.aliasTarget)) of JObject: - if isNil(levels[levels.high].key): + if levels[levels.high].key.len == 0: raise newException(YamlConstructionError, "cannot use alias node as key in JSON") else: levels[levels.high].node.fields.add( levels[levels.high].key, anchors.getOrDefault(event.aliasTarget)) - levels[levels.high].key = nil + levels[levels.high].key = "" else: internalError("Unexpected node kind: " & $levels[levels.high].node.kind) @@ -208,4 +208,4 @@ proc loadToJson*(str: string): seq[JsonNode] let e = getCurrentException() if e.parent of YamlParserError: raise (ref YamlParserError)(e.parent) - else: internalError("Unexpected exception: " & e.parent.repr) \ No newline at end of file + else: internalError("Unexpected exception: " & e.parent.repr)