From 6afbf0bd5a9981721cd904633f613a1b492b9217 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 18 Aug 2022 17:20:55 +0200 Subject: 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. --- core/variant/variant.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'core/variant') 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(_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 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 "[...]"; } -- cgit v1.2.3