| 36 |
#include <assert.h> |
#include <assert.h> |
| 37 |
#include <errno.h> |
#include <errno.h> |
| 38 |
#include <string> |
#include <string> |
| 39 |
|
#include <algorithm> |
| 40 |
#include "config.h" |
#include "config.h" |
| 41 |
// We need this to compile the proper dll on windows/msys. This is copied |
// We need this to compile the proper dll on windows/msys. This is copied |
| 42 |
// from pcre_internal.h. It would probably be better just to include that. |
// from pcre_internal.h. It would probably be better just to include that. |
| 98 |
pcre* RE::Compile(Anchor anchor) { |
pcre* RE::Compile(Anchor anchor) { |
| 99 |
// First, convert RE_Options into pcre options |
// First, convert RE_Options into pcre options |
| 100 |
int pcre_options = 0; |
int pcre_options = 0; |
| 101 |
if (options_.utf8()) |
pcre_options = options_.all_options(); |
|
pcre_options |= PCRE_UTF8; |
|
| 102 |
|
|
| 103 |
// Special treatment for anchoring. This is needed because at |
// Special treatment for anchoring. This is needed because at |
| 104 |
// runtime pcre only provides an option for anchoring at the |
// runtime pcre only provides an option for anchoring at the |
| 378 |
int matches = TryMatch(text, 0, UNANCHORED, vec, kVecSize); |
int matches = TryMatch(text, 0, UNANCHORED, vec, kVecSize); |
| 379 |
if (matches == 0) |
if (matches == 0) |
| 380 |
return false; |
return false; |
| 381 |
out->clear(); |
out->erase(); |
| 382 |
return Rewrite(out, rewrite, text, vec, matches); |
return Rewrite(out, rewrite, text, vec, matches); |
| 383 |
} |
} |
| 384 |
|
|
| 397 |
|
|
| 398 |
pcre_extra extra = { 0 }; |
pcre_extra extra = { 0 }; |
| 399 |
if (options_.match_limit() > 0) { |
if (options_.match_limit() > 0) { |
| 400 |
extra.flags = PCRE_EXTRA_MATCH_LIMIT; |
extra.flags |= PCRE_EXTRA_MATCH_LIMIT; |
| 401 |
extra.match_limit = options_.match_limit(); |
extra.match_limit = options_.match_limit(); |
| 402 |
} |
} |
| 403 |
|
if (options_.match_limit_recursion() > 0) { |
| 404 |
|
extra.flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; |
| 405 |
|
extra.match_limit_recursion = options_.match_limit_recursion(); |
| 406 |
|
} |
| 407 |
int rc = pcre_exec(re, // The regular expression object |
int rc = pcre_exec(re, // The regular expression object |
| 408 |
&extra, |
&extra, |
| 409 |
text.data(), |
(text.data() == NULL) ? "" : text.data(), |
| 410 |
text.size(), |
text.size(), |
| 411 |
startpos, |
startpos, |
| 412 |
(anchor == UNANCHORED) ? 0 : PCRE_ANCHORED, |
(anchor == UNANCHORED) ? 0 : PCRE_ANCHORED, |
| 453 |
|
|
| 454 |
*consumed = vec[1]; |
*consumed = vec[1]; |
| 455 |
|
|
| 456 |
if (args == NULL) { |
if (n == 0 || args == NULL) { |
| 457 |
// We are not interested in results |
// We are not interested in results |
| 458 |
return true; |
return true; |
| 459 |
} |
} |
| 460 |
|
|
| 461 |
|
if (NumberOfCapturingGroups() < n) { |
| 462 |
|
// RE has fewer capturing groups than number of arg pointers passed in |
| 463 |
|
return false; |
| 464 |
|
} |
| 465 |
|
|
| 466 |
// If we got here, we must have matched the whole pattern. |
// If we got here, we must have matched the whole pattern. |
| 467 |
// We do not need (can not do) any more checks on the value of 'matches' here |
// We do not need (can not do) any more checks on the value of 'matches' here |
| 468 |
// -- see the comment for TryMatch. |
// -- see the comment for TryMatch. |
| 526 |
|
|
| 527 |
// Return the number of capturing subpatterns, or -1 if the |
// Return the number of capturing subpatterns, or -1 if the |
| 528 |
// regexp wasn't valid on construction. |
// regexp wasn't valid on construction. |
| 529 |
int RE::NumberOfCapturingGroups() { |
int RE::NumberOfCapturingGroups() const { |
| 530 |
if (re_partial_ == NULL) return -1; |
if (re_partial_ == NULL) return -1; |
| 531 |
|
|
| 532 |
int result; |
int result; |
| 622 |
if (n == 0) return false; |
if (n == 0) return false; |
| 623 |
char buf[kMaxNumberLength+1]; |
char buf[kMaxNumberLength+1]; |
| 624 |
str = TerminateNumber(buf, str, n); |
str = TerminateNumber(buf, str, n); |
| 625 |
|
if (str[0] == '-') return false; // strtoul() on a negative number?! |
| 626 |
char* end; |
char* end; |
| 627 |
errno = 0; |
errno = 0; |
| 628 |
unsigned long r = strtoul(str, &end, radix); |
unsigned long r = strtoul(str, &end, radix); |
| 712 |
if (n == 0) return false; |
if (n == 0) return false; |
| 713 |
char buf[kMaxNumberLength+1]; |
char buf[kMaxNumberLength+1]; |
| 714 |
str = TerminateNumber(buf, str, n); |
str = TerminateNumber(buf, str, n); |
| 715 |
|
if (str[0] == '-') return false; // strtoull() on a negative number?! |
| 716 |
char* end; |
char* end; |
| 717 |
errno = 0; |
errno = 0; |
| 718 |
#if defined HAVE_STRTOQ |
#if defined HAVE_STRTOQ |