ENH: Fix INSERT to allow inserting to empty list
This commit is contained in:
parent
cb2a9be622
commit
ed1ea24cef
|
@ -205,27 +205,30 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
|
||||||
// expand the variable
|
// expand the variable
|
||||||
int item = atoi(args[2].c_str());
|
int item = atoi(args[2].c_str());
|
||||||
std::vector<std::string> varArgsExpanded;
|
std::vector<std::string> varArgsExpanded;
|
||||||
if ( !this->GetList(varArgsExpanded, listName.c_str()) && (item > 0 || item < -1))
|
if ( !this->GetList(varArgsExpanded, listName.c_str()) && item != 0)
|
||||||
{
|
{
|
||||||
cmOStringStream str;
|
cmOStringStream str;
|
||||||
str << "index: " << item << " out of range (-1, 0)";
|
str << "index: " << item << " out of range (0, 0)";
|
||||||
this->SetError(str.str().c_str());
|
this->SetError(str.str().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nitem = varArgsExpanded.size();
|
if ( varArgsExpanded.size() != 0 )
|
||||||
if ( item < 0 )
|
|
||||||
{
|
{
|
||||||
item = (int)nitem + item;
|
size_t nitem = varArgsExpanded.size();
|
||||||
}
|
if ( item < 0 )
|
||||||
if ( item < 0 || nitem <= (size_t)item )
|
{
|
||||||
{
|
item = (int)nitem + item;
|
||||||
cmOStringStream str;
|
}
|
||||||
str << "index: " << item << " out of range (-"
|
if ( item < 0 || nitem <= (size_t)item )
|
||||||
<< varArgsExpanded.size() << ", "
|
{
|
||||||
<< varArgsExpanded.size()-1 << ")";
|
cmOStringStream str;
|
||||||
this->SetError(str.str().c_str());
|
str << "index: " << item << " out of range (-"
|
||||||
return false;
|
<< varArgsExpanded.size() << ", "
|
||||||
|
<< (varArgsExpanded.size() == 0?0:(varArgsExpanded.size()-1)) << ")";
|
||||||
|
this->SetError(str.str().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
size_t cc;
|
size_t cc;
|
||||||
size_t cnt = 0;
|
size_t cnt = 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
MACRO(TEST command expected)
|
MACRO(TEST command expected)
|
||||||
IF("x${result}" STREQUAL "x${expected}")
|
IF("x${result}" STREQUAL "x${expected}")
|
||||||
MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
|
#MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
|
||||||
ELSE("x${result}" STREQUAL "x${expected}")
|
ELSE("x${result}" STREQUAL "x${expected}")
|
||||||
MESSAGE(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
|
MESSAGE(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
|
||||||
ENDIF("x${result}" STREQUAL "x${expected}")
|
ENDIF("x${result}" STREQUAL "x${expected}")
|
||||||
|
@ -41,7 +41,11 @@ TEST("APPEND result brad" "andy;brad")
|
||||||
|
|
||||||
LIST(APPEND "nonexiting_list3" brad)
|
LIST(APPEND "nonexiting_list3" brad)
|
||||||
SET(result "${nonexiting_list3}")
|
SET(result "${nonexiting_list3}")
|
||||||
TEST("APPEND \"nonexiting_list1\" brad" "brad")
|
TEST("APPEND \"nonexiting_list3\" brad" "brad")
|
||||||
|
|
||||||
|
LIST(INSERT "nonexiting_list4" 0 andy bill brad ken)
|
||||||
|
SET(result "${nonexiting_list4}")
|
||||||
|
TEST("APPEND \"nonexiting_list4\" andy bill brad ken" "andy;bill;brad;ken")
|
||||||
|
|
||||||
SET(result andy brad)
|
SET(result andy brad)
|
||||||
LIST(INSERT result -1 bill ken)
|
LIST(INSERT result -1 bill ken)
|
||||||
|
|
Loading…
Reference in New Issue