diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-07-29 13:15:00 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-08-01 08:38:12 (GMT) |
commit | a7d0fe9c24e111bc4f325d608b31fdf394c24602 (patch) | |
tree | cb501c55daef283f39e2daf42956c99f9f85f097 /Source/cmStringAlgorithms.h | |
parent | 541361a58bae487956c5b50d475edc4fcb453030 (diff) | |
download | CMake-a7d0fe9c24e111bc4f325d608b31fdf394c24602.zip CMake-a7d0fe9c24e111bc4f325d608b31fdf394c24602.tar.gz CMake-a7d0fe9c24e111bc4f325d608b31fdf394c24602.tar.bz2 |
cmStringAlgorithms: Simplify cmJoin using cm::string_view
Diffstat (limited to 'Source/cmStringAlgorithms.h')
-rw-r--r-- | Source/cmStringAlgorithms.h | 29 |
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) { |