| 214 | |
| 215 | template <class ITERATOR> |
| 216 | void JoinStringsIterator(const ITERATOR& start, |
| 217 | const ITERATOR& end, |
| 218 | const StringPiece& delim, |
| 219 | string* result) { |
| 220 | result->clear(); |
| 221 | |
| 222 | // Precompute resulting length so we can reserve() memory in one shot. |
| 223 | if (start != end) { |
| 224 | int length = delim.size()*(distance(start, end)-1); |
| 225 | for (ITERATOR iter = start; iter != end; ++iter) { |
| 226 | length += iter->size(); |
| 227 | } |
| 228 | result->reserve(length); |
| 229 | } |
| 230 | |
| 231 | // Now combine everything. |
| 232 | for (ITERATOR iter = start; iter != end; ++iter) { |
| 233 | if (iter != start) { |
| 234 | result->append(delim.data(), delim.size()); |
| 235 | } |
| 236 | result->append(iter->data(), iter->size()); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | template <class ITERATOR> |
| 241 | inline string JoinStringsIterator(const ITERATOR& start, |
no test coverage detected