summaryrefslogtreecommitdiff
path: root/core/array.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/array.cpp')
-rw-r--r--core/array.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/core/array.cpp b/core/array.cpp
index 1d283a14aa..bb8e527304 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -150,17 +150,26 @@ void Array::erase(const Variant& p_value) {
_p->array.erase(p_value);
}
-int Array::find(const Variant& p_value) const {
+int Array::find(const Variant& p_value, int p_from) const {
- return _p->array.find(p_value);
+ return _p->array.find(p_value, p_from);
}
-int Array::find_last(const Variant& p_value) const {
+int Array::rfind(const Variant& p_value, int p_from) const {
- if(_p->array.size() == 0)
+ if (_p->array.size() == 0)
return -1;
- for (int i=_p->array.size()-1; i>=0; i--) {
+ if (p_from < 0) {
+ // Relative offset from the end
+ p_from = _p->array.size() + p_from;
+ }
+ if (p_from < 0 || p_from >= _p->array.size()) {
+ // Limit to array boundaries
+ p_from = _p->array.size() - 1;
+ }
+
+ for (int i=p_from; i>=0; i--) {
if(_p->array[i] == p_value){
return i;
@@ -170,6 +179,11 @@ int Array::find_last(const Variant& p_value) const {
return -1;
}
+int Array::find_last(const Variant& p_value) const {
+
+ return rfind(p_value);
+}
+
int Array::count(const Variant& p_value) const {
if(_p->array.size() == 0)