diff options
author | dom96 <dominikpicheta@googlemail.com> | 2011-05-14 20:32:31 +0100 |
---|---|---|
committer | dom96 <dominikpicheta@googlemail.com> | 2011-05-14 20:32:31 +0100 |
commit | d1cd1cea345e82ff1f8b55803b81d68a86cb9d50 (patch) | |
tree | ded8f8c61d85178677ac6ed4ff3c84a71624a518 /lib/pure/json.nim | |
parent | 74b1b28f7e8d832a002502011e800405dedfb6dd (diff) | |
download | Nim-d1cd1cea345e82ff1f8b55803b81d68a86cb9d50.tar.gz |
fixed some redis commands; fixed bindAddr and scgi now doesn't bind to all addresses. copy and delete for json module.
Diffstat (limited to 'lib/pure/json.nim')
-rwxr-xr-x | lib/pure/json.nim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 75958a55f..adb7e5e8b 100755 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -606,6 +606,35 @@ proc `[]=`*(obj: PJsonNode, key: String, val: PJsonNode) = return obj.fields.add((key, val)) +proc delete*(obj: PJsonNode, key: string) = + assert(obj.kind == JObject) + for i in 0..obj.fields.len-1: + if obj.fields[i].key == key: + obj.fields.delete(i) + return + raise newException(EInvalidIndex, "key not in object") + +proc copy*(p: PJsonNode): PJsonNode = + case p.kind + of JString: + result = newJString(p.str) + of JInt: + result = newJInt(p.num) + of JFloat: + result = newJFloat(p.fnum) + of JBool: + result = newJBool(p.bval) + of JNull: + result = newJNull() + of JObject: + result = newJObject() + for key, field in items(p.fields): + result.fields.add((key, copy(field))) + of JArray: + result = newJArray() + for i in items(p.elems): + result.elems.add(copy(i)) + # ------------- pretty printing ---------------------------------------------- proc indent(s: var string, i: int) = |