Fix subtle mistake in docs and formatting
This commit is contained in:
parent
db7fee6303
commit
64d3b9a34d
1 changed files with 5 additions and 4 deletions
|
|
@ -629,13 +629,13 @@ proc len*(n: PJsonNode): int =
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc `[]`*(node: PJsonNode, name: string, default: PJsonNode = nil): PJsonNode =
|
proc `[]`*(node: PJsonNode, name: string, default: PJsonNode = nil): PJsonNode =
|
||||||
## Gets a field from a `JObject`. If node is nil, this returns default
|
## Gets a field from a `JObject`. If node is nil, this returns `default`
|
||||||
## This is to allow for chaining such as the following:
|
## This is to allow for chaining such as the following:
|
||||||
## .. code-block Nimrod
|
## .. code-block Nimrod
|
||||||
## foo["field1"]["field2"]
|
## foo["field1"]["field2"]
|
||||||
##
|
##
|
||||||
## If `field1` is undefined, it will return nil, and the access on `field2` will
|
## If `field1` is undefined, it will return nil, and the access on `field2` will
|
||||||
## pass through and return nil. Also returns default if the key is not found.
|
## pass through and return `default`. Also returns `default` if the key is not found.
|
||||||
if isNil(node):
|
if isNil(node):
|
||||||
return default
|
return default
|
||||||
assert(node.kind == JObject)
|
assert(node.kind == JObject)
|
||||||
|
|
@ -645,8 +645,9 @@ proc `[]`*(node: PJsonNode, name: string, default: PJsonNode = nil): PJsonNode =
|
||||||
return default
|
return default
|
||||||
|
|
||||||
proc `[]`*(node: PJsonNode, index: int, default: PJsonNode = nil): PJsonNode =
|
proc `[]`*(node: PJsonNode, index: int, default: PJsonNode = nil): PJsonNode =
|
||||||
## Gets the node at `index` in an Array.If `node` is nil, this returns nil to
|
## Gets the node at `index` in an Array.If `node` is nil, this returns `result`,
|
||||||
## allow for chaining. Results are undefined if the index is out of range.
|
## which is by default `nil` to allow for chaining. Results are undefined if
|
||||||
|
## the index is out of range.
|
||||||
if isNil(node):
|
if isNil(node):
|
||||||
return default
|
return default
|
||||||
assert(node.kind == JArray)
|
assert(node.kind == JArray)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue