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 | 81f46d9ce1888308b33336f9bea72147430da36b (patch) | |
tree | f3c232cbd37d132f5dc3c530151bd860335125bb /lib/Support/Regex.cpp | |
parent | 282098be8463035143bd8444796e6a58b0205c29 (diff) | |
download | external_llvm-81f46d9ce1888308b33336f9bea72147430da36b.zip external_llvm-81f46d9ce1888308b33336f9bea72147430da36b.tar.gz external_llvm-81f46d9ce1888308b33336f9bea72147430da36b.tar.bz2 |
remove support for "NoSub" from regex. It seems like a minor optimization
and makes the API more annoying. Add a Regex::getNumMatches() method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82877 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Regex.cpp')
-rw-r--r-- | lib/Support/Regex.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/Support/Regex.cpp b/lib/Support/Regex.cpp index 285e01f..618ca05 100644 --- a/lib/Support/Regex.cpp +++ b/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 |