1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
|
--- 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_
|