blob: a7d82d86272a55c90cf14f2ef83dfcb1ef90b855 [file] [log] [blame]
Jordan Bayles12b95e72020-12-03 09:26:47 -08001// 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
7namespace openscreen {
8
9std::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