summaryrefslogtreecommitdiff
path: root/core/io/json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/json.cpp')
-rw-r--r--core/io/json.cpp43
1 files changed, 0 insertions, 43 deletions
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 0186547dd2..baa62a4b0a 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -46,7 +46,6 @@ const char *JSON::tk_name[TK_MAX] = {
};
static String _make_indent(const String &p_indent, int p_size) {
-
String indent_text = "";
if (!p_indent.empty()) {
for (int i = 0; i < p_size; i++)
@@ -56,7 +55,6 @@ static String _make_indent(const String &p_indent, int p_size) {
}
String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) {
-
String colon = ":";
String end_statement = "";
@@ -66,7 +64,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
switch (p_var.get_type()) {
-
case Variant::NIL:
return "null";
case Variant::BOOL:
@@ -81,7 +78,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::ARRAY: {
-
String s = "[";
s += end_statement;
Array a = p_var;
@@ -96,7 +92,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
return s;
};
case Variant::DICTIONARY: {
-
String s = "{";
s += end_statement;
Dictionary d = p_var;
@@ -107,7 +102,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
keys.sort();
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
if (E != keys.front()) {
s += ",";
s += end_statement;
@@ -126,17 +120,13 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) {
-
return _print_var(p_var, p_indent, 0, p_sort_keys);
}
Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
-
while (p_len > 0) {
switch (p_str[index]) {
-
case '\n': {
-
line++;
index++;
break;
@@ -146,43 +136,36 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return OK;
} break;
case '{': {
-
r_token.type = TK_CURLY_BRACKET_OPEN;
index++;
return OK;
};
case '}': {
-
r_token.type = TK_CURLY_BRACKET_CLOSE;
index++;
return OK;
};
case '[': {
-
r_token.type = TK_BRACKET_OPEN;
index++;
return OK;
};
case ']': {
-
r_token.type = TK_BRACKET_CLOSE;
index++;
return OK;
};
case ':': {
-
r_token.type = TK_COLON;
index++;
return OK;
};
case ',': {
-
r_token.type = TK_COMMA;
index++;
return OK;
};
case '"': {
-
index++;
String str;
while (true) {
@@ -203,7 +186,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
CharType res = 0;
switch (next) {
-
case 'b':
res = 8;
break;
@@ -228,7 +210,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return ERR_PARSE_ERROR;
}
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
-
r_err_str = "Malformed hex constant in string";
return ERR_PARSE_ERROR;
}
@@ -273,7 +254,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
} break;
default: {
-
if (p_str[index] <= 32) {
index++;
break;
@@ -289,11 +269,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return OK;
} else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
-
String id;
while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
-
id += p_str[index];
index++;
}
@@ -313,9 +291,7 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
}
Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
-
if (token.type == TK_CURLY_BRACKET_OPEN) {
-
Dictionary d;
Error err = _parse_object(d, p_str, index, p_len, line, r_err_str);
if (err)
@@ -323,7 +299,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
value = d;
return OK;
} else if (token.type == TK_BRACKET_OPEN) {
-
Array a;
Error err = _parse_array(a, p_str, index, p_len, line, r_err_str);
if (err)
@@ -332,7 +307,6 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
return OK;
} else if (token.type == TK_IDENTIFIER) {
-
String id = token.value;
if (id == "true")
value = true;
@@ -347,11 +321,9 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
return OK;
} else if (token.type == TK_NUMBER) {
-
value = token.value;
return OK;
} else if (token.type == TK_STRING) {
-
value = token.value;
return OK;
} else {
@@ -361,25 +333,20 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
}
Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
-
Token token;
bool need_comma = false;
while (index < p_len) {
-
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
if (err != OK)
return err;
if (token.type == TK_BRACKET_CLOSE) {
-
return OK;
}
if (need_comma) {
-
if (token.type != TK_COMMA) {
-
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
} else {
@@ -401,29 +368,23 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_
}
Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
-
bool at_key = true;
String key;
Token token;
bool need_comma = false;
while (index < p_len) {
-
if (at_key) {
-
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
if (err != OK)
return err;
if (token.type == TK_CURLY_BRACKET_CLOSE) {
-
return OK;
}
if (need_comma) {
-
if (token.type != TK_COMMA) {
-
r_err_str = "Expected '}' or ','";
return ERR_PARSE_ERROR;
} else {
@@ -433,7 +394,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
}
if (token.type != TK_STRING) {
-
r_err_str = "Expected key";
return ERR_PARSE_ERROR;
}
@@ -443,13 +403,11 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
if (err != OK)
return err;
if (token.type != TK_COLON) {
-
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
}
at_key = false;
} else {
-
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
if (err != OK)
return err;
@@ -468,7 +426,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
}
Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
-
const CharType *str = p_json.ptr();
int idx = 0;
int len = p_json.length();