Improve dictionary printing to avoid confusion with arrays
- Add leading and trailing spaces within dictionaries, as the `{}`
characters are hard to distinguish from `[]` on some fonts.
This is especially helpful with empty arrays and dictionaries.
This commit is contained in:
@@ -1835,11 +1835,13 @@ String Variant::stringify(int recursion_count) const {
|
|||||||
case DICTIONARY: {
|
case DICTIONARY: {
|
||||||
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
|
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
|
||||||
if (recursion_count > MAX_RECURSION) {
|
if (recursion_count > MAX_RECURSION) {
|
||||||
ERR_PRINT("Max recursion reached");
|
ERR_PRINT("Maximum dictionary recursion reached!");
|
||||||
return "{...}";
|
return "{ ... }";
|
||||||
}
|
}
|
||||||
|
|
||||||
String str("{");
|
// Add leading and trailing space to Dictionary printing. This distinguishes it
|
||||||
|
// from array printing on fonts that have similar-looking {} and [] characters.
|
||||||
|
String str("{ ");
|
||||||
List<Variant> keys;
|
List<Variant> keys;
|
||||||
d.get_key_list(&keys);
|
d.get_key_list(&keys);
|
||||||
|
|
||||||
@@ -1858,9 +1860,9 @@ String Variant::stringify(int recursion_count) const {
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
str += ", ";
|
str += ", ";
|
||||||
}
|
}
|
||||||
str += pairs[i].key + ":" + pairs[i].value;
|
str += pairs[i].key + ": " + pairs[i].value;
|
||||||
}
|
}
|
||||||
str += "}";
|
str += " }";
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
} break;
|
} break;
|
||||||
@@ -1894,7 +1896,7 @@ String Variant::stringify(int recursion_count) const {
|
|||||||
case ARRAY: {
|
case ARRAY: {
|
||||||
Array arr = operator Array();
|
Array arr = operator Array();
|
||||||
if (recursion_count > MAX_RECURSION) {
|
if (recursion_count > MAX_RECURSION) {
|
||||||
ERR_PRINT("Max recursion reached");
|
ERR_PRINT("Maximum array recursion reached!");
|
||||||
return "[...]";
|
return "[...]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ null
|
|||||||
false
|
false
|
||||||
empty array
|
empty array
|
||||||
zero Vector2i
|
zero Vector2i
|
||||||
{22:{4:["nesting", "arrays"]}}
|
{ 22: { 4: ["nesting", "arrays"] } }
|
||||||
{4:["nesting", "arrays"]}
|
{ 4: ["nesting", "arrays"] }
|
||||||
["nesting", "arrays"]
|
["nesting", "arrays"]
|
||||||
nesting
|
nesting
|
||||||
arrays
|
arrays
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
GDTEST_OK
|
GDTEST_OK
|
||||||
{"a":1, "b":2, "with spaces":3, "2":4}
|
{ "a": 1, "b": 2, "with spaces": 3, "2": 4 }
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
GDTEST_OK
|
GDTEST_OK
|
||||||
{"hello":{"world":{"is":"beautiful"}}}
|
{ "hello": { "world": { "is": "beautiful" } } }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
GDTEST_OK
|
GDTEST_OK
|
||||||
{8:{"key":"value"}}
|
{ 8: { "key": "value" } }
|
||||||
{"key":"value"}
|
{ "key": "value" }
|
||||||
value
|
value
|
||||||
value
|
value
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
GDTEST_OK
|
GDTEST_OK
|
||||||
{1:(2, 0)}
|
{ 1: (2, 0) }
|
||||||
{3:(4, 0)}
|
{ 3: (4, 0) }
|
||||||
[[(5, 0)]]
|
[[(5, 0)]]
|
||||||
[[(6, 0)]]
|
[[(6, 0)]]
|
||||||
[[(7, 0)]]
|
[[(7, 0)]]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ hello/world
|
|||||||
RID(0)
|
RID(0)
|
||||||
Node::get_name
|
Node::get_name
|
||||||
Node::[signal]property_list_changed
|
Node::[signal]property_list_changed
|
||||||
{"hello":123}
|
{ "hello": 123 }
|
||||||
["hello", 123]
|
["hello", 123]
|
||||||
[255, 0, 1]
|
[255, 0, 1]
|
||||||
[-1, 0, 1]
|
[-1, 0, 1]
|
||||||
|
|||||||
Reference in New Issue
Block a user