| 112 |
// T (where "bool T::ParseFrom(const char*, int)" exists) |
// T (where "bool T::ParseFrom(const char*, int)" exists) |
| 113 |
// NULL (the corresponding matched sub-pattern is not copied) |
// NULL (the corresponding matched sub-pattern is not copied) |
| 114 |
// |
// |
| 115 |
|
// CAVEAT: An optional sub-pattern that does not exist in the matched |
| 116 |
|
// string is assigned the empty string. Therefore, the following will |
| 117 |
|
// return false (because the empty string is not a valid number): |
| 118 |
|
// int number; |
| 119 |
|
// pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number); |
| 120 |
|
// |
| 121 |
// ----------------------------------------------------------------------- |
// ----------------------------------------------------------------------- |
| 122 |
// DO_MATCH |
// DO_MATCH |
| 123 |
// |
// |
| 494 |
// pass in a string or a "const char*" wherever an "RE" is expected. |
// pass in a string or a "const char*" wherever an "RE" is expected. |
| 495 |
RE(const char* pat) { Init(pat, NULL); } |
RE(const char* pat) { Init(pat, NULL); } |
| 496 |
RE(const char *pat, const RE_Options& option) { Init(pat, &option); } |
RE(const char *pat, const RE_Options& option) { Init(pat, &option); } |
| 497 |
RE(const string& pat) { Init(pat.c_str(), NULL); } |
RE(const string& pat) { Init(pat, NULL); } |
| 498 |
RE(const string& pat, const RE_Options& option) { Init(pat.c_str(), &option); } |
RE(const string& pat, const RE_Options& option) { Init(pat, &option); } |
| 499 |
|
|
| 500 |
|
// Copy constructor & assignment - note that these are expensive |
| 501 |
|
// because they recompile the expression. |
| 502 |
|
RE(const RE& re) { Init(re.pattern_, &re.options_); } |
| 503 |
|
const RE& operator=(const RE& re) { |
| 504 |
|
if (this != &re) { |
| 505 |
|
Cleanup(); |
| 506 |
|
|
| 507 |
|
// This is the code that originally came from Google |
| 508 |
|
// Init(re.pattern_.c_str(), &re.options_); |
| 509 |
|
|
| 510 |
|
// This is the replacement from Ari Pollak |
| 511 |
|
Init(re.pattern_, &re.options_); |
| 512 |
|
} |
| 513 |
|
return *this; |
| 514 |
|
} |
| 515 |
|
|
| 516 |
|
|
| 517 |
~RE(); |
~RE(); |
| 518 |
|
|
| 612 |
const StringPiece &text, |
const StringPiece &text, |
| 613 |
string *out) const; |
string *out) const; |
| 614 |
|
|
| 615 |
|
// Escapes all potentially meaningful regexp characters in |
| 616 |
|
// 'unquoted'. The returned string, used as a regular expression, |
| 617 |
|
// will exactly match the original string. For example, |
| 618 |
|
// 1.5-2.0? |
| 619 |
|
// may become: |
| 620 |
|
// 1\.5\-2\.0\? |
| 621 |
|
static string QuoteMeta(const StringPiece& unquoted); |
| 622 |
|
|
| 623 |
|
|
| 624 |
/***** Generic matching interface *****/ |
/***** Generic matching interface *****/ |
| 625 |
|
|
| 626 |
// Type of match (TODO: Should be restructured as part of RE_Options) |
// Type of match (TODO: Should be restructured as part of RE_Options) |
| 643 |
|
|
| 644 |
private: |
private: |
| 645 |
|
|
| 646 |
void Init(const char* pattern, const RE_Options* options); |
void Init(const string& pattern, const RE_Options* options); |
| 647 |
|
void Cleanup(); |
| 648 |
|
|
| 649 |
// Match against "text", filling in "vec" (up to "vecsize" * 2/3) with |
// Match against "text", filling in "vec" (up to "vecsize" * 2/3) with |
| 650 |
// pairs of integers for the beginning and end positions of matched |
// pairs of integers for the beginning and end positions of matched |
| 688 |
pcre* re_full_; // For full matches |
pcre* re_full_; // For full matches |
| 689 |
pcre* re_partial_; // For partial matches |
pcre* re_partial_; // For partial matches |
| 690 |
const string* error_; // Error indicator (or points to empty string) |
const string* error_; // Error indicator (or points to empty string) |
|
|
|
|
// Don't allow the default copy or assignment constructors -- |
|
|
// they're expensive and too easy to do by accident. |
|
|
RE(const RE&); |
|
|
void operator=(const RE&); |
|
| 691 |
}; |
}; |
| 692 |
|
|
| 693 |
} // namespace pcrecpp |
} // namespace pcrecpp |