ULTIMA: Moving many string methods from Std::String to Common::String
This commit is contained in:
parent
b338b8993d
commit
a178952464
5 changed files with 147 additions and 184 deletions
|
@ -34,111 +34,6 @@ string::string(size_t n, char c) : Common::String() {
|
|||
(*this) += c;
|
||||
}
|
||||
|
||||
size_t string::find(char c, size_t pos) const {
|
||||
const char *p = strchr(_str + pos, c);
|
||||
return p ? p - _str : npos;
|
||||
}
|
||||
|
||||
size_t string::find(const char *s) const {
|
||||
const char *str = strstr(_str, s);
|
||||
return str ? str - _str : npos;
|
||||
}
|
||||
|
||||
size_t string::rfind(const char *s) const {
|
||||
int sLen = strlen(s);
|
||||
|
||||
for (int idx = (int)_size - sLen; idx >= 0; --idx) {
|
||||
if (!strncmp(_str + idx, s, sLen))
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t string::rfind(char c, size_t pos) const {
|
||||
for (int idx = MIN((int)_size - 1, (int)pos); idx >= 0; --idx) {
|
||||
if ((*this)[idx] == c)
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t string::find_first_of(char c, size_t pos) const {
|
||||
const char *strP = (pos >= _size) ? 0 : strchr(_str + pos, c);
|
||||
return strP ? strP - _str : npos;
|
||||
}
|
||||
|
||||
size_t string::find_first_of(const char *chars, size_t pos) const {
|
||||
for (uint idx = pos; idx < _size; ++idx) {
|
||||
if (strchr(chars, (*this)[idx]))
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t string::find_first_not_of(char c, size_t pos) const {
|
||||
for (uint idx = pos; idx < _size; ++idx) {
|
||||
if ((*this)[idx] != c)
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t string::find_first_not_of(const char *chars, size_t pos) const {
|
||||
for (uint idx = pos; idx < _size; ++idx) {
|
||||
if (!strchr(chars, (*this)[idx]))
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t string::find_last_not_of(char c) const {
|
||||
for (int idx = (int)_size - 1; idx >= 0; --idx) {
|
||||
if ((*this)[idx] != c)
|
||||
return c;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t string::find_last_not_of(const char *chars) const {
|
||||
for (int idx = (int)_size - 1; idx >= 0; --idx) {
|
||||
if (!strchr(chars, (*this)[idx]))
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
string string::substr(size_t pos, size_t len) const {
|
||||
if (pos >= _size)
|
||||
return string();
|
||||
else if (len == npos)
|
||||
return string(_str + pos);
|
||||
else
|
||||
return string(_str + pos, MIN(_size - pos, len));
|
||||
}
|
||||
|
||||
string &string::erase(size_t pos, size_t len) {
|
||||
if (pos < _size) {
|
||||
if (len == npos || (pos + len) >= _size)
|
||||
*this = string(_str, _str + pos);
|
||||
else
|
||||
*this = string(_str, _str + pos) + string(_str + pos + len);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
string::iterator string::erase(iterator it) {
|
||||
this->deleteChar(it - _str);
|
||||
return it;
|
||||
}
|
||||
|
||||
void string::resize(size_t count) {
|
||||
if (count == 0)
|
||||
clear();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue