Merge topic 'dev/support-substring-negative-indices'
36cb701
allow STRING(SUBSTRING) work with length -1 as "rest of the string"
This commit is contained in:
commit
2d1aa4ad06
|
@ -606,7 +606,7 @@ bool cmStringCommand::HandleSubstringCommand(std::vector<std::string> const&
|
|||
return false;
|
||||
}
|
||||
int leftOverLength = intStringLength - begin;
|
||||
if ( end < 0 || end > leftOverLength )
|
||||
if ( end < -1 || end > leftOverLength )
|
||||
{
|
||||
cmOStringStream ostr;
|
||||
ostr << "end index: " << end << " is out of range " << 0 << " - "
|
||||
|
|
|
@ -256,3 +256,27 @@ endif()
|
|||
if(NOT "${var_b}" STREQUAL "x")
|
||||
message(FATAL_ERROR "count incorrect \"b\": [${var_b}]")
|
||||
endif()
|
||||
|
||||
# Test SUBSTRING command
|
||||
SET(ST_INPUTSTRING "0123456789")
|
||||
STRING(SUBSTRING ${ST_INPUTSTRING} 3 0 ST_EMPTY)
|
||||
STRING(SUBSTRING ${ST_INPUTSTRING} 1 1 ST_ONE)
|
||||
STRING(SUBSTRING ${ST_INPUTSTRING} 0 10 ST_ALL)
|
||||
STRING(SUBSTRING ${ST_INPUTSTRING} 0 -1 ST_ALL_MINUS)
|
||||
STRING(SUBSTRING ${ST_INPUTSTRING} 9 -1 ST_NINE)
|
||||
|
||||
IF(ST_EMPTY)
|
||||
MESSAGE(SEND_ERROR "SUBSTRING with length 0 does not return an empty string")
|
||||
ENDIF(ST_EMPTY)
|
||||
IF(NOT ST_ONE STREQUAL "1")
|
||||
MESSAGE(SEND_ERROR "SUBSTING command does not cut the correct selected character, was \"" ${ST_ONE} "\", should be \"1\"")
|
||||
ENDIF(NOT ST_ONE STREQUAL "1")
|
||||
IF(NOT ST_INPUTSTRING STREQUAL ST_ALL)
|
||||
MESSAGE(SEND_ERROR "SUBSTRING does not return the whole string when selected with length")
|
||||
ENDIF(NOT ST_INPUTSTRING STREQUAL ST_ALL)
|
||||
IF(NOT ST_INPUTSTRING STREQUAL ST_ALL_MINUS)
|
||||
MESSAGE(SEND_ERROR "SUBSTRING does not return the whole string when selected with -1")
|
||||
ENDIF(NOT ST_INPUTSTRING STREQUAL ST_ALL_MINUS)
|
||||
IF(NOT ST_NINE STREQUAL "9")
|
||||
MESSAGE(SEND_ERROR "SUBSTRING does not return the tail when selected with -1")
|
||||
ENDIF(NOT ST_NINE STREQUAL "9")
|
||||
|
|
Loading…
Reference in New Issue