1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include "pw_bluetooth_sapphire/internal/host/testing/parse_args.h"
16
17 namespace bt::testing {
18
GetArgValue(std::string_view arg_name,int argc,char ** argv)19 std::optional<std::string_view> GetArgValue(std::string_view arg_name,
20 int argc,
21 char** argv) {
22 for (int i = 1; i < argc; i++) {
23 std::string_view arg(argv[i]);
24 if (arg.substr(0, 2) != "--") {
25 continue;
26 }
27 size_t eq_pos = arg.find("=");
28 if (eq_pos == std::string_view::npos ||
29 arg.substr(2, arg_name.size()) != arg_name) {
30 continue;
31 }
32 return arg.substr(eq_pos + 1);
33 }
34 return std::nullopt;
35 }
36
37 } // namespace bt::testing
38