From 91a12a3ea514eba0a10a05e2a52f60adb5a44a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Fri, 10 Oct 2014 15:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=8E=9F=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/String.h | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/TinySTL/String.h b/TinySTL/String.h index e6bf937..71ceaa1 100644 --- a/TinySTL/String.h +++ b/TinySTL/String.h @@ -109,8 +109,7 @@ namespace TinySTL{ string& replace(size_t pos, size_t len, const string& str); string& replace(iterator i1, iterator i2, const string& str); - string& replace(size_t pos, size_t len, const string& str, - size_t subpos, size_t sublen = npos); + string& replace(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen = npos); string& replace(size_t pos, size_t len, const char* s); string& replace(iterator i1, iterator i2, const char* s); string& replace(size_t pos, size_t len, const char* s, size_t n); @@ -118,14 +117,54 @@ namespace TinySTL{ string& replace(size_t pos, size_t len, size_t n, char c); string& replace(iterator i1, iterator i2, size_t n, char c); template - string& replace(iterator i1, iterator i2, - InputIterator first, InputIterator last); + string& replace(iterator i1, iterator i2, InputIterator first, InputIterator last); void swap(string& str){ std::swap(start_, str.start_); std::swap(finish_, str.finish_); std::swap(endOfStorage_, str.endOfStorage_); } + size_t copy(char* s, size_t len, size_t pos = 0) const{ + auto ptr = TinySTL::uninitialized_copy(begin() + pos, begin() + pos + len, s); + return (size_t)(ptr - s); + } + + size_t find(const string& str, size_t pos = 0) const; + size_t find(const char* s, size_t pos = 0) const; + size_t find(const char* s, size_t pos, size_t n) const; + size_t find(char c, size_t pos = 0) const; + size_t rfind(const string& str, size_t pos = npos) const; + size_t rfind(const char* s, size_t pos = npos) const; + size_t rfind(const char* s, size_t pos, size_t n) const; + size_t rfind(char c, size_t pos = npos) const; + size_t find_first_of(const string& str, size_t pos = 0) const; + size_t find_first_of(const char* s, size_t pos = 0) const; + size_t find_first_of(const char* s, size_t pos, size_t n) const; + size_t find_first_of(char c, size_t pos = 0) const; + size_t find_last_of(const string& str, size_t pos = npos) const; + size_t find_last_of(const char* s, size_t pos = npos) const; + size_t find_last_of(const char* s, size_t pos, size_t n) const; + size_t find_last_of(char c, size_t pos = npos) const; + size_t find_first_not_of(const string& str, size_t pos = 0) const; + size_t find_first_not_of(const char* s, size_t pos = 0) const; + size_t find_first_not_of(const char* s, size_t pos, size_t n) const; + size_t find_first_not_of(char c, size_t pos = 0) const; + size_t find_last_not_of(const string& str, size_t pos = npos) const; + size_t find_last_not_of(const char* s, size_t pos = npos) const; + size_t find_last_not_of(const char* s, size_t pos, size_t n) const; + size_t find_last_not_of(char c, size_t pos = npos) const; + + string substr(size_t pos = 0, size_t len = npos) const{ + return string(begin() + pos, begin() + pos + len); + } + + int compare(const string& str) const noexcept; + int compare(size_t pos, size_t len, const string& str) const; + int compare(size_t pos, size_t len, const string& str, + size_t subpos, size_t sublen = npos) const; + int compare(const char* s) const; + int compare(size_t pos, size_t len, const char* s) const; + int compare(size_t pos, size_t len, const char* s, size_t n) const; private: //插入时空间不足的情况 template