summaryrefslogtreecommitdiffstats
path: root/Source/cmStringAlgorithms.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmStringAlgorithms.h')
-rw-r--r--Source/cmStringAlgorithms.h29
1 files changed, 10 insertions, 19 deletions
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index 3f88692..8d6aec6 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -7,8 +7,6 @@
#include "cmRange.h"
#include "cm_string_view.hxx"
-#include <algorithm>
-#include <iterator>
#include <sstream>
#include <string.h>
#include <string>
@@ -32,32 +30,25 @@ private:
std::string const Test_;
};
+/** Joins elements of a range with separator into a single string. */
template <typename Range>
-std::string cmJoin(Range const& r, const char* delimiter)
+std::string cmJoin(Range const& rng, cm::string_view separator)
{
- if (r.empty()) {
+ if (rng.empty()) {
return std::string();
}
- std::ostringstream os;
- typedef typename Range::value_type ValueType;
- typedef typename Range::const_iterator InputIt;
- const InputIt first = r.begin();
- InputIt last = r.end();
- --last;
- std::copy(first, last, std::ostream_iterator<ValueType>(os, delimiter));
-
- os << *last;
+ std::ostringstream os;
+ auto it = rng.begin();
+ auto const end = rng.end();
+ os << *it;
+ while (++it != end) {
+ os << separator << *it;
+ }
return os.str();
}
template <typename Range>
-std::string cmJoin(Range const& r, std::string const& delimiter)
-{
- return cmJoin(r, delimiter.c_str());
-}
-
-template <typename Range>
std::string cmWrap(std::string const& prefix, Range const& r,
std::string const& suffix, std::string const& sep)
{