986 lines
36 KiB
Diff
Executable File
986 lines
36 KiB
Diff
Executable File
--- a/src/3rdparty/chromium/third_party/re2/src/re2/re2.h
|
|
+++ b/src/3rdparty/chromium/third_party/re2/src/re2/re2.h
|
|
@@ -2,8 +2,8 @@
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
-#ifndef RE2_RE2_H
|
|
-#define RE2_RE2_H
|
|
+#ifndef RE2_RE2_H_
|
|
+#define RE2_RE2_H_
|
|
|
|
// C++ interface to the re2 regular-expression library.
|
|
// RE2 supports Perl-style regular expressions (with extensions like
|
|
@@ -179,38 +179,25 @@
|
|
// RE2::Octal(&a), RE2::Hex(&b), RE2::CRadix(&c), RE2::CRadix(&d));
|
|
// will leave 64 in a, b, c, and d.
|
|
|
|
+#include <stddef.h>
|
|
#include <stdint.h>
|
|
+#include <sys/types.h>
|
|
+#include <algorithm>
|
|
#include <map>
|
|
+#include <mutex>
|
|
#include <string>
|
|
-#include "re2/stringpiece.h"
|
|
-#include "re2/variadic_function.h"
|
|
|
|
-#ifndef RE2_HAVE_LONGLONG
|
|
-#define RE2_HAVE_LONGLONG 1
|
|
-#endif
|
|
+#include "re2/stringpiece.h"
|
|
|
|
namespace re2 {
|
|
-
|
|
-using std::string;
|
|
-using std::map;
|
|
-class Mutex;
|
|
class Prog;
|
|
class Regexp;
|
|
+} // namespace re2
|
|
+
|
|
+namespace re2 {
|
|
|
|
-// The following enum should be used only as a constructor argument to indicate
|
|
-// that the variable has static storage class, and that the constructor should
|
|
-// do nothing to its state. It indicates to the reader that it is legal to
|
|
-// declare a static instance of the class, provided the constructor is given
|
|
-// the LINKER_INITIALIZED argument. Normally, it is unsafe to declare a
|
|
-// static variable that has a constructor or a destructor because invocation
|
|
-// order is undefined. However, IF the type can be initialized by filling with
|
|
-// zeroes (which the loader does for static variables), AND the type's
|
|
-// destructor does nothing to the storage, then a constructor for static
|
|
-// initialization can be declared as
|
|
-// explicit MyClass(LinkerInitialized x) {}
|
|
-// and invoked as
|
|
-// static MyClass my_variable_name(LINKER_INITIALIZED);
|
|
-enum LinkerInitialized { LINKER_INITIALIZED };
|
|
+// TODO(junyer): Get rid of this.
|
|
+using std::string;
|
|
|
|
// Interface for regular expression matching. Also corresponds to a
|
|
// pre-compiled regular expression. An "RE2" object is safe for
|
|
@@ -266,7 +253,7 @@ class RE2 {
|
|
RE2(const string& pattern);
|
|
#endif
|
|
RE2(const StringPiece& pattern);
|
|
- RE2(const StringPiece& pattern, const Options& option);
|
|
+ RE2(const StringPiece& pattern, const Options& options);
|
|
~RE2();
|
|
|
|
// Returns whether RE2 was created properly.
|
|
@@ -296,7 +283,7 @@ class RE2 {
|
|
// EXPERIMENTAL! SUBJECT TO CHANGE!
|
|
// Outputs the program fanout as a histogram bucketed by powers of 2.
|
|
// Returns the number of the largest non-empty bucket.
|
|
- int ProgramFanout(map<int, int>* histogram) const;
|
|
+ int ProgramFanout(std::map<int, int>* histogram) const;
|
|
|
|
// Returns the underlying Regexp; not for general use.
|
|
// Returns entire_regexp_ so that callers don't need
|
|
@@ -305,21 +292,21 @@ class RE2 {
|
|
|
|
/***** The useful part: the matching interface *****/
|
|
|
|
- // Matches "text" against "pattern". If pointer arguments are
|
|
+ // Matches "text" against "re". If pointer arguments are
|
|
// supplied, copies matched sub-patterns into them.
|
|
//
|
|
// You can pass in a "const char*" or a "string" for "text".
|
|
- // You can pass in a "const char*" or a "string" or a "RE2" for "pattern".
|
|
+ // You can pass in a "const char*" or a "string" or a "RE2" for "re".
|
|
//
|
|
// The provided pointer arguments can be pointers to any scalar numeric
|
|
// type, or one of:
|
|
// string (matched piece is copied to string)
|
|
// StringPiece (StringPiece is mutated to point to matched piece)
|
|
- // T (where "bool T::ParseFrom(const char*, int)" exists)
|
|
+ // T (where "bool T::ParseFrom(const char*, size_t)" exists)
|
|
// (void*)NULL (the corresponding matched sub-pattern is not copied)
|
|
//
|
|
// Returns true iff all of the following conditions are satisfied:
|
|
- // a. "text" matches "pattern" exactly
|
|
+ // a. "text" matches "re" exactly
|
|
// b. The number of matched sub-patterns is >= number of supplied pointers
|
|
// c. The "i"th argument has a suitable type for holding the
|
|
// string captured as the "i"th sub-pattern. If you pass in
|
|
@@ -335,32 +322,65 @@ class RE2 {
|
|
// RE2::FullMatch("abc", "[a-z]+(\\d+)?", &number);
|
|
static bool FullMatchN(const StringPiece& text, const RE2& re,
|
|
const Arg* const args[], int argc);
|
|
- static const VariadicFunction2<
|
|
- bool, const StringPiece&, const RE2&, Arg, RE2::FullMatchN> FullMatch;
|
|
|
|
- // Exactly like FullMatch(), except that "pattern" is allowed to match
|
|
+ // Exactly like FullMatch(), except that "re" is allowed to match
|
|
// a substring of "text".
|
|
- static bool PartialMatchN(const StringPiece& text, const RE2& re, // 3..16 args
|
|
+ static bool PartialMatchN(const StringPiece& text, const RE2& re,
|
|
const Arg* const args[], int argc);
|
|
- static const VariadicFunction2<
|
|
- bool, const StringPiece&, const RE2&, Arg, RE2::PartialMatchN> PartialMatch;
|
|
|
|
- // Like FullMatch() and PartialMatch(), except that pattern has to
|
|
- // match a prefix of "text", and "input" is advanced past the matched
|
|
+ // Like FullMatch() and PartialMatch(), except that "re" has to match
|
|
+ // a prefix of the text, and "input" is advanced past the matched
|
|
// text. Note: "input" is modified iff this routine returns true.
|
|
- static bool ConsumeN(StringPiece* input, const RE2& pattern, // 3..16 args
|
|
+ static bool ConsumeN(StringPiece* input, const RE2& re,
|
|
const Arg* const args[], int argc);
|
|
- static const VariadicFunction2<
|
|
- bool, StringPiece*, const RE2&, Arg, RE2::ConsumeN> Consume;
|
|
|
|
- // Like Consume(..), but does not anchor the match at the beginning of the
|
|
- // string. That is, "pattern" need not start its match at the beginning of
|
|
- // "input". For example, "FindAndConsume(s, "(\\w+)", &word)" finds the next
|
|
- // word in "s" and stores it in "word".
|
|
- static bool FindAndConsumeN(StringPiece* input, const RE2& pattern,
|
|
- const Arg* const args[], int argc);
|
|
- static const VariadicFunction2<
|
|
- bool, StringPiece*, const RE2&, Arg, RE2::FindAndConsumeN> FindAndConsume;
|
|
+ // Like Consume(), but does not anchor the match at the beginning of
|
|
+ // the text. That is, "re" need not start its match at the beginning
|
|
+ // of "input". For example, "FindAndConsume(s, "(\\w+)", &word)" finds
|
|
+ // the next word in "s" and stores it in "word".
|
|
+ static bool FindAndConsumeN(StringPiece* input, const RE2& re,
|
|
+ const Arg* const args[], int argc);
|
|
+
|
|
+#ifndef SWIG
|
|
+ private:
|
|
+ template <typename F, typename SP>
|
|
+ static inline bool Apply(F f, SP sp, const RE2& re) {
|
|
+ return f(sp, re, NULL, 0);
|
|
+ }
|
|
+
|
|
+ template <typename F, typename SP, typename... A>
|
|
+ static inline bool Apply(F f, SP sp, const RE2& re, const A&... a) {
|
|
+ const Arg* const args[] = {&a...};
|
|
+ const int argc = sizeof...(a);
|
|
+ return f(sp, re, args, argc);
|
|
+ }
|
|
+
|
|
+ public:
|
|
+ // In order to allow FullMatch() et al. to be called with a varying number
|
|
+ // of arguments of varying types, we use two layers of variadic templates.
|
|
+ // The first layer constructs the temporary Arg objects. The second layer
|
|
+ // (above) constructs the array of pointers to the temporary Arg objects.
|
|
+
|
|
+ template <typename... A>
|
|
+ static bool FullMatch(const StringPiece& text, const RE2& re, A&&... a) {
|
|
+ return Apply(FullMatchN, text, re, Arg(std::forward<A>(a))...);
|
|
+ }
|
|
+
|
|
+ template <typename... A>
|
|
+ static bool PartialMatch(const StringPiece& text, const RE2& re, A&&... a) {
|
|
+ return Apply(PartialMatchN, text, re, Arg(std::forward<A>(a))...);
|
|
+ }
|
|
+
|
|
+ template <typename... A>
|
|
+ static bool Consume(StringPiece* input, const RE2& re, A&&... a) {
|
|
+ return Apply(ConsumeN, input, re, Arg(std::forward<A>(a))...);
|
|
+ }
|
|
+
|
|
+ template <typename... A>
|
|
+ static bool FindAndConsume(StringPiece* input, const RE2& re, A&&... a) {
|
|
+ return Apply(FindAndConsumeN, input, re, Arg(std::forward<A>(a))...);
|
|
+ }
|
|
+#endif
|
|
|
|
// Replace the first match of "pattern" in "str" with "rewrite".
|
|
// Within "rewrite", backslash-escaped digits (\1 to \9) can be
|
|
@@ -451,12 +471,12 @@ class RE2 {
|
|
// The map records the index of the leftmost group
|
|
// with the given name.
|
|
// Only valid until the re is deleted.
|
|
- const map<string, int>& NamedCapturingGroups() const;
|
|
+ const std::map<string, int>& NamedCapturingGroups() const;
|
|
|
|
// Return a map from capturing indices to names.
|
|
// The map has no entries for unnamed groups.
|
|
// Only valid until the re is deleted.
|
|
- const map<int, string>& CapturingGroupNames() const;
|
|
+ const std::map<int, string>& CapturingGroupNames() const;
|
|
|
|
// General matching routine.
|
|
// Match against text starting at offset startpos
|
|
@@ -465,8 +485,8 @@ class RE2 {
|
|
// On a successful match, fills in match[] (up to nmatch entries)
|
|
// with information about submatches.
|
|
// I.e. matching RE2("(foo)|(bar)baz") on "barbazbla" will return true,
|
|
- // setting match[0] = "barbaz", match[1] = NULL, match[2] = "bar",
|
|
- // match[3] = NULL, ..., up to match[nmatch-1] = NULL.
|
|
+ // setting match[0] = "barbaz", match[1].data() = NULL, match[2] = "bar",
|
|
+ // match[3].data() = NULL, ..., up to match[nmatch-1].data() = NULL.
|
|
//
|
|
// Don't ask for more match information than you will use:
|
|
// runs much faster with nmatch == 1 than nmatch > 1, and
|
|
@@ -477,10 +497,10 @@ class RE2 {
|
|
// Passing text == StringPiece(NULL, 0) will be handled like any other
|
|
// empty string, but note that on return, it will not be possible to tell
|
|
// whether submatch i matched the empty string or did not match:
|
|
- // either way, match[i] == NULL.
|
|
+ // either way, match[i].data() == NULL.
|
|
bool Match(const StringPiece& text,
|
|
- int startpos,
|
|
- int endpos,
|
|
+ size_t startpos,
|
|
+ size_t endpos,
|
|
Anchor anchor,
|
|
StringPiece *match,
|
|
int nmatch) const;
|
|
@@ -638,19 +658,7 @@ class RE2 {
|
|
void set_one_line(bool b) { one_line_ = b; }
|
|
|
|
void Copy(const Options& src) {
|
|
- encoding_ = src.encoding_;
|
|
- posix_syntax_ = src.posix_syntax_;
|
|
- longest_match_ = src.longest_match_;
|
|
- log_errors_ = src.log_errors_;
|
|
- max_mem_ = src.max_mem_;
|
|
- literal_ = src.literal_;
|
|
- never_nl_ = src.never_nl_;
|
|
- dot_nl_ = src.dot_nl_;
|
|
- never_capture_ = src.never_capture_;
|
|
- case_sensitive_ = src.case_sensitive_;
|
|
- perl_classes_ = src.perl_classes_;
|
|
- word_boundary_ = src.word_boundary_;
|
|
- one_line_ = src.one_line_;
|
|
+ *this = src;
|
|
}
|
|
|
|
int ParseFlags() const;
|
|
@@ -669,10 +677,6 @@ class RE2 {
|
|
bool perl_classes_;
|
|
bool word_boundary_;
|
|
bool one_line_;
|
|
-
|
|
- //DISALLOW_COPY_AND_ASSIGN(Options);
|
|
- Options(const Options&);
|
|
- void operator=(const Options&);
|
|
};
|
|
|
|
// Returns the options set in the constructor.
|
|
@@ -685,10 +689,8 @@ class RE2 {
|
|
static inline Arg CRadix(unsigned int* x);
|
|
static inline Arg CRadix(long* x);
|
|
static inline Arg CRadix(unsigned long* x);
|
|
- #if RE2_HAVE_LONGLONG
|
|
static inline Arg CRadix(long long* x);
|
|
static inline Arg CRadix(unsigned long long* x);
|
|
- #endif
|
|
|
|
static inline Arg Hex(short* x);
|
|
static inline Arg Hex(unsigned short* x);
|
|
@@ -696,10 +698,8 @@ class RE2 {
|
|
static inline Arg Hex(unsigned int* x);
|
|
static inline Arg Hex(long* x);
|
|
static inline Arg Hex(unsigned long* x);
|
|
- #if RE2_HAVE_LONGLONG
|
|
static inline Arg Hex(long long* x);
|
|
static inline Arg Hex(unsigned long long* x);
|
|
- #endif
|
|
|
|
static inline Arg Octal(short* x);
|
|
static inline Arg Octal(unsigned short* x);
|
|
@@ -707,47 +707,50 @@ class RE2 {
|
|
static inline Arg Octal(unsigned int* x);
|
|
static inline Arg Octal(long* x);
|
|
static inline Arg Octal(unsigned long* x);
|
|
- #if RE2_HAVE_LONGLONG
|
|
static inline Arg Octal(long long* x);
|
|
static inline Arg Octal(unsigned long long* x);
|
|
- #endif
|
|
|
|
private:
|
|
void Init(const StringPiece& pattern, const Options& options);
|
|
|
|
bool DoMatch(const StringPiece& text,
|
|
- Anchor anchor,
|
|
- int* consumed,
|
|
- const Arg* const args[],
|
|
- int n) const;
|
|
+ Anchor anchor,
|
|
+ size_t* consumed,
|
|
+ const Arg* const args[],
|
|
+ int n) const;
|
|
|
|
re2::Prog* ReverseProg() const;
|
|
|
|
- mutable Mutex* mutex_;
|
|
- string pattern_; // string regular expression
|
|
- Options options_; // option flags
|
|
+ string pattern_; // string regular expression
|
|
+ Options options_; // option flags
|
|
string prefix_; // required prefix (before regexp_)
|
|
bool prefix_foldcase_; // prefix is ASCII case-insensitive
|
|
re2::Regexp* entire_regexp_; // parsed regular expression
|
|
re2::Regexp* suffix_regexp_; // parsed regular expression, prefix removed
|
|
re2::Prog* prog_; // compiled program for regexp
|
|
- mutable re2::Prog* rprog_; // reverse program for regexp
|
|
- bool is_one_pass_; // can use prog_->SearchOnePass?
|
|
- mutable const string* error_; // Error indicator
|
|
- // (or points to empty string)
|
|
- mutable ErrorCode error_code_; // Error code
|
|
- mutable string error_arg_; // Fragment of regexp showing error
|
|
- mutable int num_captures_; // Number of capturing groups
|
|
+ bool is_one_pass_; // can use prog_->SearchOnePass?
|
|
+
|
|
+ mutable re2::Prog* rprog_; // reverse program for regexp
|
|
+ mutable const string* error_; // Error indicator
|
|
+ // (or points to empty string)
|
|
+ mutable ErrorCode error_code_; // Error code
|
|
+ mutable string error_arg_; // Fragment of regexp showing error
|
|
+ mutable int num_captures_; // Number of capturing groups
|
|
|
|
// Map from capture names to indices
|
|
- mutable const map<string, int>* named_groups_;
|
|
+ mutable const std::map<string, int>* named_groups_;
|
|
|
|
// Map from capture indices to names
|
|
- mutable const map<int, string>* group_names_;
|
|
+ mutable const std::map<int, string>* group_names_;
|
|
+
|
|
+ // Onces for lazy computations.
|
|
+ mutable std::once_flag rprog_once_;
|
|
+ mutable std::once_flag num_captures_once_;
|
|
+ mutable std::once_flag named_groups_once_;
|
|
+ mutable std::once_flag group_names_once_;
|
|
|
|
- //DISALLOW_COPY_AND_ASSIGN(RE2);
|
|
- RE2(const RE2&);
|
|
- void operator=(const RE2&);
|
|
+ RE2(const RE2&) = delete;
|
|
+ RE2& operator=(const RE2&) = delete;
|
|
};
|
|
|
|
/***** Implementation details *****/
|
|
@@ -758,7 +761,7 @@ class RE2 {
|
|
template <class T>
|
|
class _RE2_MatchObject {
|
|
public:
|
|
- static inline bool Parse(const char* str, int n, void* dest) {
|
|
+ static inline bool Parse(const char* str, size_t n, void* dest) {
|
|
if (dest == NULL) return true;
|
|
T* object = reinterpret_cast<T*>(dest);
|
|
return object->ParseFrom(str, n);
|
|
@@ -773,31 +776,29 @@ class RE2::Arg {
|
|
// Constructor specially designed for NULL arguments
|
|
Arg(void*);
|
|
|
|
- typedef bool (*Parser)(const char* str, int n, void* dest);
|
|
+ typedef bool (*Parser)(const char* str, size_t n, void* dest);
|
|
|
|
// Type-specific parsers
|
|
-#define MAKE_PARSER(type,name) \
|
|
- Arg(type* p) : arg_(p), parser_(name) { } \
|
|
- Arg(type* p, Parser parser) : arg_(p), parser_(parser) { } \
|
|
-
|
|
+#define MAKE_PARSER(type, name) \
|
|
+ Arg(type* p) : arg_(p), parser_(name) {} \
|
|
+ Arg(type* p, Parser parser) : arg_(p), parser_(parser) {}
|
|
|
|
MAKE_PARSER(char, parse_char);
|
|
- MAKE_PARSER(signed char, parse_char);
|
|
+ MAKE_PARSER(signed char, parse_schar);
|
|
MAKE_PARSER(unsigned char, parse_uchar);
|
|
+ MAKE_PARSER(float, parse_float);
|
|
+ MAKE_PARSER(double, parse_double);
|
|
+ MAKE_PARSER(string, parse_string);
|
|
+ MAKE_PARSER(StringPiece, parse_stringpiece);
|
|
+
|
|
MAKE_PARSER(short, parse_short);
|
|
MAKE_PARSER(unsigned short, parse_ushort);
|
|
MAKE_PARSER(int, parse_int);
|
|
MAKE_PARSER(unsigned int, parse_uint);
|
|
MAKE_PARSER(long, parse_long);
|
|
MAKE_PARSER(unsigned long, parse_ulong);
|
|
- #if RE2_HAVE_LONGLONG
|
|
MAKE_PARSER(long long, parse_longlong);
|
|
MAKE_PARSER(unsigned long long, parse_ulonglong);
|
|
- #endif
|
|
- MAKE_PARSER(float, parse_float);
|
|
- MAKE_PARSER(double, parse_double);
|
|
- MAKE_PARSER(string, parse_string);
|
|
- MAKE_PARSER(StringPiece, parse_stringpiece);
|
|
|
|
#undef MAKE_PARSER
|
|
|
|
@@ -808,29 +809,31 @@ class RE2::Arg {
|
|
: arg_(p), parser_(parser) { }
|
|
|
|
// Parse the data
|
|
- bool Parse(const char* str, int n) const;
|
|
+ bool Parse(const char* str, size_t n) const;
|
|
|
|
private:
|
|
void* arg_;
|
|
Parser parser_;
|
|
|
|
- static bool parse_null (const char* str, int n, void* dest);
|
|
- static bool parse_char (const char* str, int n, void* dest);
|
|
- static bool parse_uchar (const char* str, int n, void* dest);
|
|
- static bool parse_float (const char* str, int n, void* dest);
|
|
- static bool parse_double (const char* str, int n, void* dest);
|
|
- static bool parse_string (const char* str, int n, void* dest);
|
|
- static bool parse_stringpiece (const char* str, int n, void* dest);
|
|
-
|
|
-#define DECLARE_INTEGER_PARSER(name) \
|
|
- private: \
|
|
- static bool parse_ ## name(const char* str, int n, void* dest); \
|
|
- static bool parse_ ## name ## _radix( \
|
|
- const char* str, int n, void* dest, int radix); \
|
|
- public: \
|
|
- static bool parse_ ## name ## _hex(const char* str, int n, void* dest); \
|
|
- static bool parse_ ## name ## _octal(const char* str, int n, void* dest); \
|
|
- static bool parse_ ## name ## _cradix(const char* str, int n, void* dest)
|
|
+ static bool parse_null (const char* str, size_t n, void* dest);
|
|
+ static bool parse_char (const char* str, size_t n, void* dest);
|
|
+ static bool parse_schar (const char* str, size_t n, void* dest);
|
|
+ static bool parse_uchar (const char* str, size_t n, void* dest);
|
|
+ static bool parse_float (const char* str, size_t n, void* dest);
|
|
+ static bool parse_double (const char* str, size_t n, void* dest);
|
|
+ static bool parse_string (const char* str, size_t n, void* dest);
|
|
+ static bool parse_stringpiece (const char* str, size_t n, void* dest);
|
|
+
|
|
+#define DECLARE_INTEGER_PARSER(name) \
|
|
+ private: \
|
|
+ static bool parse_##name(const char* str, size_t n, void* dest); \
|
|
+ static bool parse_##name##_radix(const char* str, size_t n, void* dest, \
|
|
+ int radix); \
|
|
+ \
|
|
+ public: \
|
|
+ static bool parse_##name##_hex(const char* str, size_t n, void* dest); \
|
|
+ static bool parse_##name##_octal(const char* str, size_t n, void* dest); \
|
|
+ static bool parse_##name##_cradix(const char* str, size_t n, void* dest)
|
|
|
|
DECLARE_INTEGER_PARSER(short);
|
|
DECLARE_INTEGER_PARSER(ushort);
|
|
@@ -838,29 +841,31 @@ class RE2::Arg {
|
|
DECLARE_INTEGER_PARSER(uint);
|
|
DECLARE_INTEGER_PARSER(long);
|
|
DECLARE_INTEGER_PARSER(ulong);
|
|
- #if RE2_HAVE_LONGLONG
|
|
DECLARE_INTEGER_PARSER(longlong);
|
|
DECLARE_INTEGER_PARSER(ulonglong);
|
|
- #endif
|
|
|
|
#undef DECLARE_INTEGER_PARSER
|
|
+
|
|
};
|
|
|
|
inline RE2::Arg::Arg() : arg_(NULL), parser_(parse_null) { }
|
|
inline RE2::Arg::Arg(void* p) : arg_(p), parser_(parse_null) { }
|
|
|
|
-inline bool RE2::Arg::Parse(const char* str, int n) const {
|
|
+inline bool RE2::Arg::Parse(const char* str, size_t n) const {
|
|
return (*parser_)(str, n, arg_);
|
|
}
|
|
|
|
// This part of the parser, appropriate only for ints, deals with bases
|
|
-#define MAKE_INTEGER_PARSER(type, name) \
|
|
- inline RE2::Arg RE2::Hex(type* ptr) { \
|
|
- return RE2::Arg(ptr, RE2::Arg::parse_ ## name ## _hex); } \
|
|
- inline RE2::Arg RE2::Octal(type* ptr) { \
|
|
- return RE2::Arg(ptr, RE2::Arg::parse_ ## name ## _octal); } \
|
|
- inline RE2::Arg RE2::CRadix(type* ptr) { \
|
|
- return RE2::Arg(ptr, RE2::Arg::parse_ ## name ## _cradix); }
|
|
+#define MAKE_INTEGER_PARSER(type, name) \
|
|
+ inline RE2::Arg RE2::Hex(type* ptr) { \
|
|
+ return RE2::Arg(ptr, RE2::Arg::parse_##name##_hex); \
|
|
+ } \
|
|
+ inline RE2::Arg RE2::Octal(type* ptr) { \
|
|
+ return RE2::Arg(ptr, RE2::Arg::parse_##name##_octal); \
|
|
+ } \
|
|
+ inline RE2::Arg RE2::CRadix(type* ptr) { \
|
|
+ return RE2::Arg(ptr, RE2::Arg::parse_##name##_cradix); \
|
|
+ }
|
|
|
|
MAKE_INTEGER_PARSER(short, short)
|
|
MAKE_INTEGER_PARSER(unsigned short, ushort)
|
|
@@ -868,15 +873,62 @@ MAKE_INTEGER_PARSER(int,
|
|
MAKE_INTEGER_PARSER(unsigned int, uint)
|
|
MAKE_INTEGER_PARSER(long, long)
|
|
MAKE_INTEGER_PARSER(unsigned long, ulong)
|
|
-#if RE2_HAVE_LONGLONG
|
|
MAKE_INTEGER_PARSER(long long, longlong)
|
|
MAKE_INTEGER_PARSER(unsigned long long, ulonglong)
|
|
-#endif
|
|
|
|
#undef MAKE_INTEGER_PARSER
|
|
|
|
+#ifndef SWIG
|
|
+// Helper for writing global or static RE2s safely.
|
|
+// Write
|
|
+// static LazyRE2 re = {".*"};
|
|
+// and then use *re instead of writing
|
|
+// static RE2 re(".*");
|
|
+// The former is more careful about multithreaded
|
|
+// situations than the latter.
|
|
+//
|
|
+// N.B. This class never deletes the RE2 object that
|
|
+// it constructs: that's a feature, so that it can be used
|
|
+// for global and function static variables.
|
|
+class LazyRE2 {
|
|
+ private:
|
|
+ struct NoArg {};
|
|
+
|
|
+ public:
|
|
+ typedef RE2 element_type; // support std::pointer_traits
|
|
+
|
|
+ // Constructor omitted to preserve braced initialization in C++98.
|
|
+
|
|
+ // Pretend to be a pointer to Type (never NULL due to on-demand creation):
|
|
+ RE2& operator*() const { return *get(); }
|
|
+ RE2* operator->() const { return get(); }
|
|
+
|
|
+ // Named accessor/initializer:
|
|
+ RE2* get() const {
|
|
+ std::call_once(once_, &LazyRE2::Init, this);
|
|
+ return ptr_;
|
|
+ }
|
|
+
|
|
+ // All data fields must be public to support {"foo"} initialization.
|
|
+ const char* pattern_;
|
|
+ RE2::CannedOptions options_;
|
|
+ NoArg barrier_against_excess_initializers_;
|
|
+
|
|
+ mutable RE2* ptr_;
|
|
+ mutable std::once_flag once_;
|
|
+
|
|
+ private:
|
|
+ static void Init(const LazyRE2* lazy_re2) {
|
|
+ lazy_re2->ptr_ = new RE2(lazy_re2->pattern_, lazy_re2->options_);
|
|
+ }
|
|
+
|
|
+ void operator=(const LazyRE2&); // disallowed
|
|
+};
|
|
+#endif // SWIG
|
|
+
|
|
} // namespace re2
|
|
|
|
using re2::RE2;
|
|
+using re2::LazyRE2;
|
|
|
|
-#endif /* RE2_RE2_H */
|
|
+#endif // RE2_RE2_H_
|
|
--- a/src/3rdparty/chromium/third_party/re2/src/re2/filtered_re2.h
|
|
+++ b/src/3rdparty/chromium/third_party/re2/src/re2/filtered_re2.h
|
|
@@ -2,6 +2,9 @@
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
+#ifndef RE2_FILTERED_RE2_H_
|
|
+#define RE2_FILTERED_RE2_H_
|
|
+
|
|
// The class FilteredRE2 is used as a wrapper to multiple RE2 regexps.
|
|
// It provides a prefilter mechanism that helps in cutting down the
|
|
// number of regexps that need to be actually searched.
|
|
@@ -18,20 +21,19 @@
|
|
// indices of strings that were found in the text to get the actual
|
|
// regexp matches.
|
|
|
|
-#ifndef RE2_FILTERED_RE2_H_
|
|
-#define RE2_FILTERED_RE2_H_
|
|
-
|
|
+#include <string>
|
|
#include <vector>
|
|
+
|
|
#include "re2/re2.h"
|
|
|
|
namespace re2 {
|
|
-using std::vector;
|
|
|
|
class PrefilterTree;
|
|
|
|
class FilteredRE2 {
|
|
public:
|
|
FilteredRE2();
|
|
+ explicit FilteredRE2(int min_atom_len);
|
|
~FilteredRE2();
|
|
|
|
// Uses RE2 constructor to create a RE2 object (re). Returns
|
|
@@ -47,7 +49,7 @@ class FilteredRE2 {
|
|
// the search text should be lowercased first to find matching
|
|
// strings from the set of strings returned by Compile. Call after
|
|
// all Add calls are done.
|
|
- void Compile(vector<string>* strings_to_match);
|
|
+ void Compile(std::vector<string>* strings_to_match);
|
|
|
|
// Returns the index of the first matching regexp.
|
|
// Returns -1 on no match. Can be called prior to Compile.
|
|
@@ -59,21 +61,21 @@ class FilteredRE2 {
|
|
// Returns -1 on no match. Compile has to be called before
|
|
// calling this.
|
|
int FirstMatch(const StringPiece& text,
|
|
- const vector<int>& atoms) const;
|
|
+ const std::vector<int>& atoms) const;
|
|
|
|
// Returns the indices of all matching regexps, after first clearing
|
|
// matched_regexps.
|
|
bool AllMatches(const StringPiece& text,
|
|
- const vector<int>& atoms,
|
|
- vector<int>* matching_regexps) const;
|
|
+ const std::vector<int>& atoms,
|
|
+ std::vector<int>* matching_regexps) const;
|
|
|
|
// Returns the indices of all potentially matching regexps after first
|
|
// clearing potential_regexps.
|
|
// A regexp is potentially matching if it passes the filter.
|
|
// If a regexp passes the filter it may still not match.
|
|
// A regexp that does not pass the filter is guaranteed to not match.
|
|
- void AllPotentials(const vector<int>& atoms,
|
|
- vector<int>* potential_regexps) const;
|
|
+ void AllPotentials(const std::vector<int>& atoms,
|
|
+ std::vector<int>* potential_regexps) const;
|
|
|
|
// The number of regexps added.
|
|
int NumRegexps() const { return static_cast<int>(re2_vec_.size()); }
|
|
@@ -87,11 +89,11 @@ class FilteredRE2 {
|
|
void PrintPrefilter(int regexpid);
|
|
|
|
// Useful for testing and debugging.
|
|
- void RegexpsGivenStrings(const vector<int>& matched_atoms,
|
|
- vector<int>* passed_regexps);
|
|
+ void RegexpsGivenStrings(const std::vector<int>& matched_atoms,
|
|
+ std::vector<int>* passed_regexps);
|
|
|
|
// All the regexps in the FilteredRE2.
|
|
- vector<RE2*> re2_vec_;
|
|
+ std::vector<RE2*> re2_vec_;
|
|
|
|
// Has the FilteredRE2 been compiled using Compile()
|
|
bool compiled_;
|
|
@@ -99,9 +101,8 @@ class FilteredRE2 {
|
|
// An AND-OR tree of string atoms used for filtering regexps.
|
|
PrefilterTree* prefilter_tree_;
|
|
|
|
- //DISALLOW_COPY_AND_ASSIGN(FilteredRE2);
|
|
- FilteredRE2(const FilteredRE2&);
|
|
- void operator=(const FilteredRE2&);
|
|
+ FilteredRE2(const FilteredRE2&) = delete;
|
|
+ FilteredRE2& operator=(const FilteredRE2&) = delete;
|
|
};
|
|
|
|
} // namespace re2
|
|
--- a/src/3rdparty/chromium/third_party/re2/src/re2/set.h
|
|
+++ b/src/3rdparty/chromium/third_party/re2/src/re2/set.h
|
|
@@ -2,16 +2,20 @@
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
-#ifndef RE2_SET_H
|
|
-#define RE2_SET_H
|
|
+#ifndef RE2_SET_H_
|
|
+#define RE2_SET_H_
|
|
|
|
-#include <utility>
|
|
+#include <string>
|
|
#include <vector>
|
|
|
|
#include "re2/re2.h"
|
|
|
|
namespace re2 {
|
|
-using std::vector;
|
|
+class Prog;
|
|
+class Regexp;
|
|
+} // namespace re2
|
|
+
|
|
+namespace re2 {
|
|
|
|
// An RE2::Set represents a collection of regexps that can
|
|
// be searched for simultaneously.
|
|
@@ -31,25 +35,25 @@ class RE2::Set {
|
|
|
|
// Compile prepares the Set for matching.
|
|
// Add must not be called again after Compile.
|
|
- // Compile must be called before FullMatch or PartialMatch.
|
|
+ // Compile must be called before Match.
|
|
// Compile may return false if it runs out of memory.
|
|
bool Compile();
|
|
|
|
// Match returns true if text matches any of the regexps in the set.
|
|
- // If so, it fills v with the indices of the matching regexps.
|
|
- bool Match(const StringPiece& text, vector<int>* v) const;
|
|
+ // If so, it fills v (if not NULL) with the indices of the matching regexps.
|
|
+ bool Match(const StringPiece& text, std::vector<int>* v) const;
|
|
|
|
private:
|
|
RE2::Options options_;
|
|
RE2::Anchor anchor_;
|
|
- vector<re2::Regexp*> re_;
|
|
+ std::vector<re2::Regexp*> re_;
|
|
re2::Prog* prog_;
|
|
bool compiled_;
|
|
- //DISALLOW_COPY_AND_ASSIGN(Set);
|
|
- Set(const Set&);
|
|
- void operator=(const Set&);
|
|
+
|
|
+ Set(const Set&) = delete;
|
|
+ Set& operator=(const Set&) = delete;
|
|
};
|
|
|
|
} // namespace re2
|
|
|
|
-#endif // RE2_SET_H
|
|
+#endif // RE2_SET_H_
|
|
--- a/src/3rdparty/chromium/third_party/re2/src/re2/stringpiece.h
|
|
+++ b/src/3rdparty/chromium/third_party/re2/src/re2/stringpiece.h
|
|
@@ -2,6 +2,9 @@
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
+#ifndef RE2_STRINGPIECE_H_
|
|
+#define RE2_STRINGPIECE_H_
|
|
+
|
|
// A string-like object that points to a sized piece of memory.
|
|
//
|
|
// Functions or methods may use const StringPiece& parameters to accept either
|
|
@@ -16,143 +19,139 @@
|
|
//
|
|
// Arghh! I wish C++ literals were "string".
|
|
|
|
-#ifndef STRINGS_STRINGPIECE_H__
|
|
-#define STRINGS_STRINGPIECE_H__
|
|
-
|
|
+#include <stddef.h>
|
|
#include <string.h>
|
|
#include <algorithm>
|
|
-#include <cstddef>
|
|
#include <iosfwd>
|
|
+#include <iterator>
|
|
#include <string>
|
|
|
|
namespace re2 {
|
|
|
|
class StringPiece {
|
|
- private:
|
|
- const char* ptr_;
|
|
- int length_;
|
|
-
|
|
public:
|
|
+ typedef char value_type;
|
|
+ typedef char* pointer;
|
|
+ typedef const char* const_pointer;
|
|
+ typedef char& reference;
|
|
+ typedef const char& const_reference;
|
|
+ typedef const char* const_iterator;
|
|
+ typedef const_iterator iterator;
|
|
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
+ typedef const_reverse_iterator reverse_iterator;
|
|
+ typedef size_t size_type;
|
|
+ typedef ptrdiff_t difference_type;
|
|
+ static const size_type npos = static_cast<size_type>(-1);
|
|
+
|
|
// We provide non-explicit singleton constructors so users can pass
|
|
// in a "const char*" or a "string" wherever a "StringPiece" is
|
|
// expected.
|
|
- StringPiece() : ptr_(NULL), length_(0) { }
|
|
- StringPiece(const char* str)
|
|
- : ptr_(str), length_((str == NULL) ? 0 : static_cast<int>(strlen(str))) { }
|
|
+ StringPiece()
|
|
+ : data_(NULL), size_(0) {}
|
|
StringPiece(const std::string& str)
|
|
- : ptr_(str.data()), length_(static_cast<int>(str.size())) { }
|
|
- StringPiece(const char* offset, int len) : ptr_(offset), length_(len) { }
|
|
-
|
|
- // data() may return a pointer to a buffer with embedded NULs, and the
|
|
- // returned buffer may or may not be null terminated. Therefore it is
|
|
- // typically a mistake to pass data() to a routine that expects a NUL
|
|
- // terminated string.
|
|
- const char* data() const { return ptr_; }
|
|
- int size() const { return length_; }
|
|
- int length() const { return length_; }
|
|
- bool empty() const { return length_ == 0; }
|
|
+ : data_(str.data()), size_(str.size()) {}
|
|
+ StringPiece(const char* str)
|
|
+ : data_(str), size_(str == NULL ? 0 : strlen(str)) {}
|
|
+ StringPiece(const char* str, size_type len)
|
|
+ : data_(str), size_(len) {}
|
|
|
|
- void clear() { ptr_ = NULL; length_ = 0; }
|
|
- void set(const char* data, int len) { ptr_ = data; length_ = len; }
|
|
- void set(const char* str) {
|
|
- ptr_ = str;
|
|
- if (str != NULL)
|
|
- length_ = static_cast<int>(strlen(str));
|
|
- else
|
|
- length_ = 0;
|
|
+ const_iterator begin() const { return data_; }
|
|
+ const_iterator end() const { return data_ + size_; }
|
|
+ const_reverse_iterator rbegin() const {
|
|
+ return const_reverse_iterator(data_ + size_);
|
|
}
|
|
- void set(const void* data, int len) {
|
|
- ptr_ = reinterpret_cast<const char*>(data);
|
|
- length_ = len;
|
|
+ const_reverse_iterator rend() const {
|
|
+ return const_reverse_iterator(data_);
|
|
}
|
|
|
|
- char operator[](int i) const { return ptr_[i]; }
|
|
+ size_type size() const { return size_; }
|
|
+ size_type length() const { return size_; }
|
|
+ bool empty() const { return size_ == 0; }
|
|
|
|
- void remove_prefix(int n) {
|
|
- ptr_ += n;
|
|
- length_ -= n;
|
|
+ const_reference operator[](size_type i) const { return data_[i]; }
|
|
+ const_pointer data() const { return data_; }
|
|
+
|
|
+ void remove_prefix(size_type n) {
|
|
+ data_ += n;
|
|
+ size_ -= n;
|
|
}
|
|
|
|
- void remove_suffix(int n) {
|
|
- length_ -= n;
|
|
+ void remove_suffix(size_type n) {
|
|
+ size_ -= n;
|
|
}
|
|
|
|
- int compare(const StringPiece& x) const {
|
|
- int r = memcmp(ptr_, x.ptr_, std::min(length_, x.length_));
|
|
- if (r == 0) {
|
|
- if (length_ < x.length_) r = -1;
|
|
- else if (length_ > x.length_) r = +1;
|
|
- }
|
|
- return r;
|
|
+ void set(const char* str) {
|
|
+ data_ = str;
|
|
+ size_ = str == NULL ? 0 : strlen(str);
|
|
+ }
|
|
+
|
|
+ void set(const char* str, size_type len) {
|
|
+ data_ = str;
|
|
+ size_ = len;
|
|
}
|
|
|
|
std::string as_string() const {
|
|
- return std::string(data(), size());
|
|
+ return std::string(data_, size_);
|
|
}
|
|
+
|
|
// We also define ToString() here, since many other string-like
|
|
// interfaces name the routine that converts to a C++ string
|
|
// "ToString", and it's confusing to have the method that does that
|
|
// for a StringPiece be called "as_string()". We also leave the
|
|
// "as_string()" method defined here for existing code.
|
|
std::string ToString() const {
|
|
- return std::string(data(), size());
|
|
+ return std::string(data_, size_);
|
|
}
|
|
|
|
- void CopyToString(std::string* target) const;
|
|
- void AppendToString(std::string* target) const;
|
|
-
|
|
- // Does "this" start with "x"
|
|
- bool starts_with(const StringPiece& x) const {
|
|
- return ((length_ >= x.length_) &&
|
|
- (memcmp(ptr_, x.ptr_, x.length_) == 0));
|
|
+ void CopyToString(std::string* target) const {
|
|
+ target->assign(data_, size_);
|
|
}
|
|
|
|
- // Does "this" end with "x"
|
|
- bool ends_with(const StringPiece& x) const {
|
|
- return ((length_ >= x.length_) &&
|
|
- (memcmp(ptr_ + (length_-x.length_), x.ptr_, x.length_) == 0));
|
|
+ void AppendToString(std::string* target) const {
|
|
+ target->append(data_, size_);
|
|
}
|
|
|
|
- // standard STL container boilerplate
|
|
- typedef char value_type;
|
|
- typedef const char* pointer;
|
|
- typedef const char& reference;
|
|
- typedef const char& const_reference;
|
|
- typedef size_t size_type;
|
|
- typedef ptrdiff_t difference_type;
|
|
- static const size_type npos;
|
|
- typedef const char* const_iterator;
|
|
- typedef const char* iterator;
|
|
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
- typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
- iterator begin() const { return ptr_; }
|
|
- iterator end() const { return ptr_ + length_; }
|
|
- const_reverse_iterator rbegin() const {
|
|
- return const_reverse_iterator(ptr_ + length_);
|
|
+ size_type copy(char* buf, size_type n, size_type pos = 0) const;
|
|
+ StringPiece substr(size_type pos = 0, size_type n = npos) const;
|
|
+
|
|
+ int compare(const StringPiece& x) const {
|
|
+ int r = memcmp(data_, x.data_, std::min(size_, x.size_));
|
|
+ if (r == 0) {
|
|
+ if (size_ < x.size_) r = -1;
|
|
+ else if (size_ > x.size_) r = +1;
|
|
+ }
|
|
+ return r;
|
|
}
|
|
- const_reverse_iterator rend() const {
|
|
- return const_reverse_iterator(ptr_);
|
|
+
|
|
+ // Does "this" start with "x"?
|
|
+ bool starts_with(const StringPiece& x) const {
|
|
+ return size_ >= x.size_ &&
|
|
+ memcmp(data_, x.data_, x.size_) == 0;
|
|
}
|
|
- // STLS says return size_type, but Google says return int
|
|
- int max_size() const { return length_; }
|
|
- int capacity() const { return length_; }
|
|
|
|
- size_type copy(char* buf, size_type n, size_type pos = 0) const;
|
|
+ // Does "this" end with "x"?
|
|
+ bool ends_with(const StringPiece& x) const {
|
|
+ return size_ >= x.size_ &&
|
|
+ memcmp(data_ + size_ - x.size_, x.data_, x.size_) == 0;
|
|
+ }
|
|
|
|
- bool contains(StringPiece s) const;
|
|
+ bool contains(const StringPiece& s) const {
|
|
+ return find(s) != npos;
|
|
+ }
|
|
|
|
size_type find(const StringPiece& s, size_type pos = 0) const;
|
|
size_type find(char c, size_type pos = 0) const;
|
|
size_type rfind(const StringPiece& s, size_type pos = npos) const;
|
|
size_type rfind(char c, size_type pos = npos) const;
|
|
|
|
- StringPiece substr(size_type pos, size_type n = npos) const;
|
|
-
|
|
- static bool _equal(const StringPiece&, const StringPiece&);
|
|
+ private:
|
|
+ const_pointer data_;
|
|
+ size_type size_;
|
|
};
|
|
|
|
inline bool operator==(const StringPiece& x, const StringPiece& y) {
|
|
- return StringPiece::_equal(x, y);
|
|
+ return x.size() == y.size() &&
|
|
+ memcmp(x.data(), y.data(), x.size()) == 0;
|
|
}
|
|
|
|
inline bool operator!=(const StringPiece& x, const StringPiece& y) {
|
|
@@ -160,8 +159,7 @@ inline bool operator!=(const StringPiece
|
|
}
|
|
|
|
inline bool operator<(const StringPiece& x, const StringPiece& y) {
|
|
- const int r = memcmp(x.data(), y.data(),
|
|
- std::min(x.size(), y.size()));
|
|
+ int r = memcmp(x.data(), y.data(), std::min(x.size(), y.size()));
|
|
return ((r < 0) || ((r == 0) && (x.size() < y.size())));
|
|
}
|
|
|
|
@@ -179,7 +177,7 @@ inline bool operator>=(const StringPiece
|
|
|
|
} // namespace re2
|
|
|
|
-// allow StringPiece to be logged
|
|
-extern std::ostream& operator<<(std::ostream& o, const re2::StringPiece& piece);
|
|
+// Allow StringPiece to be logged.
|
|
+std::ostream& operator<<(std::ostream& o, const re2::StringPiece& p);
|
|
|
|
-#endif // STRINGS_STRINGPIECE_H__
|
|
+#endif // RE2_STRINGPIECE_H_
|