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

Function HandleSublistCommand

Source/cmListCommand.cxx:806–858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

804}
805
806bool 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
860bool HandleRemoveAtCommand(std::vector<std::string> const& args,
861 cmExecutionStatus& status)

Callers

nothing calls this directly

Calls 12

GetIndexArgFunction · 0.85
to_stringMethod · 0.80
cmStrCatFunction · 0.70
GetListFunction · 0.70
sizeMethod · 0.45
SetErrorMethod · 0.45
backMethod · 0.45
GetMakefileMethod · 0.45
emptyMethod · 0.45
AddDefinitionMethod · 0.45
sublistMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…