blob: d87872048f6c4f26e2ae4b7f84e23736bd933ac7 [file] [log] [blame]
Andy Hung1ea842e2020-05-18 10:47:31 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <string>
20#include <vector>
21
22namespace android::mediametrics::stringutils {
23
24/**
25 * Return string tokens from iterator, separated by spaces and reserved chars.
26 */
27std::string tokenizer(std::string::const_iterator& it,
28 const std::string::const_iterator& end, const char *reserved);
29
30/**
31 * Splits flags string based on delimeters (or, whitespace which is removed).
32 */
33std::vector<std::string> split(const std::string& flags, const char *delim);
34
35/**
36 * Parse the devices string and return a vector of device address pairs.
37 *
38 * A failure to parse returns early with the contents that were able to be parsed.
39 */
40std::vector<std::pair<std::string, std::string>> getDeviceAddressPairs(const std::string &devices);
41
42/**
43 * Replaces targetChars with replaceChar in string, returns number of chars replaced.
44 */
45size_t replace(std::string &str, const char *targetChars, const char replaceChar);
46
47} // namespace android::mediametrics::stringutils