
When doing successive matches, track the input start and current search start positions separately to prevent the `^` anchor from matching in the middle of the string. Add policy CMP0186 to provide compatibility. Issue: #26629 Fixes: #16899
44 lines
1.4 KiB
CMake
44 lines
1.4 KiB
CMake
set(mylist 0000 1001 0002)
|
|
|
|
# OLD
|
|
cmake_policy(SET CMP0186 OLD)
|
|
|
|
unset(output)
|
|
list(TRANSFORM mylist REPLACE "^0" "" OUTPUT_VARIABLE output)
|
|
if (NOT output STREQUAL ";1001;2")
|
|
message(FATAL_ERROR "TRANSFORM(REPLACE) is \"${output}\", expected is \";1001;2\"")
|
|
endif()
|
|
|
|
unset(output)
|
|
list(TRANSFORM mylist REPLACE "^(a|0)" "x" OUTPUT_VARIABLE output)
|
|
if (NOT output STREQUAL "xxxx;1001;xxx2")
|
|
message(FATAL_ERROR "TRANSFORM(REPLACE) is \"${output}\", expected is \"xxxx;1001;xxx2\"")
|
|
endif()
|
|
|
|
unset(output)
|
|
list(TRANSFORM mylist REPLACE "(1|^)0" "x" OUTPUT_VARIABLE output)
|
|
if (NOT output STREQUAL "xxxx;xx1;xxx2")
|
|
message(FATAL_ERROR "TRANSFORM(REPLACE) is \"${output}\", expected is \"xxxx;xx1;xxx2\"")
|
|
endif()
|
|
|
|
# NEW, same cases as above
|
|
cmake_policy(SET CMP0186 NEW)
|
|
|
|
unset(output)
|
|
list(TRANSFORM mylist REPLACE "^0" "" OUTPUT_VARIABLE output)
|
|
if (NOT output STREQUAL "000;1001;002")
|
|
message(FATAL_ERROR "TRANSFORM(REPLACE) is \"${output}\", expected is \"000;1001;002\"")
|
|
endif()
|
|
|
|
unset(output)
|
|
list(TRANSFORM mylist REPLACE "^(a|0)" "x" OUTPUT_VARIABLE output)
|
|
if (NOT output STREQUAL "x000;1001;x002")
|
|
message(FATAL_ERROR "TRANSFORM(REPLACE) is \"${output}\", expected is \"x000;1001;x002\"")
|
|
endif()
|
|
|
|
unset(output)
|
|
list(TRANSFORM mylist REPLACE "(1|^)0" "x" OUTPUT_VARIABLE output)
|
|
if (NOT output STREQUAL "x000;x01;x002")
|
|
message(FATAL_ERROR "TRANSFORM(REPLACE) is \"${output}\", expected is \"x000;xx1;x002\"")
|
|
endif()
|