Jordan Bayles | 12b95e7 | 2020-12-03 09:26:47 -0800 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "util/std_util.h" |
| 6 | |
| 7 | namespace openscreen { |
| 8 | |
| 9 | std::string Join(const std::vector<std::string>& strings, |
| 10 | const char* delimiter) { |
| 11 | size_t size_to_reserve = 0; |
| 12 | for (const auto& piece : strings) { |
| 13 | size_to_reserve += piece.length(); |
| 14 | } |
| 15 | std::string out; |
| 16 | out.reserve(size_to_reserve); |
| 17 | auto it = strings.begin(); |
| 18 | out += *it; |
| 19 | for (++it; it != strings.end(); ++it) { |
| 20 | out += delimiter + *it; |
| 21 | } |
| 22 | |
| 23 | return out; |
| 24 | } |
| 25 | |
| 26 | } // namespace openscreen |