summaryrefslogtreecommitdiff
path: root/core/variant_op.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/variant_op.cpp')
-rw-r--r--core/variant_op.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 9c489c5ef2..ec43b1275c 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -922,21 +922,31 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
case REAL: { return; } break;
case STRING: {
- if (p_value.type!=Variant::STRING)
+
+ if (p_index.type!=Variant::INT && p_index.type!=Variant::REAL)
return;
- if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
- //string index
- int idx=p_index;
- String *str=reinterpret_cast<String*>(_data._mem);
- if (idx >=0 && idx<str->length()) {
- String chr = p_value;
- *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length());
- valid=true;
- return;
- }
+ int idx=p_index;
+ String *str=reinterpret_cast<String*>(_data._mem);
+ if (idx <0 || idx>=str->length())
+ return;
+
+ String chr;
+ if (p_value.type==Variant::INT || p_value.type==Variant::REAL) {
+
+ chr = String::chr(p_value);
+ } else if (p_value.type==Variant::STRING) {
+
+ chr = p_value;
+ } else {
+ return;
}
+ *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length());
+ valid=true;
+ return;
+
+
} break;
case VECTOR2: {
@@ -951,7 +961,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
Vector2 *v=reinterpret_cast<Vector2*>(_data._mem);
valid=true;
- v[idx]=p_value;
+ (*v)[idx]=p_value;
return;
}
} else if (p_index.get_type()==Variant::STRING) {
@@ -1045,7 +1055,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
Vector3 *v=reinterpret_cast<Vector3*>(_data._mem);
valid=true;
- v[idx]=p_value;
+ (*v)[idx]=p_value;
return;
}
} else if (p_index.get_type()==Variant::STRING) {