MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / ParseArguments

Method ParseArguments

cpp/iedriverserver/CommandLineArguments.cpp:37–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void CommandLineArguments::ParseArguments(int argc, _TCHAR* argv[]) {
38 this->is_help_requested_ = false;
39 this->is_version_requested_ = false;
40 for (int i = 1; i < argc; ++i) {
41 std::wstring raw_arg(argv[i]);
42 int switch_delimiter_length = GetSwitchDelimiterLength(raw_arg);
43 std::wstring arg = raw_arg.substr(switch_delimiter_length);
44 size_t equal_pos = arg.find(L"=");
45 std::wstring arg_name = L"";
46 std::wstring arg_value = L"";
47 if (equal_pos != std::string::npos && equal_pos > 0) {
48 arg_name = arg.substr(0, equal_pos);
49 arg_value = arg.substr(equal_pos + 1);
50 } else {
51 arg_name = arg;
52 }
53
54 // coerce all argument names to lowercase, making argument names
55 // case-insensitive.
56 std::transform(arg_name.begin(), arg_name.end(), arg_name.begin(), tolower);
57
58 // trim single and double quotes from argument value begin and end
59 size_t startpos = arg_value.find_first_not_of(L"'\"");
60 if (startpos != std::string::npos) {
61 arg_value = arg_value.substr(startpos);
62 }
63 size_t endpos = arg_value.find_last_not_of(L"'\"");
64 if (endpos != std::string::npos) {
65 arg_value = arg_value.substr(0, endpos + 1);
66 }
67
68 if (arg_name == L"?" || arg_name == L"h" || arg_name == L"help") {
69 this->is_help_requested_ = true;
70 }
71
72 if (arg_name == L"v" || arg_name == L"version") {
73 this->is_version_requested_ = true;
74 }
75
76 this->args_map_[arg_name] = arg_value;
77 }
78}
79
80int CommandLineArguments::GetSwitchDelimiterLength(std::wstring arg) {
81 if (arg.find(L"--") == 0) {

Callers 1

CommandLineArgumentsMethod · 0.95

Calls 2

findMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected