From cbb396c0064d77ec50a524241d22746c8b69bbdb Mon Sep 17 00:00:00 2001 From: Ibrahn Sahir Date: Mon, 7 Jan 2019 17:02:55 +0000 Subject: 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. --- core/cowdata.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'core/cowdata.h') 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 &p_from) { _ref(p_from); }; @@ -315,6 +317,24 @@ Error CowData::resize(int p_size) { return OK; } +template +int CowData::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 void CowData::_ref(const CowData *p_from) { _ref(*p_from); -- cgit v1.2.3