forked from OSchip/llvm-project
Introduce Regex::isLiteralERE function.
This will be used to implement an optimisation for literal entries in special case lists. Differential Revision: http://llvm-reviews.chandlerc.com/D1278 llvm-svn: 187731
This commit is contained in:
parent
bd6389b11f
commit
fe8cd75971
|
@ -77,6 +77,10 @@ namespace llvm {
|
|||
/// string.
|
||||
std::string sub(StringRef Repl, StringRef String, std::string *Error = 0);
|
||||
|
||||
/// \brief If this function returns true, ^Str$ is an extended regular
|
||||
/// expression that matches Str and only Str.
|
||||
static bool isLiteralERE(StringRef Str);
|
||||
|
||||
private:
|
||||
struct llvm_regex *preg;
|
||||
int error;
|
||||
|
|
|
@ -168,3 +168,10 @@ std::string Regex::sub(StringRef Repl, StringRef String,
|
|||
|
||||
return Res;
|
||||
}
|
||||
|
||||
bool Regex::isLiteralERE(StringRef Str) {
|
||||
// Check for regex metacharacters. This list was derived from our regex
|
||||
// implementation in regcomp.c and double checked against the POSIX extended
|
||||
// regular expression specification.
|
||||
return Str.find_first_of("()^$|*+?.[]\\{}") == StringRef::npos;
|
||||
}
|
||||
|
|
|
@ -112,4 +112,19 @@ TEST_F(RegexTest, Substitution) {
|
|||
EXPECT_EQ(Error, "invalid backreference string '100'");
|
||||
}
|
||||
|
||||
TEST_F(RegexTest, IsLiteralERE) {
|
||||
EXPECT_TRUE(Regex::isLiteralERE("abc"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("a(bc)"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("^abc"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc$"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("a|bc"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc*"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc+"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc?"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc."));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("a[bc]"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc\\1"));
|
||||
EXPECT_FALSE(Regex::isLiteralERE("abc{1,2}"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue