Prettier str() for arrays

This commit is contained in:
Ignacio Etcheverry 2016-07-02 15:54:37 +02:00
parent 5b96496a99
commit 38ed5d9c7d
1 changed files with 12 additions and 6 deletions

View File

@ -1559,72 +1559,78 @@ Variant::operator String() const {
case VECTOR2_ARRAY: { case VECTOR2_ARRAY: {
DVector<Vector2> vec = operator DVector<Vector2>(); DVector<Vector2> vec = operator DVector<Vector2>();
String str; String str("[");
for(int i=0;i<vec.size();i++) { for(int i=0;i<vec.size();i++) {
if (i>0) if (i>0)
str+=", "; str+=", ";
str=str+Variant( vec[i] ); str=str+Variant( vec[i] );
} }
str += "]";
return str; return str;
} break; } break;
case VECTOR3_ARRAY: { case VECTOR3_ARRAY: {
DVector<Vector3> vec = operator DVector<Vector3>(); DVector<Vector3> vec = operator DVector<Vector3>();
String str; String str("[");
for(int i=0;i<vec.size();i++) { for(int i=0;i<vec.size();i++) {
if (i>0) if (i>0)
str+=", "; str+=", ";
str=str+Variant( vec[i] ); str=str+Variant( vec[i] );
} }
str += "]";
return str; return str;
} break; } break;
case STRING_ARRAY: { case STRING_ARRAY: {
DVector<String> vec = operator DVector<String>(); DVector<String> vec = operator DVector<String>();
String str; String str("[");
for(int i=0;i<vec.size();i++) { for(int i=0;i<vec.size();i++) {
if (i>0) if (i>0)
str+=", "; str+=", ";
str=str+vec[i]; str=str+vec[i];
} }
str += "]";
return str; return str;
} break; } break;
case INT_ARRAY: { case INT_ARRAY: {
DVector<int> vec = operator DVector<int>(); DVector<int> vec = operator DVector<int>();
String str; String str("[");
for(int i=0;i<vec.size();i++) { for(int i=0;i<vec.size();i++) {
if (i>0) if (i>0)
str+=", "; str+=", ";
str=str+itos(vec[i]); str=str+itos(vec[i]);
} }
str += "]";
return str; return str;
} break; } break;
case REAL_ARRAY: { case REAL_ARRAY: {
DVector<real_t> vec = operator DVector<real_t>(); DVector<real_t> vec = operator DVector<real_t>();
String str; String str("[");
for(int i=0;i<vec.size();i++) { for(int i=0;i<vec.size();i++) {
if (i>0) if (i>0)
str+=", "; str+=", ";
str=str+rtos(vec[i]); str=str+rtos(vec[i]);
} }
str += "]";
return str; return str;
} break; } break;
case ARRAY: { case ARRAY: {
Array arr = operator Array(); Array arr = operator Array();
String str; String str("[");
for (int i=0; i<arr.size(); i++) { for (int i=0; i<arr.size(); i++) {
if (i) if (i)
str+=", "; str+=", ";
str += String(arr[i]); str += String(arr[i]);
}; };
str += "]";
return str; return str;
} break; } break;