From: TimePath Date: Mon, 28 Mar 2016 11:00:09 +0000 (+1100) Subject: json: property accessor X-Git-Tag: xonotic-v0.8.2~992^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c2cab6a53eb44d930452998f15d97257bd5e64e3;p=xonotic%2Fxonotic-data.pk3dir.git json: property accessor --- diff --git a/qcsrc/lib/json.qc b/qcsrc/lib/json.qc index 3ba44aec1..555c4b10c 100644 --- a/qcsrc/lib/json.qc +++ b/qcsrc/lib/json.qc @@ -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(); }