Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: third_party/re2/util/pcre.cc

Issue 1516543002: Update re2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated update instructions Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/util/pcre.h ('k') | third_party/re2/util/rune.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/util/pcre.cc
diff --git a/third_party/re2/util/pcre.cc b/third_party/re2/util/pcre.cc
index 160213335ea12f3f46e85604d8efd053afd7d3f6..9a3f32d25a370d65193e4f0a68e6de106903a9d9 100644
--- a/third_party/re2/util/pcre.cc
+++ b/third_party/re2/util/pcre.cc
@@ -7,15 +7,11 @@
// compilation as PCRE in namespace re2.
#include <errno.h>
+#include <limits>
#include "util/util.h"
#include "util/flags.h"
#include "util/pcre.h"
-#ifdef WIN32
-#define strtoll _strtoi64
-#define strtoull _strtoui64
-#endif
-
#define PCREPORT(level) LOG(level)
// Default PCRE limits.
@@ -27,6 +23,42 @@ DEFINE_int32(regexp_stack_limit, 256<<10, "default PCRE stack limit (bytes)");
DEFINE_int32(regexp_match_limit, 1000000,
"default PCRE match limit (function calls)");
+#ifndef USEPCRE
+
+// Fake just enough of the PCRE API to allow this file to build. :)
+
+struct pcre_extra {
+ int flags;
+ int match_limit;
+ int match_limit_recursion;
+};
+
+#define PCRE_EXTRA_MATCH_LIMIT 0
+#define PCRE_EXTRA_MATCH_LIMIT_RECURSION 0
+#define PCRE_ANCHORED 0
+#define PCRE_NOTEMPTY 0
+#define PCRE_ERROR_NOMATCH 1
+#define PCRE_ERROR_MATCHLIMIT 2
+#define PCRE_ERROR_RECURSIONLIMIT 3
+#define PCRE_INFO_CAPTURECOUNT 0
+
+void pcre_free(void*) {
+}
+
+pcre* pcre_compile(const char*, int, const char**, int*, const unsigned char*) {
+ return NULL;
+}
+
+int pcre_exec(const pcre*, const pcre_extra*, const char*, int, int, int, int*, int) {
+ return 0;
+}
+
+int pcre_fullinfo(const pcre*, const pcre_extra*, int, void*) {
+ return 0;
+}
+
+#endif
+
namespace re2 {
// Maximum number of args we can set
@@ -118,7 +150,7 @@ pcre* PCRE::Compile(Anchor anchor) {
// ANCHOR_BOTH Tack a "\z" to the end of the original pattern
// and use a pcre anchored match.
- const char* error;
+ const char* error = "";
int eoffset;
pcre* re;
if (anchor != ANCHOR_BOTH) {
@@ -183,7 +215,7 @@ bool PCRE::FullMatchFunctor::operator ()(const StringPiece& text,
done:
int consumed;
- int vec[kVecSize];
+ int vec[kVecSize] = {};
return re.DoMatchImpl(text, ANCHOR_BOTH, &consumed, args, n, vec, kVecSize);
}
@@ -226,7 +258,7 @@ bool PCRE::PartialMatchFunctor::operator ()(const StringPiece& text,
done:
int consumed;
- int vec[kVecSize];
+ int vec[kVecSize] = {};
return re.DoMatchImpl(text, UNANCHORED, &consumed, args, n, vec, kVecSize);
}
@@ -269,7 +301,7 @@ bool PCRE::ConsumeFunctor::operator ()(StringPiece* input,
done:
int consumed;
- int vec[kVecSize];
+ int vec[kVecSize] = {};
if (pattern.DoMatchImpl(*input, ANCHOR_START, &consumed,
args, n, vec, kVecSize)) {
input->remove_prefix(consumed);
@@ -318,7 +350,7 @@ bool PCRE::FindAndConsumeFunctor::operator ()(StringPiece* input,
done:
int consumed;
- int vec[kVecSize];
+ int vec[kVecSize] = {};
if (pattern.DoMatchImpl(*input, UNANCHORED, &consumed,
args, n, vec, kVecSize)) {
input->remove_prefix(consumed);
@@ -331,7 +363,7 @@ done:
bool PCRE::Replace(string *str,
const PCRE& pattern,
const StringPiece& rewrite) {
- int vec[kVecSize];
+ int vec[kVecSize] = {};
int matches = pattern.TryMatch(*str, 0, UNANCHORED, true, vec, kVecSize);
if (matches == 0)
return false;
@@ -350,12 +382,12 @@ int PCRE::GlobalReplace(string *str,
const PCRE& pattern,
const StringPiece& rewrite) {
int count = 0;
- int vec[kVecSize];
+ int vec[kVecSize] = {};
string out;
int start = 0;
bool last_match_was_empty_string = false;
- for (; start <= str->length();) {
+ while (start <= static_cast<int>(str->size())) {
// If the previous match was for the empty string, we shouldn't
// just match again: we'll match in the same way and get an
// infinite loop. Instead, we do the match in a special way:
@@ -371,14 +403,15 @@ int PCRE::GlobalReplace(string *str,
matches = pattern.TryMatch(*str, start, ANCHOR_START, false,
vec, kVecSize);
if (matches <= 0) {
- if (start < str->length())
+ if (start < static_cast<int>(str->size()))
out.push_back((*str)[start]);
start++;
last_match_was_empty_string = false;
continue;
}
} else {
- matches = pattern.TryMatch(*str, start, UNANCHORED, true, vec, kVecSize);
+ matches = pattern.TryMatch(*str, start, UNANCHORED, true,
+ vec, kVecSize);
if (matches <= 0)
break;
}
@@ -396,8 +429,8 @@ int PCRE::GlobalReplace(string *str,
if (count == 0)
return 0;
- if (start < str->length())
- out.append(*str, start, str->length() - start);
+ if (start < static_cast<int>(str->size()))
+ out.append(*str, start, static_cast<int>(str->size()) - start);
swap(out, *str);
return count;
}
@@ -406,7 +439,7 @@ bool PCRE::Extract(const StringPiece &text,
const PCRE& pattern,
const StringPiece &rewrite,
string *out) {
- int vec[kVecSize];
+ int vec[kVecSize] = {};
int matches = pattern.TryMatch(text, 0, UNANCHORED, true, vec, kVecSize);
if (matches == 0)
return false;
@@ -452,7 +485,7 @@ string PCRE::QuoteMeta(const StringPiece& unquoted) {
/***** Actual matching and rewriting code *****/
bool PCRE::HitLimit() {
- return hit_limit_;
+ return hit_limit_ != 0;
}
void PCRE::ClearHitLimit() {
@@ -600,9 +633,9 @@ bool PCRE::DoMatch(const StringPiece& text,
const Arg* const args[],
int n) const {
assert(n >= 0);
- size_t const vecsize = (1 + n) * 3; // results + PCRE workspace
- // (as for kVecSize)
- int *vec = new int[vecsize];
+ const int vecsize = (1 + n) * 3; // results + PCRE workspace
+ // (as for kVecSize)
+ int* vec = new int[vecsize];
bool b = DoMatchImpl(text, anchor, consumed, args, n, vec, vecsize);
delete[] vec;
return b;
@@ -808,7 +841,7 @@ bool PCRE::Arg::parse_short_radix(const char* str,
if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse
if ((short)r != r) return false; // Out of range
if (dest == NULL) return true;
- *(reinterpret_cast<short*>(dest)) = r;
+ *(reinterpret_cast<short*>(dest)) = (short)r;
return true;
}
@@ -820,7 +853,7 @@ bool PCRE::Arg::parse_ushort_radix(const char* str,
if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse
if ((ushort)r != r) return false; // Out of range
if (dest == NULL) return true;
- *(reinterpret_cast<unsigned short*>(dest)) = r;
+ *(reinterpret_cast<unsigned short*>(dest)) = (ushort)r;
return true;
}
@@ -898,7 +931,7 @@ bool PCRE::Arg::parse_double(const char* str, int n, void* dest) {
char* end;
double r = strtod(buf, &end);
if (end != buf + n) {
-#ifdef COMPILER_MSVC
+#ifdef _WIN32
// Microsoft's strtod() doesn't handle inf and nan, so we have to
// handle it explicitly. Speed is not important here because this
// code is only called in unit tests.
@@ -911,11 +944,11 @@ bool PCRE::Arg::parse_double(const char* str, int n, void* dest) {
++i;
}
if (0 == stricmp(i, "inf") || 0 == stricmp(i, "infinity")) {
- r = numeric_limits<double>::infinity();
+ r = std::numeric_limits<double>::infinity();
if (!pos)
r = -r;
} else if (0 == stricmp(i, "nan")) {
- r = numeric_limits<double>::quiet_NaN();
+ r = std::numeric_limits<double>::quiet_NaN();
} else {
return false;
}
« no previous file with comments | « third_party/re2/util/pcre.h ('k') | third_party/re2/util/rune.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698