diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-07-10 13:32:37 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-10 13:32:37 -0300 |
commit | 9dac41432e9aeaf2b96af9cd3ce44389c604c28a (patch) | |
tree | f23bec0cbae8c7c125f635d8dbf9823074703762 | |
parent | bcf6491a86038559356729f28c98574c8086172f (diff) | |
parent | 9ac7eaa89caa9f4613f39df1ffc5d08fc8f20168 (diff) |
Merge pull request #5443 from samuelgrigolato/iterate-string-in-gdscript
Add support to String type in gdscript iteration
-rw-r--r-- | core/variant_op.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/core/variant_op.cpp b/core/variant_op.cpp index e549161de9..9182dcde1a 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -2911,6 +2911,14 @@ bool Variant::iter_init(Variant& r_iter,bool &valid) const { return ret; } break; + case STRING: { + + const String *str=reinterpret_cast<const String*>(_data._mem); + if (str->empty()) + return false; + r_iter = 0; + return true; + } break; case DICTIONARY: { const Dictionary *dic=reinterpret_cast<const Dictionary*>(_data._mem); @@ -3028,6 +3036,17 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const { return ret; } break; + + case STRING: { + + const String *str=reinterpret_cast<const String*>(_data._mem); + int idx = r_iter; + idx++; + if (idx >= str->size()) + return false; + r_iter = idx; + return true; + } break; case DICTIONARY: { const Dictionary *dic=reinterpret_cast<const Dictionary*>(_data._mem); @@ -3158,6 +3177,11 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const { return ret; } break; + case STRING: { + + const String *str=reinterpret_cast<const String*>(_data._mem); + return str->substr(r_iter,1); + } break; case DICTIONARY: { return r_iter; //iterator is the same as the key |