7 |
<p> |
<p> |
8 |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |
9 |
</p> |
</p> |
10 |
<p> |
<p> |
11 |
This page is part of the PCRE HTML documentation. It was generated automatically |
This page is part of the PCRE HTML documentation. It was generated automatically |
12 |
from the original man page. If there is any nonsense in it, please consult the |
from the original man page. If there is any nonsense in it, please consult the |
13 |
man page, in case the conversion went wrong. |
man page, in case the conversion went wrong. |
14 |
<br> |
<br> |
15 |
<ul> |
<ul> |
16 |
<li><a name="TOC1" href="#SEC1">PCRE CALLOUTS</a> |
<li><a name="TOC1" href="#SEC1">PCRE CALLOUTS</a> |
17 |
<li><a name="TOC2" href="#SEC2">MISSING CALLOUTS</a> |
<li><a name="TOC2" href="#SEC2">MISSING CALLOUTS</a> |
37 |
a number less than 256 after the letter C. The default value is zero. |
a number less than 256 after the letter C. The default value is zero. |
38 |
For example, this pattern has two callout points: |
For example, this pattern has two callout points: |
39 |
<pre> |
<pre> |
40 |
(?C1)\deabc(?C2)def |
(?C1)abc(?C2)def |
41 |
</pre> |
</pre> |
42 |
If the PCRE_AUTO_CALLOUT option bit is set when <b>pcre_compile()</b> is called, |
If the PCRE_AUTO_CALLOUT option bit is set when <b>pcre_compile()</b> or |
43 |
PCRE automatically inserts callouts, all with number 255, before each item in |
<b>pcre_compile2()</b> is called, PCRE automatically inserts callouts, all with |
44 |
the pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern |
number 255, before each item in the pattern. For example, if PCRE_AUTO_CALLOUT |
45 |
|
is used with the pattern |
46 |
<pre> |
<pre> |
47 |
A(\d{2}|--) |
A(\d{2}|--) |
48 |
</pre> |
</pre> |
63 |
<br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br> |
<br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br> |
64 |
<P> |
<P> |
65 |
You should be aware that, because of optimizations in the way PCRE matches |
You should be aware that, because of optimizations in the way PCRE matches |
66 |
patterns, callouts sometimes do not happen. For example, if the pattern is |
patterns by default, callouts sometimes do not happen. For example, if the |
67 |
|
pattern is |
68 |
<pre> |
<pre> |
69 |
ab(?C4)cd |
ab(?C4)cd |
70 |
</pre> |
</pre> |
73 |
the callout is never reached. However, with "abyd", though the result is still |
the callout is never reached. However, with "abyd", though the result is still |
74 |
no match, the callout is obeyed. |
no match, the callout is obeyed. |
75 |
</P> |
</P> |
76 |
|
<P> |
77 |
|
If the pattern is studied, PCRE knows the minimum length of a matching string, |
78 |
|
and will immediately give a "no match" return without actually running a match |
79 |
|
if the subject is not long enough, or, for unanchored patterns, if it has |
80 |
|
been scanned far enough. |
81 |
|
</P> |
82 |
|
<P> |
83 |
|
You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE |
84 |
|
option to <b>pcre_compile()</b>, <b>pcre_exec()</b>, or <b>pcre_dfa_exec()</b>, |
85 |
|
or by starting the pattern with (*NO_START_OPT). This slows down the matching |
86 |
|
process, but does ensure that callouts such as the example above are obeyed. |
87 |
|
</P> |
88 |
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
89 |
<P> |
<P> |
90 |
During matching, when PCRE reaches a callout point, the external function |
During matching, when PCRE reaches a callout point, the external function |
93 |
only argument to the callout function is a pointer to a <b>pcre_callout</b> |
only argument to the callout function is a pointer to a <b>pcre_callout</b> |
94 |
block. This structure contains the following fields: |
block. This structure contains the following fields: |
95 |
<pre> |
<pre> |
96 |
int <i>version</i>; |
int <i>version</i>; |
97 |
int <i>callout_number</i>; |
int <i>callout_number</i>; |
98 |
int *<i>offset_vector</i>; |
int *<i>offset_vector</i>; |
99 |
const char *<i>subject</i>; |
const char *<i>subject</i>; |
100 |
int <i>subject_length</i>; |
int <i>subject_length</i>; |
101 |
int <i>start_match</i>; |
int <i>start_match</i>; |
102 |
int <i>current_position</i>; |
int <i>current_position</i>; |
103 |
int <i>capture_top</i>; |
int <i>capture_top</i>; |
104 |
int <i>capture_last</i>; |
int <i>capture_last</i>; |
105 |
void *<i>callout_data</i>; |
void *<i>callout_data</i>; |
106 |
int <i>pattern_position</i>; |
int <i>pattern_position</i>; |
107 |
int <i>next_item_length</i>; |
int <i>next_item_length</i>; |
108 |
|
const unsigned char *<i>mark</i>; |
109 |
</pre> |
</pre> |
110 |
The <i>version</i> field is an integer containing the version number of the |
The <i>version</i> field is an integer containing the version number of the |
111 |
block format. The initial version was 0; the current version is 1. The version |
block format. The initial version was 0; the current version is 2. The version |
112 |
number will change again in future if additional fields are added, but the |
number will change again in future if additional fields are added, but the |
113 |
intention is never to remove any of the existing fields. |
intention is never to remove any of the existing fields. |
114 |
</P> |
</P> |
130 |
that were passed to <b>pcre_exec()</b>. |
that were passed to <b>pcre_exec()</b>. |
131 |
</P> |
</P> |
132 |
<P> |
<P> |
133 |
The <i>start_match</i> field contains the offset within the subject at which the |
The <i>start_match</i> field normally contains the offset within the subject at |
134 |
current match attempt started. If the pattern is not anchored, the callout |
which the current match attempt started. However, if the escape sequence \K |
135 |
function may be called several times from the same point in the pattern for |
has been encountered, this value is changed to reflect the modified starting |
136 |
different starting points in the subject. |
point. If the pattern is not anchored, the callout function may be called |
137 |
|
several times from the same point in the pattern for different starting points |
138 |
|
in the subject. |
139 |
</P> |
</P> |
140 |
<P> |
<P> |
141 |
The <i>current_position</i> field contains the offset within the subject of the |
The <i>current_position</i> field contains the offset within the subject of the |
181 |
help in distinguishing between different automatic callouts, which all have the |
help in distinguishing between different automatic callouts, which all have the |
182 |
same callout number. However, they are set for all callouts. |
same callout number. However, they are set for all callouts. |
183 |
</P> |
</P> |
184 |
|
<P> |
185 |
|
The <i>mark</i> field is present from version 2 of the <i>pcre_callout</i> |
186 |
|
structure. In callouts from <b>pcre_exec()</b> it contains a pointer to the |
187 |
|
zero-terminated name of the most recently passed (*MARK) item in the match, or |
188 |
|
NULL if there are no (*MARK)s in the current matching path. In callouts from |
189 |
|
<b>pcre_dfa_exec()</b> this field always contains NULL. |
190 |
|
</P> |
191 |
<br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br> |
<br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br> |
192 |
<P> |
<P> |
193 |
The external callout function returns an integer to PCRE. If the value is zero, |
The external callout function returns an integer to PCRE. If the value is zero, |
194 |
matching proceeds as normal. If the value is greater than zero, matching fails |
matching proceeds as normal. If the value is greater than zero, matching fails |
195 |
at the current point, but the testing of other matching possibilities goes |
at the current point, but the testing of other matching possibilities goes |
196 |
ahead, just as if a lookahead assertion had failed. If the value is less than |
ahead, just as if a lookahead assertion had failed. If the value is less than |
197 |
zero, the match is abandoned, and <b>pcre_exec()</b> (or <b>pcre_dfa_exec()</b>) |
zero, the match is abandoned, and <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> |
198 |
returns the negative value. |
returns the negative value. |
199 |
</P> |
</P> |
200 |
<P> |
<P> |
214 |
</P> |
</P> |
215 |
<br><a name="SEC6" href="#TOC1">REVISION</a><br> |
<br><a name="SEC6" href="#TOC1">REVISION</a><br> |
216 |
<P> |
<P> |
217 |
Last updated: 06 March 2007 |
Last updated: 31 July 2011 |
218 |
<br> |
<br> |
219 |
Copyright © 1997-2007 University of Cambridge. |
Copyright © 1997-2011 University of Cambridge. |
220 |
<br> |
<br> |
221 |
<p> |
<p> |
222 |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |