Unify Pool*Array printing output

Co-authored-by: mashumafi <mashumafi@gmail.com>
This commit is contained in:
Yuri Sizov 2021-10-11 01:55:52 +03:00
parent 779a5e5621
commit c2106725ae

View File

@ -1323,6 +1323,19 @@ Variant::operator String() const {
return stringify(stack); return stringify(stack);
} }
template <class T>
String stringify_vector(const T &vec, List<const void *> &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<const void *> &stack) const { String Variant::stringify(List<const void *> &stack) const {
switch (type) { switch (type) {
case NIL: case NIL:
@ -1419,64 +1432,25 @@ String Variant::stringify(List<const void *> &stack) const {
return str; return str;
} break; } break;
case POOL_VECTOR2_ARRAY: { case POOL_VECTOR2_ARRAY: {
PoolVector<Vector2> vec = operator PoolVector<Vector2>(); return stringify_vector(operator PoolVector<Vector2>(), stack);
String str("[");
for (int i = 0; i < vec.size(); i++) {
if (i > 0) {
str += ", ";
}
str = str + Variant(vec[i]);
}
str += "]";
return str;
} break; } break;
case POOL_VECTOR3_ARRAY: { case POOL_VECTOR3_ARRAY: {
PoolVector<Vector3> vec = operator PoolVector<Vector3>(); return stringify_vector(operator PoolVector<Vector3>(), stack);
String str("["); } break;
for (int i = 0; i < vec.size(); i++) { case POOL_COLOR_ARRAY: {
if (i > 0) { return stringify_vector(operator PoolVector<Color>(), stack);
str += ", ";
}
str = str + Variant(vec[i]);
}
str += "]";
return str;
} break; } break;
case POOL_STRING_ARRAY: { case POOL_STRING_ARRAY: {
PoolVector<String> vec = operator PoolVector<String>(); return stringify_vector(operator PoolVector<String>(), stack);
String str("["); } break;
for (int i = 0; i < vec.size(); i++) { case POOL_BYTE_ARRAY: {
if (i > 0) { return stringify_vector(operator PoolVector<uint8_t>(), stack);
str += ", ";
}
str = str + vec[i];
}
str += "]";
return str;
} break; } break;
case POOL_INT_ARRAY: { case POOL_INT_ARRAY: {
PoolVector<int> vec = operator PoolVector<int>(); return stringify_vector(operator PoolVector<int>(), stack);
String str("[");
for (int i = 0; i < vec.size(); i++) {
if (i > 0) {
str += ", ";
}
str = str + itos(vec[i]);
}
str += "]";
return str;
} break; } break;
case POOL_REAL_ARRAY: { case POOL_REAL_ARRAY: {
PoolVector<real_t> vec = operator PoolVector<real_t>(); return stringify_vector(operator PoolVector<real_t>(), stack);
String str("[");
for (int i = 0; i < vec.size(); i++) {
if (i > 0) {
str += ", ";
}
str = str + rtos(vec[i]);
}
str += "]";
return str;
} break; } break;
case ARRAY: { case ARRAY: {
Array arr = operator Array(); Array arr = operator Array();
@ -1484,17 +1458,7 @@ String Variant::stringify(List<const void *> &stack) const {
return "[...]"; return "[...]";
} }
stack.push_back(arr.id()); stack.push_back(arr.id());
String str = stringify_vector(arr, stack);
String str("[");
for (int i = 0; i < arr.size(); i++) {
if (i) {
str += ", ";
}
str += arr[i].stringify(stack);
}
str += "]";
stack.erase(arr.id()); stack.erase(arr.id());
return str; return str;