Repository :
http://git.fedorahosted.org/cgit/firewalld-recode.git
On branch : master
---------------------------------------------------------------
commit 1464b6f29a2bee7bbe19fe1aac7caad5fa55f368
Author: Daniel Kopecek <dkopecek(a)redhat.com>
Date: Wed Oct 22 13:15:04 2014 +0200
Generalize the tokenizeString utility function
---------------------------------------------------------------
src/Common/Utility.cpp | 23 -----------------------
src/Common/Utility.hpp | 24 +++++++++++++++++++++++-
2 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/src/Common/Utility.cpp b/src/Common/Utility.cpp
index 59e89de..3bb73ab 100644
--- a/src/Common/Utility.cpp
+++ b/src/Common/Utility.cpp
@@ -218,29 +218,6 @@ namespace firewalld
return retval;
}
- void tokenizeString(const String& str, StringVector& tokens, const String&
delimiters, bool trim_empty)
- {
- String::size_type pos, last_pos = 0;
- while(true) {
- pos = str.find_first_of(delimiters, last_pos);
- if(pos == String::npos) {
- pos = str.length();
-
- if(pos != last_pos || !trim_empty) {
- tokens.push_back(StringVector::value_type(str.data() + last_pos, pos - last_pos));
- }
-
- break;
- } else {
- if(pos != last_pos || !trim_empty) {
- tokens.push_back(StringVector::value_type(str.data() + last_pos, pos - last_pos));
- }
- }
-
- last_pos = pos + 1;
- }
- }
-
String filenameFromPath(const String& filepath, bool include_extension)
{
const String directory_separator = "/";
diff --git a/src/Common/Utility.hpp b/src/Common/Utility.hpp
index a748888..a73abef 100644
--- a/src/Common/Utility.hpp
+++ b/src/Common/Utility.hpp
@@ -47,7 +47,29 @@ namespace firewalld
int runCommand(const char *path, const char *arg1, const char *arg2, int timeout_secs =
10);
int runCommand(const String& path, const std::vector<String>& args =
std::vector<String>(), int timeout_secs = 10);
- void tokenizeString(const String& str, StringVector& tokens, const String&
delimiters = " ", bool trim_empty = false);
+ template<typename StringType>
+ void tokenizeString(const StringType& str, std::vector<StringType>&
tokens, const typename std::vector<StringType>::value_type delimiters, bool
trim_empty = false)
+ {
+ typename StringType::size_type pos, last_pos = 0;
+ while(true) {
+ pos = str.find_first_of(delimiters, last_pos);
+ if(pos == StringType::npos) {
+ pos = str.length();
+
+ if(pos != last_pos || !trim_empty) {
+ tokens.push_back(StringType(str.data() + last_pos, pos - last_pos));
+ }
+
+ break;
+ } else {
+ if(pos != last_pos || !trim_empty) {
+ tokens.push_back(StringType(str.data() + last_pos, pos - last_pos));
+ }
+ }
+
+ last_pos = pos + 1;
+ }
+ }
template<typename T>
String numberToString(T number)