| 87 | */ |
| 88 | template <typename Range> |
| 89 | std::string cmJoinStrings(Range const& rng, cm::string_view separator, |
| 90 | cm::string_view initial) |
| 91 | { |
| 92 | if (rng.empty()) { |
| 93 | return { std::begin(initial), std::end(initial) }; |
| 94 | } |
| 95 | |
| 96 | std::string result; |
| 97 | result.reserve(std::accumulate( |
| 98 | std::begin(rng), std::end(rng), |
| 99 | initial.size() + (rng.size() - 1) * separator.size(), |
| 100 | [](std::size_t sum, typename Range::value_type const& item) { |
| 101 | return sum + item.size(); |
| 102 | })); |
| 103 | result.append(std::begin(initial), std::end(initial)); |
| 104 | |
| 105 | auto begin = std::begin(rng); |
| 106 | auto end = std::end(rng); |
| 107 | result += *begin; |
| 108 | |
| 109 | for (++begin; begin != end; ++begin) { |
| 110 | result.append(std::begin(separator), std::end(separator)); |
| 111 | result += *begin; |
| 112 | } |
| 113 | |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Faster overloads for std::string ranges. |
no test coverage detected
searching dependent graphs…