size_t string::rfind(char c, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); for (auto cit = cbegin() + pos; cit >= cbegin(); --cit) { if (*cit == c) return cit - cbegin(); } return npos; }
size_t string::find_last_not_of(char c, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); for (int i = pos; i >= 0; --i) { if ((*this)[i] != c) return i; } return npos; }
string::string(const string &str, size_t pos, size_t len){ len = changeVarWhenEuqalNPOS(len, str.size(), pos); allocateAndCopy(str.start_ + pos, str.start_ + pos + len); }
string& string::append(const string& str, size_t subpos, size_t sublen){ sublen = changeVarWhenEuqalNPOS(sublen, str.size(), subpos); insert(size(),str,subpos,sublen); return *this; }
size_t string::find_last_not_of(const char* s, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); return find_last_not_of(s, pos, strlen(s)); }
size_t string::find_last_not_of(const string& str, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); return find_last_not_of(str.begin(), pos, str.size()); }
size_t string::rfind(const char* s, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); return rfind(s, pos, strlen(s)); }
size_t string::rfind(const string& str, size_t pos) const { auto lengthOfS = str.size(); pos = changeVarWhenEuqalNPOS(pos, size(), 1); return rfind_aux(str.begin(), pos, lengthOfS, 0); }
string& string::replace(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen) { sublen = changeVarWhenEuqalNPOS(sublen, str.size(), subpos); return replace(begin() + pos, begin() + pos + len, str.begin() + subpos, str.begin() + subpos + sublen); }
string& string::erase(size_t pos, size_t len) { len = changeVarWhenEuqalNPOS(len, size(), pos); erase(begin() + pos, begin() + pos + len); return *this; }
string& string::insert(size_t pos, const string& str, size_t subpos, size_t sublen) { sublen = changeVarWhenEuqalNPOS(sublen, str.size(), subpos); insert(begin() + pos, str.begin() + subpos, str.begin() + subpos + sublen); return *this; }