mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 11:22:21 -06:00
When `string(REGEX REPLACE)` or `string(REGEX MATCHALL)` loop internally, they store their matches, but they do not clear the previous match from an earlier iteration. This can leave the contents of `CMAKE_MATCH_<N>` with bogus values for later matches in the string if they have groups which earlier matched a non-empty string, but now match an empty string. Fixes #17079.
21 lines
658 B
CMake
21 lines
658 B
CMake
cmake_minimum_required (VERSION 3.0)
|
|
project (RegexClear NONE)
|
|
|
|
function (output_results msg)
|
|
message("results from: ${msg}")
|
|
message("CMAKE_MATCH_0: -->${CMAKE_MATCH_0}<--")
|
|
message("CMAKE_MATCH_1: -->${CMAKE_MATCH_1}<--")
|
|
message("CMAKE_MATCH_2: -->${CMAKE_MATCH_2}<--")
|
|
message("CMAKE_MATCH_COUNT: -->${CMAKE_MATCH_COUNT}<--")
|
|
endfunction ()
|
|
|
|
set(haystack "Some::Scope")
|
|
|
|
string(REGEX MATCHALL "^([^:]+)(::)?" matches "${haystack}")
|
|
message("matches: ${matches}")
|
|
output_results("string(REGEX MATCHALL)")
|
|
|
|
string(REGEX REPLACE "^([^:]+)(::)?" "[\\1]" replace "${haystack}")
|
|
message("replace: ${replace}")
|
|
output_results("string(REGEX REPLACE)")
|