From 8e5cf5623e9869334ee06297ef32e7df7b4b4c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Thu, 25 Dec 2014 10:43:01 +0800 Subject: [PATCH] bug fix --- TinySTL/String.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/TinySTL/String.h b/TinySTL/String.h index f4b7db5..d24e3e3 100644 --- a/TinySTL/String.h +++ b/TinySTL/String.h @@ -673,16 +673,24 @@ namespace TinySTL{ } size_t string::find_last_of(const string& str, size_t pos) const{ pos = changeVarWhenEuqalNPOS(pos, size(), 1); - return find_last_of(str.begin(), pos, pos + 1); + //return find_last_of(str.begin(), pos, pos + 1); + return find_last_of(str.begin(), pos, str.size()); } size_t string::find_last_of(const char* s, size_t pos) const{ pos = changeVarWhenEuqalNPOS(pos, size(), 1); - return find_last_of(s, pos, pos + 1); + //return find_last_of(s, pos, pos + 1); + return find_last_of(s, pos, strlen(s)); } size_t string::find_last_of(const char* s, size_t pos, size_t n) const{ - for (size_t i = pos, j = 0; i >= 0 && j != n; --i, ++j){ + /*for (size_t i = pos, j = 0; i >= 0 && j != n; --i, ++j){ if (isContained((*this)[i], s, s + strlen(s))) return i; + }*/ + //bug fix + //2014.12.25 + for (size_t i = pos; i > 0; --i){ + if (isContained((*this)[i], s, s + n)) + return i; } return npos; }