Use boost::algorithm::string::split for splitting strings into tokens.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 7 Sep 2009 09:48:50 +0000 (11:48 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 7 Sep 2009 09:48:50 +0000 (11:48 +0200)
src/dhs.cpp
src/dhs.h
src/dyns.cpp
src/dyns.h
src/easydns.cpp
src/easydns.h

index bbb9940..befed5c 100644 (file)
@@ -11,6 +11,9 @@
 
 #include <time.h>
 #include <boost/foreach.hpp>
+#include <boost/algorithm/string.hpp>
+
+namespace ba = boost::algorithm;
 
 using namespace std;
 
@@ -108,7 +111,8 @@ string DHS::assemble_base_url(const string& hostname, const string& domain_part)
  */
 list<string> DHS::separate_domain_and_host_part(const string& fqdn) const
 {
-    list<string> splitted = split(fqdn,".");
+    list<string> splitted;
+    ba::split(splitted,fqdn,boost::is_any_of("."));
 
     if ( splitted.size() > 1 )
     {
@@ -134,33 +138,6 @@ list<string> DHS::separate_domain_and_host_part(const string& fqdn) const
 
 
 /**
- * Splitts a string into single tokens useing given delimiters
- * @param str String to split
- * @param delimiters Deliminters to use
- * @return A list with the single tokens
- */
-list<string> DHS::split(const string& str,const string& delimiters) const
-{
-    list<string> tokens;
-    // Skip delimiters at beginning.
-    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
-    // Find first "non-delimiter".
-    string::size_type pos = str.find_first_of(delimiters, lastPos);
-
-    while (string::npos != pos || string::npos != lastPos)
-    {
-        // Found a token, add it to the list.
-        tokens.push_back(str.substr(lastPos, pos - lastPos));
-        // Skip delimiters.  Note the "not_of"
-        lastPos = str.find_first_not_of(delimiters, pos);
-        // Find next "non-delimiter"
-        pos = str.find_first_of(delimiters, lastPos);
-    }
-    return tokens;
-}
-
-
-/**
  * Performs the Service update.
  * @param ip IP Address to set.
  * @return 0 if all is fine, -1 otherwise.
index 54e818b..eb70951 100644 (file)
--- a/src/dhs.h
+++ b/src/dhs.h
@@ -32,8 +32,6 @@ private:
 
     HTTPHelper::Ptr HTTPHelp;
 
-    std::list<std::string> split(const std::string& str,const std::string& delimiters) const;
-
     std::list<std::string> separate_domain_and_host_part(const std::string& str) const;
 
     std::string assemble_base_url(const std::string& hostname, const std::string& domain_part) const;
index 7a2229d..4ef7391 100644 (file)
@@ -11,6 +11,9 @@
 
 #include <time.h>
 #include <boost/foreach.hpp>
+#include <boost/algorithm/string.hpp>
+
+namespace ba = boost::algorithm;
 
 using namespace std;
 
@@ -142,35 +145,9 @@ int DYNS::perform_update(const std::string& ip)
  */
 string DYNS::parse_status_code(const string& data) const
 {
-    list<string> tokens = split(data," ");
-    return tokens.front();
-}
-
-
-/**
- * Splitts a string into single tokens useing given delimiters
- * @param str String to split
- * @param delimiters Deliminters to use
- * @return A list with the single tokens
- */
-list<string> DYNS::split(const string& str,const string& delimiters) const
-{
     list<string> tokens;
-    // Skip delimiters at beginning.
-    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
-    // Find first "non-delimiter".
-    string::size_type pos = str.find_first_of(delimiters, lastPos);
-
-    while (string::npos != pos || string::npos != lastPos)
-    {
-        // Found a token, add it to the list.
-        tokens.push_back(str.substr(lastPos, pos - lastPos));
-        // Skip delimiters.  Note the "not_of"
-        lastPos = str.find_first_not_of(delimiters, pos);
-        // Find next "non-delimiter"
-        pos = str.find_first_of(delimiters, lastPos);
-    }
-    return tokens;
+    ba::split(tokens,data,boost::is_any_of(" "));
+    return tokens.front();
 }
 
 
index 1650f80..f21afd9 100644 (file)
@@ -36,8 +36,6 @@ private:
 
     std::string parse_status_code(const std::string& data) const;
 
-    std::list<std::string> split(const std::string& str,const std::string& delimiters) const;
-
 public:
 
     typedef boost::shared_ptr<DYNS> Ptr;
index 8840776..843fb9c 100644 (file)
@@ -11,6 +11,9 @@
 
 #include <time.h>
 #include <boost/foreach.hpp>
+#include <boost/algorithm/string.hpp>
+
+namespace ba = boost::algorithm;
 
 using namespace std;
 
@@ -86,7 +89,8 @@ string EASYDNS::get_two_level_tld(const string& domain_part) const
     // TODO: There is a list with all two level TLD's, use it
 
     // split the domain_part
-    list<string> domain_tokens = split(domain_part,".");
+    list<string> domain_tokens;
+    ba::split(domain_tokens,domain_part,boost::is_any_of("."));
 
     domain_tokens.pop_front();
 
@@ -146,7 +150,8 @@ string EASYDNS::assemble_base_url(const string& hostname, const string& two_leve
  */
 list<string> EASYDNS::separate_domain_and_host_part(const string& fqdn) const
 {
-    list<string> splitted = split(fqdn,".");
+    list<string> splitted;
+    ba::split(splitted,fqdn,boost::is_any_of("."));
 
     if ( splitted.size() > 1 )
     {
@@ -172,33 +177,6 @@ list<string> EASYDNS::separate_domain_and_host_part(const string& fqdn) const
 
 
 /**
- * Splitts a string into single tokens useing given delimiters
- * @param str String to split
- * @param delimiters Deliminters to use
- * @return A list with the single tokens
- */
-list<string> EASYDNS::split(const string& str,const string& delimiters) const
-{
-    list<string> tokens;
-    // Skip delimiters at beginning.
-    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
-    // Find first "non-delimiter".
-    string::size_type pos = str.find_first_of(delimiters, lastPos);
-
-    while (string::npos != pos || string::npos != lastPos)
-    {
-        // Found a token, add it to the list.
-        tokens.push_back(str.substr(lastPos, pos - lastPos));
-        // Skip delimiters.  Note the "not_of"
-        lastPos = str.find_first_not_of(delimiters, pos);
-        // Find next "non-delimiter"
-        pos = str.find_first_of(delimiters, lastPos);
-    }
-    return tokens;
-}
-
-
-/**
  * Performs the Service update.
  * @param ip IP Address to set.
  * @return 0 if all is fine, -1 otherwise.
index ddd0812..2e4fed7 100644 (file)
@@ -32,8 +32,6 @@ private:
 
     HTTPHelper::Ptr HTTPHelp;
 
-    std::list<std::string> split(const std::string& str,const std::string& delimiters) const;
-
     std::list<std::string> separate_domain_and_host_part(const std::string& str) const;
 
     std::string assemble_base_url(const std::string& hostname, const std::string& two_level_tld) const;