From 9cc790869ed3905c78c7eeeb0bb44f800b3f2af4 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:11:09 +0200 Subject: 3.15 --- shared/zbase.h | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'shared/zbase.h') diff --git a/shared/zbase.h b/shared/zbase.h index a0322de0..f08a87e3 100644 --- a/shared/zbase.h +++ b/shared/zbase.h @@ -125,7 +125,7 @@ private: static size_t calcCapacity(size_t length) { - return (length + (19 - length % 16)); //allocate some additional length to speed up concatenation + return std::max(16, length + length / 2); //exponential growth + min size } }; @@ -207,7 +207,7 @@ private: static size_t calcCapacity(size_t length) { - return (length + (19 - length % 16)); //allocate some additional length to speed up concatenation + return std::max(16, length + length / 2); //exponential growth + min size } }; @@ -228,6 +228,11 @@ public: operator const T* () const; //implicit conversion to C-string //STL accessors + typedef T* iterator; + typedef const T* const_iterator; + typedef T& reference; + typedef const T& const_reference; + typedef T value_type; const T* begin() const; const T* end() const; T* begin(); @@ -262,11 +267,13 @@ public: size_t find(const T* str, size_t pos = 0) const; //returns "npos" if not found size_t find(T ch, size_t pos = 0) const; // size_t rfind(T ch, size_t pos = npos) const; // + size_t rfind(const T* str, size_t pos = npos) const; // Zbase& replace(size_t pos1, size_t n1, const T* str, size_t n2); void reserve(size_t minCapacity); Zbase& assign(const T* source, size_t len); void resize(size_t newSize, T fillChar = 0); void swap(Zbase& other); + void push_back(T val); //STL access //number conversion template static Zbase fromNumber(N number); @@ -619,6 +626,21 @@ size_t Zbase::rfind(T ch, size_t pos) const } +template class SP, class AP> +inline +size_t Zbase::rfind(const T* str, size_t pos) const +{ + assert(pos == npos || pos <= length()); + + const size_t strLen = z_impl::cStringLength(str); + const T* currEnd = pos == npos ? end() : begin() + std::min(pos + strLen, length()); + + const T* iter = std::find_end(begin(), currEnd, + str, str + strLen); + return iter == currEnd ? npos : iter - begin(); +} + + template class SP, class AP> Zbase& Zbase::replace(size_t pos1, size_t n1, const T* str, size_t n2) { @@ -861,6 +883,14 @@ T* Zbase::end() } +template class SP, class AP> +inline +void Zbase::push_back(T val) +{ + operator+=(val); +} + + template class SP, class AP> inline bool Zbase::empty() const @@ -1067,8 +1097,8 @@ template inline N Zbase::toNumber() const { - std::basic_istringstream ss(std::basic_string(rawStr)); - T number = 0; + std::basic_istringstream ss((std::basic_string(rawStr))); + N number = 0; ss >> number; return number; } -- cgit