This commit is contained in:
Marian Krivos 2012-04-29 11:24:44 +00:00
parent 0ad8b3c924
commit c33bf13bdc
3 changed files with 24 additions and 82 deletions

View File

@ -78,6 +78,12 @@ StringTokenizer::StringTokenizer(const std::string& str, const std::string& sepa
} }
} }
StringTokenizer::~StringTokenizer()
{
}
std::size_t StringTokenizer::count(const std::string& token) const std::size_t StringTokenizer::count(const std::string& token) const
{ {
std::size_t result = 0; std::size_t result = 0;
@ -120,65 +126,6 @@ std::size_t StringTokenizer::replace(const std::string& oldToken, const std::str
return result; return result;
} }
StringTokenizer::~StringTokenizer()
{
}
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 == token)
return it - begin();
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;
}
} // namespace Poco } // namespace Poco

View File

@ -49,24 +49,24 @@ public:
void testClear(); void testClear();
void testCacheSize0(); void testCacheSize0();
void testCacheSize1(); void testCacheSize1();
void testCacheSize2(); void testCacheSize2();
void testCacheSizeN(); void testCacheSizeN();
void testDuplicateAdd(); void testDuplicateAdd();
void testUpdate(); void testUpdate();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();
private: private:
void onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args); void onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args);
void onAdd(const void* pSender, const Poco::KeyValueArgs<int, int>& args); void onAdd(const void* pSender, const Poco::KeyValueArgs<int, int>& args);
void onRemove(const void* pSender, const int& args); void onRemove(const void* pSender, const int& args);
private: private:
int addCnt; int addCnt;
int updateCnt; int updateCnt;
int removeCnt; int removeCnt;
}; };

View File

@ -31,32 +31,27 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef StringTokenizerTest_INCLUDED #ifndef StringTokenizerTest_INCLUDED
#define StringTokenizerTest_INCLUDED #define StringTokenizerTest_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "CppUnit/TestCase.h" #include "CppUnit/TestCase.h"
class StringTokenizerTest: public CppUnit::TestCase class StringTokenizerTest: public CppUnit::TestCase
{ {
public: public:
StringTokenizerTest(const std::string& name); StringTokenizerTest(const std::string& name);
~StringTokenizerTest(); ~StringTokenizerTest();
void testStringTokenizer(); void testStringTokenizer();
void testFind();
void testFind(); void testFind();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();
private: private:
}; };
#endif // StringTokenizerTest_INCLUDED #endif // StringTokenizerTest_INCLUDED