summaryrefslogtreecommitdiff
path: root/lib/Support/Regex.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 10:51:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 10:51:19 +0000
commiteb11fae6d08f479c0799db45860a98af528fa6e7 (patch)
tree44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/Support/Regex.cpp
parentb8a2042aa938069e862750553db0e4d82d25822c (diff)
Notes
Diffstat (limited to 'lib/Support/Regex.cpp')
-rw-r--r--lib/Support/Regex.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/Support/Regex.cpp b/lib/Support/Regex.cpp
index b1087fd8853c..48caab131526 100644
--- a/lib/Support/Regex.cpp
+++ b/lib/Support/Regex.cpp
@@ -12,11 +12,16 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Regex.h"
-#include "regex_impl.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include <string>
+
+// Important this comes last because it defines "_REGEX_H_". At least on
+// Darwin, if included before any header that (transitively) includes
+// xlocale.h, this will cause trouble, because of missing regex-related types.
+#include "regex_impl.h"
+
using namespace llvm;
Regex::Regex() : preg(nullptr), error(REG_BADPAT) {}
@@ -25,7 +30,7 @@ Regex::Regex(StringRef regex, unsigned Flags) {
unsigned flags = 0;
preg = new llvm_regex();
preg->re_endp = regex.end();
- if (Flags & IgnoreCase)
+ if (Flags & IgnoreCase)
flags |= REG_ICASE;
if (Flags & Newline)
flags |= REG_NEWLINE;
@@ -51,9 +56,9 @@ Regex::~Regex() {
bool Regex::isValid(std::string &Error) const {
if (!error)
return true;
-
+
size_t len = llvm_regerror(error, preg, nullptr, 0);
-
+
Error.resize(len - 1);
llvm_regerror(error, preg, &Error[0], len);
return false;
@@ -91,7 +96,7 @@ bool Regex::match(StringRef String, SmallVectorImpl<StringRef> *Matches){
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