Shaka Packager SDK
Loading...
Searching...
No Matches
kv_pairs.cc
1// Copyright 2022 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#include <packager/kv_pairs/kv_pairs.h>
8
9#include <string>
10#include <string_view>
11#include <vector>
12
13#include <absl/strings/str_split.h>
14
15namespace shaka {
16
17std::vector<KVPair> SplitStringIntoKeyValuePairs(std::string_view str,
18 char kv_separator,
19 char list_separator) {
20 std::vector<KVPair> kv_pairs;
21
22 // Edge case: 0 pairs.
23 if (str.size() == 0) {
24 return kv_pairs;
25 }
26
27 std::vector<std::string> kv_strings = absl::StrSplit(str, list_separator);
28 for (const auto& kv_string : kv_strings) {
29 KVPair pair = absl::StrSplit(kv_string, absl::MaxSplits(kv_separator, 1));
30 kv_pairs.push_back(pair);
31 }
32
33 return kv_pairs;
34}
35
36} // namespace shaka
All the methods that are virtual are virtual for mocking.