mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 18:22:59 +02:00
Add missing functions
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "Poco/StringTokenizer.h"
|
||||
#include "Poco/Ascii.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@@ -77,6 +78,47 @@ StringTokenizer::StringTokenizer(const std::string& str, const std::string& sepa
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t StringTokenizer::count(const std::string& token) const
|
||||
{
|
||||
std::size_t result = 0;
|
||||
TokenVec::const_iterator it = std::find(_tokens.begin(), _tokens.end(), token);
|
||||
while(it != _tokens.end())
|
||||
{
|
||||
result++;
|
||||
it = std::find(++it, _tokens.end(), token);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::size_t StringTokenizer::find(const std::string& token, std::size_t pos) const
|
||||
{
|
||||
TokenVec::const_iterator it = std::find(_tokens.begin() + pos, _tokens.end(), token);
|
||||
if ( it != _tokens.end() )
|
||||
{
|
||||
return it - _tokens.begin();
|
||||
}
|
||||
throw NotFoundException(token);
|
||||
}
|
||||
|
||||
bool StringTokenizer::has(const std::string& token) const
|
||||
{
|
||||
TokenVec::const_iterator it = std::find(_tokens.begin(), _tokens.end(), token);
|
||||
return it != _tokens.end();
|
||||
}
|
||||
|
||||
std::size_t StringTokenizer::replace(const std::string& oldToken, const std::string& newToken, std::size_t pos)
|
||||
{
|
||||
std::size_t result = 0;
|
||||
TokenVec::iterator it = std::find(_tokens.begin() + pos, _tokens.end(), oldToken);
|
||||
while(it != _tokens.end())
|
||||
{
|
||||
result++;
|
||||
*it = newToken;
|
||||
it = std::find(++it, _tokens.end(), oldToken);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
StringTokenizer::~StringTokenizer()
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizerTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
@@ -411,6 +411,7 @@ void StringTokenizerTest::testFind()
|
||||
assert (2 == st.count("5"));
|
||||
|
||||
st.replace("3", "6", 4);
|
||||
|
||||
assert (1 == st.count("3"));
|
||||
assert (1 == st.count("6"));
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
~StringTokenizerTest();
|
||||
|
||||
void testStringTokenizer();
|
||||
void testFind();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
Reference in New Issue
Block a user