MCPcopy Create free account
hub / github.com/Kitware/CMake / Parse

Method Parse

Source/kwsys/CommandLineArguments.cxx:150–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150int CommandLineArguments::Parse()
151{
152 std::vector<std::string>::size_type cc;
153 std::vector<std::string> matches;
154 if (this->StoreUnusedArgumentsFlag) {
155 this->Internals->UnusedArguments.clear();
156 }
157 for (cc = 0; cc < this->Internals->Argv.size(); cc++) {
158 std::string const& arg = this->Internals->Argv[cc];
159 CommandLineArguments_DEBUG("Process argument: " << arg);
160 this->Internals->LastArgument = cc;
161 if (this->GetMatchedArguments(&matches, arg)) {
162 // Ok, we found one or more arguments that match what user specified.
163 // Let's find the longest one.
164 CommandLineArguments::Internal::VectorOfStrings::size_type kk;
165 CommandLineArguments::Internal::VectorOfStrings::size_type maxidx = 0;
166 CommandLineArguments::Internal::String::size_type maxlen = 0;
167 for (kk = 0; kk < matches.size(); kk++) {
168 if (matches[kk].size() > maxlen) {
169 maxlen = matches[kk].size();
170 maxidx = kk;
171 }
172 }
173 // So, the longest one is probably the right one. Now see if it has any
174 // additional value
175 CommandLineArgumentsCallbackStructure* cs =
176 &this->Internals->Callbacks[matches[maxidx]];
177 std::string const& sarg = matches[maxidx];
178 if (cs->Argument != sarg) {
179 abort();
180 }
181 switch (cs->ArgumentType) {
182 case NO_ARGUMENT:
183 // No value
184 if (!this->PopulateVariable(cs, nullptr)) {
185 return 0;
186 }
187 break;
188 case SPACE_ARGUMENT:
189 if (cc == this->Internals->Argv.size() - 1) {
190 this->Internals->LastArgument--;
191 return 0;
192 }
193 CommandLineArguments_DEBUG("This is a space argument: "
194 << arg << " value: "
195 << this->Internals->Argv[cc + 1]);
196 // Value is the next argument
197 if (!this->PopulateVariable(cs,
198 this->Internals->Argv[cc + 1].c_str())) {
199 return 0;
200 }
201 cc++;
202 break;
203 case EQUAL_ARGUMENT:
204 if (arg.size() == sarg.size() || arg.at(sarg.size()) != '=') {
205 this->Internals->LastArgument--;
206 return 0;
207 }

Callers 5

InvokeMethod · 0.45
ParseResponseMethod · 0.45
testCommandLineArgumentsFunction · 0.45

Calls 7

GetMatchedArgumentsMethod · 0.95
PopulateVariableMethod · 0.95
c_strMethod · 0.80
push_backMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45

Tested by 5

InvokeMethod · 0.36
ParseResponseMethod · 0.36
testCommandLineArgumentsFunction · 0.36