Skip to content

Commit

Permalink
Unify Pool*Array printing output
Browse files Browse the repository at this point in the history
Co-authored-by: mashumafi <mashumafi@gmail.com>
  • Loading branch information
YuriSizov and mashumafi committed Oct 12, 2021
1 parent 779a5e5 commit c210672
Showing 1 changed file with 25 additions and 61 deletions.
86 changes: 25 additions & 61 deletions core/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,19 @@ Variant::operator String() const {
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 {
switch (type) {
case NIL:
Expand Down Expand Up @@ -1419,82 +1432,33 @@ String Variant::stringify(List<const void *> &stack) const {
return str;
} break;
case POOL_VECTOR2_ARRAY: {
PoolVector<Vector2> vec = operator PoolVector<Vector2>();
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<Vector2>(), stack);
} break;
case POOL_VECTOR3_ARRAY: {
PoolVector<Vector3> vec = operator PoolVector<Vector3>();
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<Vector3>(), stack);
} break;
case POOL_COLOR_ARRAY: {
return stringify_vector(operator PoolVector<Color>(), stack);
} break;
case POOL_STRING_ARRAY: {
PoolVector<String> vec = operator PoolVector<String>();
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<String>(), stack);
} break;
case POOL_BYTE_ARRAY: {
return stringify_vector(operator PoolVector<uint8_t>(), stack);
} break;
case POOL_INT_ARRAY: {
PoolVector<int> vec = operator PoolVector<int>();
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<int>(), stack);
} break;
case POOL_REAL_ARRAY: {
PoolVector<real_t> vec = operator PoolVector<real_t>();
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<real_t>(), stack);
} break;
case ARRAY: {
Array arr = operator Array();
if (stack.find(arr.id())) {
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;

Expand Down

0 comments on commit c210672

Please sign in to comment.