diff --git a/core/variant.cpp b/core/variant.cpp index ad271651cdd..5e12ba9da49 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1323,6 +1323,19 @@ Variant::operator String() const { return stringify(stack); } +template +String stringify_vector(const T &vec, List &stack) { + String str("["); + for (int i = 0; i < vec.size(); i++) { + if (i > 0) { + str += ", "; + } + str = str + Variant(vec[i]).stringify(stack); + } + str += "]"; + return str; +} + String Variant::stringify(List &stack) const { switch (type) { case NIL: @@ -1419,64 +1432,25 @@ String Variant::stringify(List &stack) const { return str; } break; case POOL_VECTOR2_ARRAY: { - PoolVector vec = operator PoolVector(); - String str("["); - for (int i = 0; i < vec.size(); i++) { - if (i > 0) { - str += ", "; - } - str = str + Variant(vec[i]); - } - str += "]"; - return str; + return stringify_vector(operator PoolVector(), stack); } break; case POOL_VECTOR3_ARRAY: { - PoolVector vec = operator PoolVector(); - String str("["); - for (int i = 0; i < vec.size(); i++) { - if (i > 0) { - str += ", "; - } - str = str + Variant(vec[i]); - } - str += "]"; - return str; + return stringify_vector(operator PoolVector(), stack); + } break; + case POOL_COLOR_ARRAY: { + return stringify_vector(operator PoolVector(), stack); } break; case POOL_STRING_ARRAY: { - PoolVector vec = operator PoolVector(); - String str("["); - for (int i = 0; i < vec.size(); i++) { - if (i > 0) { - str += ", "; - } - str = str + vec[i]; - } - str += "]"; - return str; + return stringify_vector(operator PoolVector(), stack); + } break; + case POOL_BYTE_ARRAY: { + return stringify_vector(operator PoolVector(), stack); } break; case POOL_INT_ARRAY: { - PoolVector vec = operator PoolVector(); - String str("["); - for (int i = 0; i < vec.size(); i++) { - if (i > 0) { - str += ", "; - } - str = str + itos(vec[i]); - } - str += "]"; - return str; + return stringify_vector(operator PoolVector(), stack); } break; case POOL_REAL_ARRAY: { - PoolVector vec = operator PoolVector(); - String str("["); - for (int i = 0; i < vec.size(); i++) { - if (i > 0) { - str += ", "; - } - str = str + rtos(vec[i]); - } - str += "]"; - return str; + return stringify_vector(operator PoolVector(), stack); } break; case ARRAY: { Array arr = operator Array(); @@ -1484,17 +1458,7 @@ String Variant::stringify(List &stack) const { return "[...]"; } stack.push_back(arr.id()); - - String str("["); - for (int i = 0; i < arr.size(); i++) { - if (i) { - str += ", "; - } - - str += arr[i].stringify(stack); - } - - str += "]"; + String str = stringify_vector(arr, stack); stack.erase(arr.id()); return str;