Commit 724f8cf6 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

ENH: merge in list find to support Findqt

parent 805a0a16
...@@ -42,6 +42,10 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args) ...@@ -42,6 +42,10 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args)
{ {
return this->HandleAppendCommand(args); return this->HandleAppendCommand(args);
} }
if(subCommand == "FIND")
{
return this->HandleFindCommand(args);
}
if(subCommand == "INSERT") if(subCommand == "INSERT")
{ {
return this->HandleInsertCommand(args); return this->HandleInsertCommand(args);
...@@ -199,6 +203,43 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args) ...@@ -199,6 +203,43 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
return true; return true;
} }
//----------------------------------------------------------------------------
bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args)
{
if(args.size() != 4)
{
this->SetError("sub-command FIND requires three arguments.");
return false;
}
const std::string& listName = args[1];
const std::string& variableName = args[args.size() - 1];
// expand the variable
std::vector<std::string> varArgsExpanded;
if ( !this->GetList(varArgsExpanded, listName.c_str()) )
{
this->Makefile->AddDefinition(variableName.c_str(), "-1");
return true;
}
std::vector<std::string>::iterator it;
unsigned int index = 0;
for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
{
if ( *it == args[2] )
{
char indexString[32];
sprintf(indexString, "%d", index);
this->Makefile->AddDefinition(variableName.c_str(), indexString);
return true;
}
index++;
}
this->Makefile->AddDefinition(variableName.c_str(), "-1");
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args) bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
{ {
......
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
" LIST(GET <list> <element index> [<element index> ...] " " LIST(GET <list> <element index> [<element index> ...] "
"<output variable>)\n" "<output variable>)\n"
" LIST(APPEND <list> <element> [<element> ...])\n" " LIST(APPEND <list> <element> [<element> ...])\n"
" LIST(FIND <list> <value> <output variable>)\n"
" LIST(INSERT <list> <element_index> <element> [<element> ...])\n" " LIST(INSERT <list> <element_index> <element> [<element> ...])\n"
" LIST(REMOVE_ITEM <list> <value> [<value> ...])\n" " LIST(REMOVE_ITEM <list> <value> [<value> ...])\n"
" LIST(REMOVE_AT <list> <index> [<index> ...])\n" " LIST(REMOVE_AT <list> <index> [<index> ...])\n"
...@@ -76,6 +77,8 @@ public: ...@@ -76,6 +77,8 @@ public:
"LENGTH will return a given list's length.\n" "LENGTH will return a given list's length.\n"
"GET will return list of elements specified by indices from the list.\n" "GET will return list of elements specified by indices from the list.\n"
"APPEND will append elements to the list.\n" "APPEND will append elements to the list.\n"
"FIND will return the index of the element specified in the list or -1 "
"if it wasn't found.\n"
"INSERT will insert elements to the list to the specified location.\n" "INSERT will insert elements to the list to the specified location.\n"
"When specifying an index, negative value corresponds to index from the" "When specifying an index, negative value corresponds to index from the"
" end of the list.\n" " end of the list.\n"
...@@ -90,6 +93,7 @@ protected: ...@@ -90,6 +93,7 @@ protected:
bool HandleLengthCommand(std::vector<std::string> const& args); bool HandleLengthCommand(std::vector<std::string> const& args);
bool HandleGetCommand(std::vector<std::string> const& args); bool HandleGetCommand(std::vector<std::string> const& args);
bool HandleAppendCommand(std::vector<std::string> const& args); bool HandleAppendCommand(std::vector<std::string> const& args);
bool HandleFindCommand(std::vector<std::string> const& args);
bool HandleInsertCommand(std::vector<std::string> const& args); bool HandleInsertCommand(std::vector<std::string> const& args);
bool HandleRemoveAtCommand(std::vector<std::string> const& args); bool HandleRemoveAtCommand(std::vector<std::string> const& args);
bool HandleRemoveItemCommand(std::vector<std::string> const& args); bool HandleRemoveItemCommand(std::vector<std::string> const& args);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment