[SF 2479446] Extend StringTokenizer interface

This commit is contained in:
Aleksandar Fabijanic
2008-12-31 19:31:03 +00:00
parent 66dc4abff0
commit 736cb1fcee
3 changed files with 109 additions and 10 deletions

View File

@@ -83,14 +83,55 @@ StringTokenizer::~StringTokenizer()
}
std::size_t StringTokenizer::find(const std::string& key, std::size_t pos) const
bool StringTokenizer::has(const std::string& token) const
{
Iterator it = begin();
Iterator stop = end();
for (; it != stop; ++it)
if (*it == token) return true;
return false;
}
std::size_t StringTokenizer::find(const std::string& token, std::size_t pos) const
{
Iterator it = begin();
Iterator stop = end();
for (it += pos; it != stop; ++it)
if (*it == key) return it - begin();
if (*it == token) return it - begin();
throw NotFoundException(key);
throw NotFoundException(token);
}
std::size_t StringTokenizer::replace(const std::string& oldToken, const std::string& newToken, std::size_t pos)
{
std::size_t count = 0;
TokenVec::iterator it = _tokens.begin();
TokenVec::iterator stop = _tokens.end();
for (it += pos; it != stop; ++it)
{
if (*it == oldToken)
{
*it = newToken;
++count;
}
}
return count;
}
std::size_t StringTokenizer::count(const std::string& token) const
{
std::size_t cnt = 0;
Iterator it = begin();
Iterator stop = end();
for (; it != stop; ++it)
if (*it == token) ++cnt;
return cnt;
}