You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
937 B

  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. function(test_escape_string_as_regex)
  12. SET(test1 "\\.^$-+*()[]?|")
  13. escape_string_as_regex(test2 "${test1}")
  14. SET(testRef "\\\\\\.\\^\\$\\-\\+\\*\\(\\)\\[\\]\\?\\|")
  15. if(NOT test2 STREQUAL testRef)
  16. message("Error in the escape_string_for_regex function : \n ${test1} was escaped as ${test2}, should be ${testRef}")
  17. endif(NOT test2 STREQUAL testRef)
  18. endfunction()