Add missing escape characters to the new Regex::escape() function
The old AddFixedStringToRegEx() it was based on got away with this for the
longest time, but the problem became easy to spot after the cleanup in r197096.
Also add a quick unit test to cover regex escaping.
llvm-svn: 197121
diff --git a/llvm/unittests/Support/RegexTest.cpp b/llvm/unittests/Support/RegexTest.cpp
index 7b977f7..abc8d0f 100644
--- a/llvm/unittests/Support/RegexTest.cpp
+++ b/llvm/unittests/Support/RegexTest.cpp
@@ -127,6 +127,11 @@
EXPECT_FALSE(Regex::isLiteralERE("abc{1,2}"));
}
+TEST_F(RegexTest, Escape) {
+ EXPECT_EQ(Regex::escape("a[bc]"), "a\\[bc\\]");
+ EXPECT_EQ(Regex::escape("abc{1\\,2}"), "abc\\{1\\\\,2\\}");
+}
+
TEST_F(RegexTest, IsValid) {
std::string Error;
EXPECT_FALSE(Regex("(foo").isValid(Error));