[PATCH] D27318: Support escaping in TrigramIndex.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 19:59:13 PST 2016


pcc added inline comments.


================
Comment at: lib/Support/TrigramIndex.cpp:60-68
+        case 'n':
+          Char = '\n';
+          break;
+        case 't':
+          Char = '\t';
+          break;
+        // Decimal escapes are backreferences.
----------------
This part doesn't look right. Neither 'n', 't' nor '0' are special. See: http://llvm-cs.pcc.me.uk/lib/Support/regcomp.c#379

I confirmed it with this passing test:
```
diff --git a/llvm/unittests/Support/RegexTest.cpp b/llvm/unittests/Support/RegexTest.cpp
index 5e3ce39..e151f47 100644
--- a/llvm/unittests/Support/RegexTest.cpp
+++ b/llvm/unittests/Support/RegexTest.cpp
@@ -171,4 +171,16 @@ TEST_F(RegexTest, MatchInvalid) {
   EXPECT_FALSE(r1.match("X"));
 }
 
+TEST_F(RegexTest, foo) {
+  Regex r1("\\t");
+  EXPECT_TRUE(r1.match("t"));
+  EXPECT_FALSE(r1.match("\t"));
+  Regex r2("\\n");
+  EXPECT_TRUE(r2.match("n"));
+  EXPECT_FALSE(r2.match("\n"));
+  Regex r3("\\0");
+  EXPECT_TRUE(r3.match("0"));
+  EXPECT_FALSE(r3.match("x"));
+}
+
 }

```


https://reviews.llvm.org/D27318





More information about the llvm-commits mailing list