From 1ac43ce99b789e9fb143b9e56960675f05de8b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 11 Oct 2014 09:52:52 +0800 Subject: [PATCH] find_first_not_of bug fix --- TinySTL/String.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/TinySTL/String.h b/TinySTL/String.h index 80d8160..7db7567 100644 --- a/TinySTL/String.h +++ b/TinySTL/String.h @@ -604,7 +604,7 @@ namespace TinySTL{ return compare_aux(pos, len, s, 0, n); } size_t string::find_first_of(const string& str, size_t pos) const{ - return find_first_of(str.begin(), pos, str.size() - pos); + return find_first_of(str.begin(), pos, size() - pos); } size_t string::find_first_of(const char* s, size_t pos) const{ return find_first_of(s, pos, size() - pos); @@ -620,7 +620,7 @@ namespace TinySTL{ return find(c, pos); } size_t string::find_first_not_of(const string& str, size_t pos) const{ - return find_first_not_of(str.begin(), pos, str.size() - pos); + return find_first_not_of(str.begin(), pos, size() - pos); } size_t string::find_first_not_of(const char* s, size_t pos) const{ return find_first_not_of(s, pos, size() - pos); @@ -639,26 +639,20 @@ namespace TinySTL{ } return npos; } - //size_t string::find_last_of(const string& str, size_t pos = npos) const; + size_t string::find_last_of(const string& str, size_t pos) const{ + if (pos == npos) + pos = size() - 1; + return find_last_of(str.begin(), pos, pos + 1); + } size_t string::find_last_of(const char* s, size_t pos) const{ if (pos == npos) pos = size() - 1; return find_last_of(s, pos, pos + 1); } size_t string::find_last_of(const char* s, size_t pos, size_t n) const{ - /*size_t lengthOfS = strlen(s);*/ - /*if (n < lengthOfS) - return npos;*/ - size_t i, j; - for (i = pos; i != 0 && i != pos - n; --i){ + for (size_t i = pos; i != 0 && i != pos - n; --i){ if (isContained((*this)[i], s, s + strlen(s))) return i; - /*for (j = 0; j != lengthOfS; ++j){ - if ((*this)[i + j] != s[j]) - break; - } - if (j == lengthOfS) - return i;*/ } return npos; }