diff options
author | Chris Lattner <sabre@nondot.org> | 2009-09-26 21:27:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-09-26 21:27:04 +0000 |
commit | 37d8015dc1e09de96e32be45a70cb53b9fe118db (patch) | |
tree | 3d3f3952739dce15ec9fa1f6f7fefc9cb0e58fa1 /llvm/lib/Support/Regex.cpp | |
parent | a26b471f1d0f0f057df492235213515e7a95f031 (diff) | |
download | bcm5719-llvm-37d8015dc1e09de96e32be45a70cb53b9fe118db.tar.gz bcm5719-llvm-37d8015dc1e09de96e32be45a70cb53b9fe118db.zip |
remove support for "NoSub" from regex. It seems like a minor optimization
and makes the API more annoying. Add a Regex::getNumMatches() method.
llvm-svn: 82877
Diffstat (limited to 'llvm/lib/Support/Regex.cpp')
-rw-r--r-- | llvm/lib/Support/Regex.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/llvm/lib/Support/Regex.cpp b/llvm/lib/Support/Regex.cpp index 285e01f02b1..618ca0524a0 100644 --- a/llvm/lib/Support/Regex.cpp +++ b/llvm/lib/Support/Regex.cpp @@ -25,21 +25,20 @@ Regex::Regex(const StringRef ®ex, unsigned Flags) { preg->re_endp = regex.end(); if (Flags & IgnoreCase) flags |= REG_ICASE; - if (Flags & NoSub) { - flags |= REG_NOSUB; - sub = false; - } else { - sub = true; - } if (Flags & Newline) flags |= REG_NEWLINE; error = llvm_regcomp(preg, regex.data(), flags|REG_EXTENDED|REG_PEND); } +Regex::~Regex() { + llvm_regfree(preg); + delete preg; +} + bool Regex::isValid(std::string &Error) { if (!error) return true; - + size_t len = llvm_regerror(error, preg, NULL, 0); Error.resize(len); @@ -47,19 +46,15 @@ bool Regex::isValid(std::string &Error) { return false; } -Regex::~Regex() { - llvm_regfree(preg); - delete preg; +/// getNumMatches - In a valid regex, return the number of parenthesized +/// matches it contains. +unsigned Regex::getNumMatches() const { + return preg->re_nsub; } bool Regex::match(const StringRef &String, SmallVectorImpl<StringRef> *Matches){ unsigned nmatch = Matches ? preg->re_nsub+1 : 0; - if (Matches) { - assert(sub && "Substring matching requested but pattern compiled without"); - Matches->clear(); - } - // pmatch needs to have at least one element. SmallVector<llvm_regmatch_t, 8> pm; pm.resize(nmatch > 0 ? nmatch : 1); @@ -79,6 +74,8 @@ bool Regex::match(const StringRef &String, SmallVectorImpl<StringRef> *Matches){ // There was a match. if (Matches) { // match position requested + Matches->clear(); + for (unsigned i = 0; i != nmatch; ++i) { if (pm[i].rm_so == -1) { // this group didn't match |