]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
json: property accessor
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 28 Mar 2016 11:00:09 +0000 (22:00 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 28 Mar 2016 11:00:09 +0000 (22:00 +1100)
qcsrc/lib/json.qc

index 3ba44aec170c95591b70ea71f87499bc34b7bfd2..555c4b10cc75a6877eb3450bedcde8a29aab87cb 100644 (file)
@@ -258,6 +258,19 @@ int json_parse(string in, bool() func) {
     return _json_buffer;
 }
 
+string json_get(int buf, string key)
+{
+    for (int i = 1, n = buf_getsize(buf); i < n; i += 2) {
+        if (bufstr_get(buf, i) == key) return bufstr_get(buf, i + 1);
+    }
+    return string_null;
+}
+
+void json_del(int buf)
+{
+    buf_del(buf);
+}
+
 #undef JSON_BEGIN
 #undef JSON_FAIL
 #undef JSON_END
@@ -277,5 +290,5 @@ TEST(json, Parse)
     for (int i = 0, n = buf_getsize(buf); i < n; ++i) {
         print(bufstr_get(buf, i), "\n");
     }
-       SUCCEED();
+    SUCCEED();
 }