OLD | NEW |
1 // Copyright 2003-2010 Google Inc. All Rights Reserved. | 1 // Copyright 2003-2010 Google Inc. All Rights Reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This is a variant of PCRE's pcrecpp.h, originally written at Google. | 5 // This is a variant of PCRE's pcrecpp.h, originally written at Google. |
6 // The main changes are the addition of the HitLimit method and | 6 // The main changes are the addition of the HitLimit method and |
7 // compilation as PCRE in namespace re2. | 7 // compilation as PCRE in namespace re2. |
8 | 8 |
9 // C++ interface to the pcre regular-expression library. PCRE supports | 9 // C++ interface to the pcre regular-expression library. PCRE supports |
10 // Perl-style regular expressions (with extensions like \d, \w, \s, | 10 // Perl-style regular expressions (with extensions like \d, \w, \s, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 #include "util/util.h" | 161 #include "util/util.h" |
162 #include "re2/stringpiece.h" | 162 #include "re2/stringpiece.h" |
163 | 163 |
164 #ifdef USEPCRE | 164 #ifdef USEPCRE |
165 #include <pcre.h> | 165 #include <pcre.h> |
166 namespace re2 { | 166 namespace re2 { |
167 const bool UsingPCRE = true; | 167 const bool UsingPCRE = true; |
168 } // namespace re2 | 168 } // namespace re2 |
169 #else | 169 #else |
| 170 struct pcre; // opaque |
170 namespace re2 { | 171 namespace re2 { |
171 const bool UsingPCRE = false; | 172 const bool UsingPCRE = false; |
172 struct pcre; | |
173 struct pcre_extra { int flags, match_limit, match_limit_recursion; }; | |
174 #define pcre_free(x) {} | |
175 #define PCRE_EXTRA_MATCH_LIMIT 0 | |
176 #define PCRE_EXTRA_MATCH_LIMIT_RECURSION 0 | |
177 #define PCRE_ANCHORED 0 | |
178 #define PCRE_NOTEMPTY 0 | |
179 #define PCRE_ERROR_NOMATCH 1 | |
180 #define PCRE_ERROR_MATCHLIMIT 2 | |
181 #define PCRE_ERROR_RECURSIONLIMIT 3 | |
182 #define PCRE_INFO_CAPTURECOUNT 0 | |
183 #ifndef WIN32 | |
184 #define pcre_compile(a,b,c,d,e) ({ (void)(a); (void)(b); *(c)=""; *(d)=0; (void)
(e); ((pcre*)0); }) | |
185 #define pcre_exec(a, b, c, d, e, f, g, h) ({ (void)(a); (void)(b); (void)(c); (v
oid)(d); (void)(e); (void)(f); (void)(g); (void)(h); 0; }) | |
186 #define pcre_fullinfo(a, b, c, d) ({ (void)(a); (void)(b); (void)(c); *(d) = 0;
0; }) | |
187 #else | |
188 #define pcre_compile(a,b,c,d,e) NULL | |
189 #define pcre_exec(a, b, c, d, e, f, g, h) NULL | |
190 #define pcre_fullinfo(a, b, c, d) NULL | |
191 #endif | |
192 } // namespace re2 | 173 } // namespace re2 |
193 #endif | 174 #endif |
194 | 175 |
195 namespace re2 { | 176 namespace re2 { |
196 | 177 |
197 class PCRE_Options; | 178 class PCRE_Options; |
198 | 179 |
199 // Interface for regular expression matching. Also corresponds to a | 180 // Interface for regular expression matching. Also corresponds to a |
200 // pre-compiled regular expression. An "PCRE" object is safe for | 181 // pre-compiled regular expression. An "PCRE" object is safe for |
201 // concurrent use by multiple threads. | 182 // concurrent use by multiple threads. |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 490 |
510 string pattern_; | 491 string pattern_; |
511 Option options_; | 492 Option options_; |
512 pcre* re_full_; // For full matches | 493 pcre* re_full_; // For full matches |
513 pcre* re_partial_; // For partial matches | 494 pcre* re_partial_; // For partial matches |
514 const string* error_; // Error indicator (or empty string) | 495 const string* error_; // Error indicator (or empty string) |
515 bool report_errors_; // Silences error logging if false | 496 bool report_errors_; // Silences error logging if false |
516 int match_limit_; // Limit on execution resources | 497 int match_limit_; // Limit on execution resources |
517 int stack_limit_; // Limit on stack resources (bytes) | 498 int stack_limit_; // Limit on stack resources (bytes) |
518 mutable int32_t hit_limit_; // Hit limit during execution (bool)? | 499 mutable int32_t hit_limit_; // Hit limit during execution (bool)? |
519 DISALLOW_EVIL_CONSTRUCTORS(PCRE); | 500 DISALLOW_COPY_AND_ASSIGN(PCRE); |
520 }; | 501 }; |
521 | 502 |
522 // PCRE_Options allow you to set the PCRE::Options, plus any pcre | 503 // PCRE_Options allow you to set the PCRE::Options, plus any pcre |
523 // "extra" options. The only extras are match_limit, which limits | 504 // "extra" options. The only extras are match_limit, which limits |
524 // the CPU time of a match, and stack_limit, which limits the | 505 // the CPU time of a match, and stack_limit, which limits the |
525 // stack usage. Setting a limit to <= 0 lets PCRE pick a sensible default | 506 // stack usage. Setting a limit to <= 0 lets PCRE pick a sensible default |
526 // that should not cause too many problems in production code. | 507 // that should not cause too many problems in production code. |
527 // If PCRE hits a limit during a match, it may return a false negative, | 508 // If PCRE hits a limit during a match, it may return a false negative, |
528 // but (hopefully) it won't crash. | 509 // but (hopefully) it won't crash. |
529 // | 510 // |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 MAKE_INTEGER_PARSER(int, int); | 657 MAKE_INTEGER_PARSER(int, int); |
677 MAKE_INTEGER_PARSER(unsigned int, uint); | 658 MAKE_INTEGER_PARSER(unsigned int, uint); |
678 MAKE_INTEGER_PARSER(long, long); | 659 MAKE_INTEGER_PARSER(long, long); |
679 MAKE_INTEGER_PARSER(unsigned long, ulong); | 660 MAKE_INTEGER_PARSER(unsigned long, ulong); |
680 MAKE_INTEGER_PARSER(long long, longlong); | 661 MAKE_INTEGER_PARSER(long long, longlong); |
681 MAKE_INTEGER_PARSER(unsigned long long, ulonglong); | 662 MAKE_INTEGER_PARSER(unsigned long long, ulonglong); |
682 | 663 |
683 #undef MAKE_INTEGER_PARSER | 664 #undef MAKE_INTEGER_PARSER |
684 | 665 |
685 } // namespace re2 | 666 } // namespace re2 |
OLD | NEW |