| 308 | } |
| 309 | |
| 310 | bool HandleFindCommand(std::vector<std::string> const& args, |
| 311 | cmExecutionStatus& status) |
| 312 | { |
| 313 | // check if all required parameters were passed |
| 314 | if (args.size() < 4 || args.size() > 5) { |
| 315 | status.SetError("sub-command FIND requires 3 or 4 parameters."); |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | // check if the reverse flag was set or not |
| 320 | bool reverseMode = false; |
| 321 | if (args.size() == 5 && args[4] == "REVERSE") { |
| 322 | reverseMode = true; |
| 323 | } |
| 324 | |
| 325 | // if we have 5 arguments the last one must be REVERSE |
| 326 | if (args.size() == 5 && args[4] != "REVERSE") { |
| 327 | status.SetError("sub-command FIND: unknown last parameter"); |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | // local parameter names. |
| 332 | std::string const& sstring = args[1]; |
| 333 | std::string const& schar = args[2]; |
| 334 | std::string const& outvar = args[3]; |
| 335 | |
| 336 | // ensure that the user cannot accidentally specify REVERSE as a variable |
| 337 | if (outvar == "REVERSE") { |
| 338 | status.SetError("sub-command FIND does not allow one to select REVERSE as " |
| 339 | "the output variable. " |
| 340 | "Maybe you missed the actual output variable?"); |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | // try to find the character and return its position |
| 345 | auto pos = cm::CMakeString{ sstring }.Find( |
| 346 | schar, |
| 347 | reverseMode ? cm::CMakeString::FindFrom::End |
| 348 | : cm::CMakeString::FindFrom::Begin); |
| 349 | |
| 350 | status.GetMakefile().AddDefinition( |
| 351 | outvar, pos != cm::CMakeString::npos ? std::to_string(pos) : "-1"); |
| 352 | |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | bool HandleCompareCommand(std::vector<std::string> const& args, |
| 357 | cmExecutionStatus& status) |
nothing calls this directly
no test coverage detected
searching dependent graphs…