MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / parse

Method parse

utils/command_line/CommandLineParser.h:116–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116inline void CommandLineParser::parse(int argc, char **argv)
117{
118 const std::regex option_regex{"--((?:no-)?)([^=]+)(?:=(.*))?"};
119
120 const auto set_option = [&](const std::string &option, const std::string &name, const std::string &value)
121 {
122 if (_options.find(name) == _options.end())
123 {
124 _unknown_options.push_back(option);
125 return;
126 }
127
128 const bool success = _options[name]->parse(value);
129
130 if (!success)
131 {
132 _invalid_options.push_back(option);
133 }
134 };
135
136 unsigned int positional_index = 0;
137
138 for (int i = 1; i < argc; ++i)
139 {
140 std::string mixed_case_opt{argv[i]};
141 int equal_sign = mixed_case_opt.find('=');
142 int pos = (equal_sign == -1) ? strlen(argv[i]) : equal_sign;
143
144 const std::string option =
145 arm_compute::utility::tolower(mixed_case_opt.substr(0, pos)) + mixed_case_opt.substr(pos);
146 std::smatch option_matches;
147
148 if (std::regex_match(option, option_matches, option_regex))
149 {
150 // Boolean option
151 if (option_matches.str(3).empty())
152 {
153 set_option(option, option_matches.str(2), option_matches.str(1).empty() ? "true" : "false");
154 }
155 else
156 {
157 // Can't have "no-" and a value
158 if (!option_matches.str(1).empty())
159 {
160 _invalid_options.emplace_back(option);
161 }
162 else
163 {
164 set_option(option, option_matches.str(2), option_matches.str(3));
165 }
166 }
167 }
168 else
169 {
170 if (positional_index >= _positional_options.size())
171 {
172 _invalid_options.push_back(mixed_case_opt);
173 }

Callers

nothing calls this directly

Calls 7

findMethod · 0.80
push_backMethod · 0.80
strMethod · 0.80
tolowerFunction · 0.50
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected