summaryrefslogtreecommitdiff
path: root/core/variant/variant.cpp
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2022-08-18 17:20:55 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2022-10-04 20:33:40 +0200
commit6afbf0bd5a9981721cd904633f613a1b492b9217 (patch)
tree957e9016e5095af866ae7ae7104271f0954c4fe2 /core/variant/variant.cpp
parent0056acf46fc88757cae9d9f6fe9805f0eec1cd09 (diff)
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.
Diffstat (limited to 'core/variant/variant.cpp')
-rw-r--r--core/variant/variant.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index f24ffeb1a9..e3819fa632 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -1835,11 +1835,13 @@ String Variant::stringify(int recursion_count) const {
case DICTIONARY: {
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
if (recursion_count > MAX_RECURSION) {
- ERR_PRINT("Max recursion reached");
- return "{...}";
+ ERR_PRINT("Maximum dictionary recursion reached!");
+ 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;
d.get_key_list(&keys);
@@ -1858,9 +1860,9 @@ String Variant::stringify(int recursion_count) const {
if (i > 0) {
str += ", ";
}
- str += pairs[i].key + ":" + pairs[i].value;
+ str += pairs[i].key + ": " + pairs[i].value;
}
- str += "}";
+ str += " }";
return str;
} break;
@@ -1894,7 +1896,7 @@ String Variant::stringify(int recursion_count) const {
case ARRAY: {
Array arr = operator Array();
if (recursion_count > MAX_RECURSION) {
- ERR_PRINT("Max recursion reached");
+ ERR_PRINT("Maximum array recursion reached!");
return "[...]";
}