diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-10 17:49:14 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-10 17:49:14 +0200 |
commit | 7670b812333f64b8ef349797cf3e2fb26765502c (patch) | |
tree | bbfae7eca9992c0dcdf2ee237dd56f9d742d6c77 /core/io/json.cpp | |
parent | 1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff) | |
parent | 64146cb7f35b57b0974b82845674d58f9f3480b6 (diff) | |
download | redot-engine-7670b812333f64b8ef349797cf3e2fb26765502c.tar.gz |
Merge pull request #86518 from AThousandShips/array_iter
[Core] Add iteration support to `Array`
Diffstat (limited to 'core/io/json.cpp')
-rw-r--r-- | core/io/json.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/core/io/json.cpp b/core/io/json.cpp index 496400a5ea..5a1fe45f70 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -86,7 +86,7 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_ case Variant::PACKED_STRING_ARRAY: case Variant::ARRAY: { Array a = p_var; - if (a.size() == 0) { + if (a.is_empty()) { return "[]"; } String s = "["; @@ -95,12 +95,15 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_ ERR_FAIL_COND_V_MSG(p_markers.has(a.id()), "\"[...]\"", "Converting circular structure to JSON."); p_markers.insert(a.id()); - for (int i = 0; i < a.size(); i++) { - if (i > 0) { + bool first = true; + for (const Variant &var : a) { + if (first) { + first = false; + } else { s += ","; s += end_statement; } - s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(a[i], p_indent, p_cur_indent + 1, p_sort_keys, p_markers); + s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(var, p_indent, p_cur_indent + 1, p_sort_keys, p_markers); } s += end_statement + _make_indent(p_indent, p_cur_indent) + "]"; p_markers.erase(a.id()); |