[PATCH] D24102: [LLVM/Support] - Disallow match() method of llvm::Regex to change object state.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 02:28:53 PDT 2016
grimar updated this revision to Diff 69961.
grimar added a comment.
- Simplified.
https://reviews.llvm.org/D24102
Files:
include/llvm/Support/Regex.h
lib/Support/Regex.cpp
Index: lib/Support/Regex.cpp
===================================================================
--- lib/Support/Regex.cpp
+++ lib/Support/Regex.cpp
@@ -58,7 +58,7 @@
return preg->re_nsub;
}
-bool Regex::match(StringRef String, SmallVectorImpl<StringRef> *Matches){
+bool Regex::match(StringRef String, SmallVectorImpl<StringRef> *Matches) const {
unsigned nmatch = Matches ? preg->re_nsub+1 : 0;
// pmatch needs to have at least one element.
@@ -68,14 +68,8 @@
pm[0].rm_eo = String.size();
int rc = llvm_regexec(preg, String.data(), nmatch, pm.data(), REG_STARTEND);
-
- if (rc == REG_NOMATCH)
- return false;
- if (rc != 0) {
- // regexec can fail due to invalid pattern or running out of memory.
- error = rc;
+ if (!rc)
return false;
- }
// There was a match.
Index: include/llvm/Support/Regex.h
===================================================================
--- include/llvm/Support/Regex.h
+++ include/llvm/Support/Regex.h
@@ -75,7 +75,8 @@
/// the first group is always the entire pattern.
///
/// This returns true on a successful match.
- bool match(StringRef String, SmallVectorImpl<StringRef> *Matches = nullptr);
+ bool match(StringRef String,
+ SmallVectorImpl<StringRef> *Matches = nullptr) const;
/// sub - Return the result of replacing the first match of the regex in
/// \p String with the \p Repl string. Backreferences like "\0" in the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24102.69961.patch
Type: text/x-patch
Size: 1455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160901/54679c09/attachment.bin>
More information about the llvm-commits
mailing list