| 944 |
size_t size, regex_gotten_store; |
size_t size, regex_gotten_store; |
| 945 |
int do_study = 0; |
int do_study = 0; |
| 946 |
int do_debug = debug; |
int do_debug = debug; |
| 947 |
int debug_lengths = 1; |
int debug_lengths = 1; |
| 948 |
int do_G = 0; |
int do_G = 0; |
| 949 |
int do_g = 0; |
int do_g = 0; |
| 950 |
int do_showinfo = showinfo; |
int do_showinfo = showinfo; |
| 1135 |
case 'S': do_study = 1; break; |
case 'S': do_study = 1; break; |
| 1136 |
case 'U': options |= PCRE_UNGREEDY; break; |
case 'U': options |= PCRE_UNGREEDY; break; |
| 1137 |
case 'X': options |= PCRE_EXTRA; break; |
case 'X': options |= PCRE_EXTRA; break; |
| 1138 |
case 'Z': debug_lengths = 0; |
case 'Z': debug_lengths = 0; break; |
| 1139 |
case '8': options |= PCRE_UTF8; use_utf8 = 1; break; |
case '8': options |= PCRE_UTF8; use_utf8 = 1; break; |
| 1140 |
case '?': options |= PCRE_NO_UTF8_CHECK; break; |
case '?': options |= PCRE_NO_UTF8_CHECK; break; |
| 1141 |
|
|
| 1972 |
|
|
| 1973 |
for (;; gmatched++) /* Loop for /g or /G */ |
for (;; gmatched++) /* Loop for /g or /G */ |
| 1974 |
{ |
{ |
| 1975 |
|
int gany_fudge; |
| 1976 |
if (timeitm > 0) |
if (timeitm > 0) |
| 1977 |
{ |
{ |
| 1978 |
register int i; |
register int i; |
| 2256 |
what Perl's /g options does. This turns out to be rather cunning. First |
what Perl's /g options does. This turns out to be rather cunning. First |
| 2257 |
we set PCRE_NOTEMPTY and PCRE_ANCHORED and try the match again at the |
we set PCRE_NOTEMPTY and PCRE_ANCHORED and try the match again at the |
| 2258 |
same point. If this fails (picked up above) we advance to the next |
same point. If this fails (picked up above) we advance to the next |
| 2259 |
character. */ |
character. |
| 2260 |
|
|
| 2261 |
|
Yet more complication arises in the case when the newline option is |
| 2262 |
|
"any" and a pattern in multiline mode has to match at the start of a |
| 2263 |
|
line. If a previous match was at the end of a line, and advance of one |
| 2264 |
|
character just passes the \r, whereas we should prefer the longer newline |
| 2265 |
|
sequence, as does the code in pcre_exec(). So we fudge it. */ |
| 2266 |
|
|
| 2267 |
g_notempty = 0; |
g_notempty = 0; |
| 2268 |
|
gany_fudge = 0; |
| 2269 |
|
|
| 2270 |
if (use_offsets[0] == use_offsets[1]) |
if (use_offsets[0] == use_offsets[1]) |
| 2271 |
{ |
{ |
| 2272 |
if (use_offsets[0] == len) break; |
if (use_offsets[0] == len) break; |
| 2273 |
g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED; |
g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED; |
| 2274 |
|
if ((((real_pcre *)re)->options & PCRE_STARTLINE) != 0 && |
| 2275 |
|
(((real_pcre *)re)->options & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY && |
| 2276 |
|
use_offsets[0] < len - 1 && |
| 2277 |
|
bptr[use_offsets[0]] == '\r' && |
| 2278 |
|
bptr[use_offsets[0]+1] == '\n') |
| 2279 |
|
gany_fudge = 1; |
| 2280 |
} |
} |
| 2281 |
|
|
| 2282 |
/* For /g, update the start offset, leaving the rest alone */ |
/* For /g, update the start offset, leaving the rest alone */ |
| 2283 |
|
|
| 2284 |
if (do_g) start_offset = use_offsets[1]; |
if (do_g) start_offset = use_offsets[1] + gany_fudge; |
| 2285 |
|
|
| 2286 |
/* For /G, update the pointer and length */ |
/* For /G, update the pointer and length */ |
| 2287 |
|
|
| 2288 |
else |
else |
| 2289 |
{ |
{ |
| 2290 |
bptr += use_offsets[1]; |
bptr += use_offsets[1] + gany_fudge; |
| 2291 |
len -= use_offsets[1]; |
len -= use_offsets[1] + gany_fudge; |
| 2292 |
} |
} |
| 2293 |
} /* End of loop for /g and /G */ |
} /* End of loop for /g and /G */ |
| 2294 |
|
|