mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
added == for PJsonNode
This commit is contained in:
@@ -619,6 +619,25 @@ proc `%`*(elements: openArray[PJsonNode]): PJsonNode =
|
||||
newSeq(result.elems, elements.len)
|
||||
for i, p in pairs(elements): result.elems[i] = p
|
||||
|
||||
proc `==`* (a,b: PJsonNode): bool =
|
||||
if a.kind != b.kind: false
|
||||
else:
|
||||
case a.kind
|
||||
of JString:
|
||||
a.str == b.str
|
||||
of JInt:
|
||||
a.num == b.num
|
||||
of JFloat:
|
||||
a.fnum == b.fnum
|
||||
of JBool:
|
||||
a.bval == b.bval
|
||||
of JNull:
|
||||
true
|
||||
of JArray:
|
||||
a.elems == b.elems
|
||||
of JObject:
|
||||
a.fields == b.fields
|
||||
|
||||
proc len*(n: PJsonNode): int =
|
||||
## If `n` is a `JArray`, it returns the number of elements.
|
||||
## If `n` is a `JObject`, it returns the number of pairs.
|
||||
|
||||
Reference in New Issue
Block a user