From a7d0fe9c24e111bc4f325d608b31fdf394c24602 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 29 Jul 2019 15:15:00 +0200 Subject: cmStringAlgorithms: Simplify cmJoin using cm::string_view --- Source/cmStringAlgorithms.h | 29 ++++++++++------------------- 1 file 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 -#include #include #include #include @@ -32,32 +30,25 @@ private: std::string const Test_; }; +/** Joins elements of a range with separator into a single string. */ template -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(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 -std::string cmJoin(Range const& r, std::string const& delimiter) -{ - return cmJoin(r, delimiter.c_str()); -} - -template std::string cmWrap(std::string const& prefix, Range const& r, std::string const& suffix, std::string const& sep) { -- cgit v0.12