commit bc0049fec9d7fc9965b2f6cd1d9696cba1c979e1
parent 0623c73707d90fd449eb97084e69b3c8deb697b2
Author: Sebastian <sebastian@sebsite.pw>
Date: Wed, 18 May 2022 23:41:09 -0400
encoding::json: make del take in multiple keys
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/encoding/json/value.ha b/encoding/json/value.ha
@@ -45,16 +45,19 @@ export fn set(obj: *object, key: const str, val: const value) void = {
append(bucket, (strings::dup(key), dup(val)));
};
-// Deletes a value from a JSON object.
-export fn del(obj: *object, key: const str) void = {
- const hash = fnv::string(key);
- const bucket = &obj.buckets[hash % len(obj.buckets)];
- for (let i = 0z; i < len(bucket); i += 1) {
- if (bucket[i].0 == key) {
- free(bucket[i].0);
- finish(bucket[i].1);
- delete(bucket[i]);
- break;
+// Deletes values from a JSON object, if they are present.
+export fn del(obj: *object, keys: const str...) void = {
+ for (let i = 0z; i < len(keys); i += 1) {
+ const key = keys[i];
+ const hash = fnv::string(key);
+ const bucket = &obj.buckets[hash % len(obj.buckets)];
+ for (let i = 0z; i < len(bucket); i += 1) {
+ if (bucket[i].0 == key) {
+ free(bucket[i].0);
+ finish(bucket[i].1);
+ delete(bucket[i]);
+ break;
+ };
};
};
};