// Current keys
int _json_keys;
+ERASEABLE
bool _json_parse_object() {
JSON_BEGIN();
if (STRING_ITERATOR_GET(_json) != '{') JSON_FAIL("expected '{'");
JSON_END();
}
+ ERASEABLE
bool _json_parse_members() {
JSON_BEGIN();
for (;;) {
JSON_END();
}
+ ERASEABLE
bool _json_parse_pair() {
JSON_BEGIN();
if (!_json_parse_string(false)) JSON_FAIL("expected string");
JSON_END();
}
+ERASEABLE
bool _json_parse_array() {
JSON_BEGIN();
if (STRING_ITERATOR_GET(_json) != '[') JSON_FAIL("expected '['");
int it = bufstr_add(_json_buffer, key, 0);
bool ret = false; WITH(string, _json_ns, key, ret = _json_parse_value());
if (!ret) {
- bufstr_set(_json_buffer, it, string_null);
+ bufstr_free(_json_buffer, it);
if (required) JSON_FAIL("expected value"); else break;
}
bufstr_set(_json_buffer, len, ftos(n + 1));
JSON_END();
}
+ERASEABLE
bool _json_parse_value() {
JSON_BEGIN();
if (!(_json_parse_string(true)
JSON_END();
}
+ ERASEABLE
bool _json_parse_true() {
JSON_BEGIN();
if (!(STRING_ITERATOR_GET(_json) == 't'
JSON_END();
}
+ ERASEABLE
bool _json_parse_false() {
JSON_BEGIN();
if (!(STRING_ITERATOR_GET(_json) == 'f'
JSON_END();
}
+ ERASEABLE
bool _json_parse_null() {
JSON_BEGIN();
if (!(STRING_ITERATOR_GET(_json) == 'n'
JSON_END();
}
+ERASEABLE
bool _json_parse_string(bool add) {
JSON_BEGIN();
if (STRING_ITERATOR_GET(_json) != '"') JSON_FAIL("expected opening '\"'");
case 'n': esc = "\n"; break;
case 't': esc = "\t"; break;
case 'u': esc = "\\u"; break; // TODO
+ case '/': esc = "/"; break;
}
s = strcat(s, esc);
} else {
JSON_END();
}
+ERASEABLE
bool _json_parse_number() {
JSON_BEGIN();
if (!(_json_parse_float() || _json_parse_int())) JSON_FAIL("expected number");
JSON_END();
}
+ ERASEABLE
bool _json_parse_float() {
JSON_BEGIN();
string s = "";
JSON_END();
}
+ ERASEABLE
bool _json_parse_int() {
JSON_BEGIN();
string s = "";
JSON_END();
}
+ERASEABLE
int json_parse(string in, bool() func) {
string trimmed = "";
LABEL(trim) {
return _json_buffer;
}
+ERASEABLE
+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;
+}
+
+ERASEABLE
+void json_del(int buf)
+{
+ buf_del(buf);
+}
+
+ERASEABLE
+void json_dump(int buf)
+{
+ for (int i = 0, n = buf_getsize(buf); i < n; ++i) {
+ print(bufstr_get(buf, i), "\n");
+ }
+}
+
#undef JSON_BEGIN
#undef JSON_FAIL
#undef JSON_END
print(s, "\n");
int buf = json_parse(s, _json_parse_object);
EXPECT_NE(-1, buf);
- for (int i = 0, n = buf_getsize(buf); i < n; ++i) {
- print(bufstr_get(buf, i), "\n");
- }
- SUCCEED();
+ json_dump(buf);
+ SUCCEED();
}