diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index f17e65ac4..73c6e60f2 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -254,7 +254,7 @@ bool cmStringCommand::RegexReplace(std::vector const& args) std::string::size_type r = re.end(); // Concatenate the part of the input that was not matched. - output += input.substr(base, l-base); + output += input.substr(base, l); // Make sure the match had some text. if(r-l == 0) @@ -282,7 +282,7 @@ bool cmStringCommand::RegexReplace(std::vector const& args) if((start != std::string::npos) && (end != std::string::npos) && (start >= 0) && (start <= len) && (end >= 0) && (end <= len)) { - output += input.substr(base+l, r-l); + output += input.substr(base+start, end-start); } else { diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt index aa4bb4b43..af0c5d1aa 100644 --- a/Tests/Complex/CMakeLists.txt +++ b/Tests/Complex/CMakeLists.txt @@ -221,12 +221,13 @@ STRING(REGEX MATCHALL "b" RESULT "abcb") IF(NOT RESULT) MESSAGE(SEND_ERROR "STRING(REGEX MATCHALL ... ) test failed.") ENDIF(NOT RESULT) -STRING(REGEX REPLACE "(b)" "[\\1]" RESULT "abcde") -IF("x${RESULT}" MATCHES "^xa\\[b\\]cde$") +STRING(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e") +IF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") SET(STRING_REGEX_PASSED 1) -ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]cde$") +ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") IF(NOT STRING_REGEX_PASSED) - MESSAGE(SEND_ERROR "STRING(REGEX REPLACE ... ) test failed.") + MESSAGE(SEND_ERROR + "STRING(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")") ENDIF(NOT STRING_REGEX_PASSED) # diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt index aa4bb4b43..af0c5d1aa 100644 --- a/Tests/ComplexOneConfig/CMakeLists.txt +++ b/Tests/ComplexOneConfig/CMakeLists.txt @@ -221,12 +221,13 @@ STRING(REGEX MATCHALL "b" RESULT "abcb") IF(NOT RESULT) MESSAGE(SEND_ERROR "STRING(REGEX MATCHALL ... ) test failed.") ENDIF(NOT RESULT) -STRING(REGEX REPLACE "(b)" "[\\1]" RESULT "abcde") -IF("x${RESULT}" MATCHES "^xa\\[b\\]cde$") +STRING(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e") +IF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") SET(STRING_REGEX_PASSED 1) -ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]cde$") +ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") IF(NOT STRING_REGEX_PASSED) - MESSAGE(SEND_ERROR "STRING(REGEX REPLACE ... ) test failed.") + MESSAGE(SEND_ERROR + "STRING(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")") ENDIF(NOT STRING_REGEX_PASSED) # diff --git a/Tests/ComplexRelativePaths/CMakeLists.txt b/Tests/ComplexRelativePaths/CMakeLists.txt index aa4bb4b43..af0c5d1aa 100644 --- a/Tests/ComplexRelativePaths/CMakeLists.txt +++ b/Tests/ComplexRelativePaths/CMakeLists.txt @@ -221,12 +221,13 @@ STRING(REGEX MATCHALL "b" RESULT "abcb") IF(NOT RESULT) MESSAGE(SEND_ERROR "STRING(REGEX MATCHALL ... ) test failed.") ENDIF(NOT RESULT) -STRING(REGEX REPLACE "(b)" "[\\1]" RESULT "abcde") -IF("x${RESULT}" MATCHES "^xa\\[b\\]cde$") +STRING(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e") +IF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") SET(STRING_REGEX_PASSED 1) -ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]cde$") +ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") IF(NOT STRING_REGEX_PASSED) - MESSAGE(SEND_ERROR "STRING(REGEX REPLACE ... ) test failed.") + MESSAGE(SEND_ERROR + "STRING(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")") ENDIF(NOT STRING_REGEX_PASSED) #