MCPcopy Create free account
hub / github.com/Kitware/CMake / cmJoinStrings

Function cmJoinStrings

Source/cmStringAlgorithms.h:89–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87 */
88template <typename Range>
89std::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.

Callers 4

FormatListFileStackMethod · 0.85
cmJoinFunction · 0.85
FormatMethod · 0.85

Calls 5

accumulateFunction · 0.85
reserveMethod · 0.80
appendMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…