Add String::Contains().

Refs #5355
This commit is contained in:
Michael Friedrich 2013-12-17 12:19:29 +01:00
parent 12d32ad719
commit 7fa9188df8
4 changed files with 24 additions and 0 deletions

View File

@ -22,6 +22,8 @@
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/compare.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/classification.hpp>
using namespace icinga;
@ -179,6 +181,11 @@ void String::Trim(void)
boost::algorithm::trim(m_Data);
}
bool String::Contains(const String& str) const
{
return boost::algorithm::contains(m_Data, str);
}
void String::swap(String& str)
{
m_Data.swap(str.m_Data);

View File

@ -91,6 +91,7 @@ public:
void Replace(size_t first, size_t second, const String& str);
void Trim(void);
bool Contains(const String& str) const;
void swap(String& str);
Iterator erase(Iterator first, Iterator last);

View File

@ -62,6 +62,7 @@ add_boost_test(base
base_string/clear
base_string/append
base_string/trim
base_string/contains
base_string/replace
base_string/index
base_string/find

View File

@ -79,6 +79,21 @@ BOOST_AUTO_TEST_CASE(trim)
BOOST_CHECK(s4 == "hello");
}
BOOST_AUTO_TEST_CASE(contains)
{
String s1 = "hello world";
String s2 = "hello";
BOOST_CHECK(s1.Contains(s2));
String s3 = " hello world ";
String s4 = " hello";
BOOST_CHECK(s3.Contains(s4));
String s5 = " hello world ";
String s6 = "world ";
BOOST_CHECK(s5.Contains(s6));
}
BOOST_AUTO_TEST_CASE(replace)
{
String s = "hello";