diff --git a/premake.make b/premake.make index 3a89fc3..074e8a4 100644 --- a/premake.make +++ b/premake.make @@ -12,7 +12,7 @@ PRODUCT := lib # Single source of truth for version. MAJOR := 1 -MINOR := 4 +MINOR := 5 PATCH := 0 # Specify desired C++ standard for this project. diff --git a/src/string_utils.cpp b/src/string_utils.cpp index 181fb22..7bd4bad 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -26,20 +26,14 @@ vector sc::split(const string& str, const string& sep) return components; } -vector sc::split(const string& str, const regex& sep) { +vector sc::split(const string& str, const regex& sep) +{ return {sregex_token_iterator {str.begin(), str.end(), sep, -1}, sregex_token_iterator {}}; } string sc::join(const vector& components, const string& join) { - string result; - for (vector::const_iterator i = components.cbegin(); i != components.cend(); ++i) { - if (i != components.cbegin()) { - result += join; - } - result += *i; - } - return result; + return sc::join::const_iterator>(components.cbegin(), components.cend(), join); } string sc::trim(const string& str, const string& del) diff --git a/src/string_utils.hpp b/src/string_utils.hpp index df835de..ab34516 100644 --- a/src/string_utils.hpp +++ b/src/string_utils.hpp @@ -22,9 +22,22 @@ namespace sc { std::vector split (const std::string& str, const std::regex& sep); + template + std::string join (It beg, It end, const std::string& join) + { + std::string result; + for (auto i = beg; i != end; ++i) { + if (i != beg) { + result += join; + } + result += *i; + } + return result; + } + std::string join (const std::vector& components, const std::string& join); - + std::string trim (const std::string& str, const std::string& del = " ");