| 440 | } |
| 441 | |
| 442 | bool HandleTransformCommand(std::vector<std::string> const& args, |
| 443 | cmExecutionStatus& status) |
| 444 | { |
| 445 | if (args.size() < 3) { |
| 446 | status.SetError( |
| 447 | "sub-command TRANSFORM requires an action to be specified."); |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | // Descriptor of action |
| 452 | // Action: enum value identifying action |
| 453 | // Arity: number of arguments required for the action |
| 454 | struct ActionDescriptor |
| 455 | { |
| 456 | ActionDescriptor(std::string name) |
| 457 | : Name(std::move(name)) |
| 458 | { |
| 459 | } |
| 460 | ActionDescriptor(std::string name, cmList::TransformAction action, |
| 461 | int arity) |
| 462 | : Name(std::move(name)) |
| 463 | , Action(action) |
| 464 | , Arity(arity) |
| 465 | { |
| 466 | } |
| 467 | |
| 468 | operator std::string const&() const { return this->Name; } |
| 469 | |
| 470 | std::string Name; |
| 471 | cmList::TransformAction Action; |
| 472 | int Arity = 0; |
| 473 | }; |
| 474 | |
| 475 | // Build a set of supported actions. |
| 476 | std::set<ActionDescriptor, |
| 477 | std::function<bool(std::string const&, std::string const&)>> |
| 478 | descriptors{ { { "APPEND", cmList::TransformAction::APPEND, 1 }, |
| 479 | { "PREPEND", cmList::TransformAction::PREPEND, 1 }, |
| 480 | { "TOUPPER", cmList::TransformAction::TOUPPER, 0 }, |
| 481 | { "TOLOWER", cmList::TransformAction::TOLOWER, 0 }, |
| 482 | { "STRIP", cmList::TransformAction::STRIP, 0 }, |
| 483 | { "GENEX_STRIP", cmList::TransformAction::GENEX_STRIP, 0 }, |
| 484 | { "REPLACE", cmList::TransformAction::REPLACE, 2 } }, |
| 485 | [](std::string const& x, std::string const& y) { |
| 486 | return x < y; |
| 487 | } }; |
| 488 | |
| 489 | std::string const& listName = args[1]; |
| 490 | |
| 491 | // Parse all possible function parameters |
| 492 | using size_type = std::vector<std::string>::size_type; |
| 493 | size_type index = 2; |
| 494 | |
| 495 | auto descriptor = descriptors.find(args[index]); |
| 496 | |
| 497 | if (descriptor == descriptors.end()) { |
| 498 | status.SetError( |
| 499 | cmStrCat(" sub-command TRANSFORM, ", args[index], " invalid action.")); |
nothing calls this directly
no test coverage detected
searching dependent graphs…