17 |
<li><a name="TOC2" href="#SEC2">MISSING CALLOUTS</a> |
<li><a name="TOC2" href="#SEC2">MISSING CALLOUTS</a> |
18 |
<li><a name="TOC3" href="#SEC3">THE CALLOUT INTERFACE</a> |
<li><a name="TOC3" href="#SEC3">THE CALLOUT INTERFACE</a> |
19 |
<li><a name="TOC4" href="#SEC4">RETURN VALUES</a> |
<li><a name="TOC4" href="#SEC4">RETURN VALUES</a> |
20 |
|
<li><a name="TOC5" href="#SEC5">AUTHOR</a> |
21 |
|
<li><a name="TOC6" href="#SEC6">REVISION</a> |
22 |
</ul> |
</ul> |
23 |
<br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br> |
<br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br> |
24 |
<P> |
<P> |
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> |
60 |
indicates how the pattern is matched. This is useful information when you are |
indicates how the pattern is matched. This is useful information when you are |
61 |
trying to optimize the performance of a particular pattern. |
trying to optimize the performance of a particular pattern. |
62 |
</P> |
</P> |
63 |
|
<P> |
64 |
|
The use of callouts in a pattern makes it ineligible for optimization by the |
65 |
|
just-in-time compiler. Studying such a pattern with the PCRE_STUDY_JIT_COMPILE |
66 |
|
option always fails. |
67 |
|
</P> |
68 |
<br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br> |
<br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br> |
69 |
<P> |
<P> |
70 |
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 |
71 |
patterns, callouts sometimes do not happen. For example, if the pattern is |
patterns by default, callouts sometimes do not happen. For example, if the |
72 |
|
pattern is |
73 |
<pre> |
<pre> |
74 |
ab(?C4)cd |
ab(?C4)cd |
75 |
</pre> |
</pre> |
78 |
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 |
79 |
no match, the callout is obeyed. |
no match, the callout is obeyed. |
80 |
</P> |
</P> |
81 |
|
<P> |
82 |
|
If the pattern is studied, PCRE knows the minimum length of a matching string, |
83 |
|
and will immediately give a "no match" return without actually running a match |
84 |
|
if the subject is not long enough, or, for unanchored patterns, if it has |
85 |
|
been scanned far enough. |
86 |
|
</P> |
87 |
|
<P> |
88 |
|
You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE |
89 |
|
option to <b>pcre_compile()</b>, <b>pcre_exec()</b>, or <b>pcre_dfa_exec()</b>, |
90 |
|
or by starting the pattern with (*NO_START_OPT). This slows down the matching |
91 |
|
process, but does ensure that callouts such as the example above are obeyed. |
92 |
|
</P> |
93 |
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
94 |
<P> |
<P> |
95 |
During matching, when PCRE reaches a callout point, the external function |
During matching, when PCRE reaches a callout point, the external function |
96 |
defined by <i>pcre_callout</i> is called (if it is set). The only argument is a |
defined by <i>pcre_callout</i> is called (if it is set). This applies to both |
97 |
pointer to a <b>pcre_callout</b> block. This structure contains the following |
the <b>pcre_exec()</b> and the <b>pcre_dfa_exec()</b> matching functions. The |
98 |
fields: |
only argument to the callout function is a pointer to a <b>pcre_callout</b> |
99 |
|
block. This structure contains the following fields: |
100 |
<pre> |
<pre> |
101 |
int <i>version</i>; |
int <i>version</i>; |
102 |
int <i>callout_number</i>; |
int <i>callout_number</i>; |
103 |
int *<i>offset_vector</i>; |
int *<i>offset_vector</i>; |
104 |
const char *<i>subject</i>; |
const char *<i>subject</i>; |
105 |
int <i>subject_length</i>; |
int <i>subject_length</i>; |
106 |
int <i>start_match</i>; |
int <i>start_match</i>; |
107 |
int <i>current_position</i>; |
int <i>current_position</i>; |
108 |
int <i>capture_top</i>; |
int <i>capture_top</i>; |
109 |
int <i>capture_last</i>; |
int <i>capture_last</i>; |
110 |
void *<i>callout_data</i>; |
void *<i>callout_data</i>; |
111 |
int <i>pattern_position</i>; |
int <i>pattern_position</i>; |
112 |
int <i>next_item_length</i>; |
int <i>next_item_length</i>; |
113 |
|
const unsigned char *<i>mark</i>; |
114 |
</pre> |
</pre> |
115 |
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 |
116 |
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 |
117 |
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 |
118 |
intention is never to remove any of the existing fields. |
intention is never to remove any of the existing fields. |
119 |
</P> |
</P> |
124 |
</P> |
</P> |
125 |
<P> |
<P> |
126 |
The <i>offset_vector</i> field is a pointer to the vector of offsets that was |
The <i>offset_vector</i> field is a pointer to the vector of offsets that was |
127 |
passed by the caller to <b>pcre_exec()</b>. The contents can be inspected in |
passed by the caller to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. When |
128 |
order to extract substrings that have been matched so far, in the same way as |
<b>pcre_exec()</b> is used, the contents can be inspected in order to extract |
129 |
for extracting substrings after a match has completed. |
substrings that have been matched so far, in the same way as for extracting |
130 |
|
substrings after a match has completed. For <b>pcre_dfa_exec()</b> this field is |
131 |
|
not useful. |
132 |
</P> |
</P> |
133 |
<P> |
<P> |
134 |
The <i>subject</i> and <i>subject_length</i> fields contain copies of the values |
The <i>subject</i> and <i>subject_length</i> fields contain copies of the values |
135 |
that were passed to <b>pcre_exec()</b>. |
that were passed to <b>pcre_exec()</b>. |
136 |
</P> |
</P> |
137 |
<P> |
<P> |
138 |
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 |
139 |
current match attempt started. If the pattern is not anchored, the callout |
which the current match attempt started. However, if the escape sequence \K |
140 |
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 |
141 |
different starting points in the subject. |
point. If the pattern is not anchored, the callout function may be called |
142 |
|
several times from the same point in the pattern for different starting points |
143 |
|
in the subject. |
144 |
</P> |
</P> |
145 |
<P> |
<P> |
146 |
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 |
147 |
current match pointer. |
current match pointer. |
148 |
</P> |
</P> |
149 |
<P> |
<P> |
150 |
The <i>capture_top</i> field contains one more than the number of the highest |
When the <b>pcre_exec()</b> function is used, the <i>capture_top</i> field |
151 |
numbered captured substring so far. If no substrings have been captured, |
contains one more than the number of the highest numbered captured substring so |
152 |
the value of <i>capture_top</i> is one. |
far. If no substrings have been captured, the value of <i>capture_top</i> is |
153 |
|
one. This is always the case when <b>pcre_dfa_exec()</b> is used, because it |
154 |
|
does not support captured substrings. |
155 |
</P> |
</P> |
156 |
<P> |
<P> |
157 |
The <i>capture_last</i> field contains the number of the most recently captured |
The <i>capture_last</i> field contains the number of the most recently captured |
158 |
substring. If no substrings have been captured, its value is -1. |
substring. If no substrings have been captured, its value is -1. This is always |
159 |
|
the case when <b>pcre_dfa_exec()</b> is used. |
160 |
</P> |
</P> |
161 |
<P> |
<P> |
162 |
The <i>callout_data</i> field contains a value that is passed to |
The <i>callout_data</i> field contains a value that is passed to |
163 |
<b>pcre_exec()</b> by the caller specifically so that it can be passed back in |
<b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> specifically so that it can be |
164 |
callouts. It is passed in the <i>pcre_callout</i> field of the <b>pcre_extra</b> |
passed back in callouts. It is passed in the <i>pcre_callout</i> field of the |
165 |
data structure. If no such data was passed, the value of <i>callout_data</i> in |
<b>pcre_extra</b> data structure. If no such data was passed, the value of |
166 |
a <b>pcre_callout</b> block is NULL. There is a description of the |
<i>callout_data</i> in a <b>pcre_callout</b> block is NULL. There is a |
167 |
<b>pcre_extra</b> structure in the |
description of the <b>pcre_extra</b> structure in the |
168 |
<a href="pcreapi.html"><b>pcreapi</b></a> |
<a href="pcreapi.html"><b>pcreapi</b></a> |
169 |
documentation. |
documentation. |
170 |
</P> |
</P> |
186 |
help in distinguishing between different automatic callouts, which all have the |
help in distinguishing between different automatic callouts, which all have the |
187 |
same callout number. However, they are set for all callouts. |
same callout number. However, they are set for all callouts. |
188 |
</P> |
</P> |
189 |
|
<P> |
190 |
|
The <i>mark</i> field is present from version 2 of the <i>pcre_callout</i> |
191 |
|
structure. In callouts from <b>pcre_exec()</b> it contains a pointer to the |
192 |
|
zero-terminated name of the most recently passed (*MARK) item in the match, or |
193 |
|
NULL if there are no (*MARK)s in the current matching path. In callouts from |
194 |
|
<b>pcre_dfa_exec()</b> this field always contains NULL. |
195 |
|
</P> |
196 |
<br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br> |
<br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br> |
197 |
<P> |
<P> |
198 |
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, |
199 |
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 |
200 |
at the current point, but backtracking to test other matching possibilities |
at the current point, but the testing of other matching possibilities goes |
201 |
goes ahead, just as if a lookahead assertion had failed. If the value is less |
ahead, just as if a lookahead assertion had failed. If the value is less than |
202 |
than zero, the match is abandoned, and <b>pcre_exec()</b> returns the negative |
zero, the match is abandoned, and <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> |
203 |
value. |
returns the negative value. |
204 |
</P> |
</P> |
205 |
<P> |
<P> |
206 |
Negative values should normally be chosen from the set of PCRE_ERROR_xxx |
Negative values should normally be chosen from the set of PCRE_ERROR_xxx |
208 |
The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions; |
The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions; |
209 |
it will never be used by PCRE itself. |
it will never be used by PCRE itself. |
210 |
</P> |
</P> |
211 |
|
<br><a name="SEC5" href="#TOC1">AUTHOR</a><br> |
212 |
<P> |
<P> |
213 |
Last updated: 09 September 2004 |
Philip Hazel |
214 |
|
<br> |
215 |
|
University Computing Service |
216 |
|
<br> |
217 |
|
Cambridge CB2 3QH, England. |
218 |
|
<br> |
219 |
|
</P> |
220 |
|
<br><a name="SEC6" href="#TOC1">REVISION</a><br> |
221 |
|
<P> |
222 |
|
Last updated: 26 August 2011 |
223 |
|
<br> |
224 |
|
Copyright © 1997-2011 University of Cambridge. |
225 |
<br> |
<br> |
|
Copyright © 1997-2004 University of Cambridge. |
|
226 |
<p> |
<p> |
227 |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |
228 |
</p> |
</p> |