| 804 | } |
| 805 | |
| 806 | bool HandleSublistCommand(std::vector<std::string> const& args, |
| 807 | cmExecutionStatus& status) |
| 808 | { |
| 809 | if (args.size() != 5) { |
| 810 | status.SetError(cmStrCat("sub-command SUBLIST requires four arguments (", |
| 811 | args.size() - 1, " found).")); |
| 812 | return false; |
| 813 | } |
| 814 | |
| 815 | std::string const& listName = args[1]; |
| 816 | std::string const& variableName = args.back(); |
| 817 | |
| 818 | // expand the variable |
| 819 | auto list = GetList(listName, status.GetMakefile()); |
| 820 | |
| 821 | if (!list || list->empty()) { |
| 822 | status.GetMakefile().AddDefinition(variableName, ""); |
| 823 | return true; |
| 824 | } |
| 825 | |
| 826 | int start; |
| 827 | int length; |
| 828 | if (!GetIndexArg(args[2], &start, status.GetMakefile())) { |
| 829 | status.SetError(cmStrCat("index: ", args[2], " is not a valid index")); |
| 830 | return false; |
| 831 | } |
| 832 | if (!GetIndexArg(args[3], &length, status.GetMakefile())) { |
| 833 | status.SetError(cmStrCat("index: ", args[3], " is not a valid index")); |
| 834 | return false; |
| 835 | } |
| 836 | |
| 837 | if (start < 0) { |
| 838 | status.SetError(cmStrCat("begin index: ", start, " is out of range 0 - ", |
| 839 | list->size() - 1)); |
| 840 | return false; |
| 841 | } |
| 842 | if (length < -1) { |
| 843 | status.SetError(cmStrCat("length: ", length, " should be -1 or greater")); |
| 844 | return false; |
| 845 | } |
| 846 | |
| 847 | using size_type = cmList::size_type; |
| 848 | |
| 849 | try { |
| 850 | auto sublist = list->sublist(static_cast<size_type>(start), |
| 851 | static_cast<size_type>(length)); |
| 852 | status.GetMakefile().AddDefinition(variableName, sublist.to_string()); |
| 853 | return true; |
| 854 | } catch (std::out_of_range& e) { |
| 855 | status.SetError(e.what()); |
| 856 | return false; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | bool HandleRemoveAtCommand(std::vector<std::string> const& args, |
| 861 | cmExecutionStatus& status) |
nothing calls this directly
no test coverage detected
searching dependent graphs…