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 |
|
|