summaryrefslogtreecommitdiffstats
path: root/core/cowdata.h
diff options
context:
space:
mode:
authorIbrahn Sahir <ibrahn.sahir@gmail.com>2019-01-07 17:02:55 +0000
committerIbrahn Sahir <ibrahn.sahir@gmail.com>2019-01-07 17:34:44 +0000
commitcbb396c0064d77ec50a524241d22746c8b69bbdb (patch)
treee232fceee2453a3cd85ea20c44abc877b0f49b23 /core/cowdata.h
parentbcecf5626768c8399e9293fe12a25511eeb6c52d (diff)
downloadredot-engine-cbb396c0064d77ec50a524241d22746c8b69bbdb.tar.gz
Repair String lstrip and rstrip.
Background: lstrip and rstrip were broken by changes to String in: 0e29f7974b59e4440cf02e1388fb9d8ab2b5c5fd which removed it's access to Vector::find(CharType). Moved Vector's find up into CowData so it can be shared by Vector and String. Added String::find_char using CowData::find. Implemented rstrip and lstrip using find_char. Added a few tests for String rstrip and lstrip.
Diffstat (limited to 'core/cowdata.h')
-rw-r--r--core/cowdata.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/cowdata.h b/core/cowdata.h
index 319e61d261..3e40ad0f4b 100644
--- a/core/cowdata.h
+++ b/core/cowdata.h
@@ -179,6 +179,8 @@ public:
return OK;
};
+ int find(const T &p_val, int p_from = 0) const;
+
_FORCE_INLINE_ CowData();
_FORCE_INLINE_ ~CowData();
_FORCE_INLINE_ CowData(CowData<T> &p_from) { _ref(p_from); };
@@ -316,6 +318,24 @@ Error CowData<T>::resize(int p_size) {
}
template <class T>
+int CowData<T>::find(const T &p_val, int p_from) const {
+ int ret = -1;
+
+ if (p_from < 0 || size() == 0) {
+ return ret;
+ }
+
+ for (int i = p_from; i < size(); i++) {
+ if (get(i) == p_val) {
+ ret = i;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+template <class T>
void CowData<T>::_ref(const CowData *p_from) {
_ref(*p_from);
}