Line | |
---|
1 | function(escape_string_as_regex _str_out _str_in)
|
---|
2 | STRING(REGEX REPLACE "\\\\" "\\\\\\\\" FILETEST2 "${_str_in}")
|
---|
3 | STRING(REGEX REPLACE "([.$+*?|-])" "\\\\\\1" FILETEST2 "${FILETEST2}")
|
---|
4 | STRING(REGEX REPLACE "\\^" "\\\\^" FILETEST2 "${FILETEST2}")
|
---|
5 | STRING(REGEX REPLACE "\\(" "\\\\(" FILETEST2 "${FILETEST2}")
|
---|
6 | STRING(REGEX REPLACE "\\)" "\\\\)" FILETEST2 "${FILETEST2}")
|
---|
7 | STRING(REGEX REPLACE "\\[" "\\\\[" FILETEST2 "${FILETEST2}")
|
---|
8 | STRING(REGEX REPLACE "\\]" "\\\\]" FILETEST2 "${FILETEST2}")
|
---|
9 | SET(${_str_out} "${FILETEST2}" PARENT_SCOPE)
|
---|
10 | endfunction()
|
---|
11 |
|
---|
12 | function(test_escape_string_as_regex)
|
---|
13 | SET(test1 "\\.^$-+*()[]?|")
|
---|
14 | escape_string_as_regex(test2 "${test1}")
|
---|
15 | SET(testRef "\\\\\\.\\^\\$\\-\\+\\*\\(\\)\\[\\]\\?\\|")
|
---|
16 | if(NOT test2 STREQUAL testRef)
|
---|
17 | message("Error in the escape_string_for_regex function : \n ${test1} was escaped as ${test2}, should be ${testRef}")
|
---|
18 | endif(NOT test2 STREQUAL testRef)
|
---|
19 | endfunction() |
---|
Note:
See
TracBrowser
for help on using the repository browser.