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> is called, |
43 |
PCRE automatically inserts callouts, all with number 255, before each item in |
PCRE automatically inserts callouts, all with number 255, before each item in |
74 |
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
75 |
<P> |
<P> |
76 |
During matching, when PCRE reaches a callout point, the external function |
During matching, when PCRE reaches a callout point, the external function |
77 |
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 |
78 |
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 |
79 |
fields: |
only argument to the callout function is a pointer to a <b>pcre_callout</b> |
80 |
|
block. This structure contains the following fields: |
81 |
<pre> |
<pre> |
82 |
int <i>version</i>; |
int <i>version</i>; |
83 |
int <i>callout_number</i>; |
int <i>callout_number</i>; |
104 |
</P> |
</P> |
105 |
<P> |
<P> |
106 |
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 |
107 |
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 |
108 |
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 |
109 |
for extracting substrings after a match has completed. |
substrings that have been matched so far, in the same way as for extracting |
110 |
|
substrings after a match has completed. For <b>pcre_dfa_exec()</b> this field is |
111 |
|
not useful. |
112 |
</P> |
</P> |
113 |
<P> |
<P> |
114 |
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 |
115 |
that were passed to <b>pcre_exec()</b>. |
that were passed to <b>pcre_exec()</b>. |
116 |
</P> |
</P> |
117 |
<P> |
<P> |
118 |
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 |
119 |
current match attempt started. If the pattern is not anchored, the callout |
which the current match attempt started. However, if the escape sequence \K |
120 |
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 |
121 |
different starting points in the subject. |
point. If the pattern is not anchored, the callout function may be called |
122 |
|
several times from the same point in the pattern for different starting points |
123 |
|
in the subject. |
124 |
</P> |
</P> |
125 |
<P> |
<P> |
126 |
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 |
127 |
current match pointer. |
current match pointer. |
128 |
</P> |
</P> |
129 |
<P> |
<P> |
130 |
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 |
131 |
numbered captured substring so far. If no substrings have been captured, |
contains one more than the number of the highest numbered captured substring so |
132 |
the value of <i>capture_top</i> is one. |
far. If no substrings have been captured, the value of <i>capture_top</i> is |
133 |
|
one. This is always the case when <b>pcre_dfa_exec()</b> is used, because it |
134 |
|
does not support captured substrings. |
135 |
</P> |
</P> |
136 |
<P> |
<P> |
137 |
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 |
138 |
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 |
139 |
|
the case when <b>pcre_dfa_exec()</b> is used. |
140 |
</P> |
</P> |
141 |
<P> |
<P> |
142 |
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 |
143 |
<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 |
144 |
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 |
145 |
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 |
146 |
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 |
147 |
<b>pcre_extra</b> structure in the |
description of the <b>pcre_extra</b> structure in the |
148 |
<a href="pcreapi.html"><b>pcreapi</b></a> |
<a href="pcreapi.html"><b>pcreapi</b></a> |
149 |
documentation. |
documentation. |
150 |
</P> |
</P> |
170 |
<P> |
<P> |
171 |
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, |
172 |
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 |
173 |
at the current point, but backtracking to test other matching possibilities |
at the current point, but the testing of other matching possibilities goes |
174 |
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 |
175 |
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>) |
176 |
value. |
returns the negative value. |
177 |
</P> |
</P> |
178 |
<P> |
<P> |
179 |
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 |
181 |
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; |
182 |
it will never be used by PCRE itself. |
it will never be used by PCRE itself. |
183 |
</P> |
</P> |
184 |
|
<br><a name="SEC5" href="#TOC1">AUTHOR</a><br> |
185 |
<P> |
<P> |
186 |
Last updated: 09 September 2004 |
Philip Hazel |
187 |
|
<br> |
188 |
|
University Computing Service |
189 |
|
<br> |
190 |
|
Cambridge CB2 3QH, England. |
191 |
|
<br> |
192 |
|
</P> |
193 |
|
<br><a name="SEC6" href="#TOC1">REVISION</a><br> |
194 |
|
<P> |
195 |
|
Last updated: 29 May 2007 |
196 |
|
<br> |
197 |
|
Copyright © 1997-2007 University of Cambridge. |
198 |
<br> |
<br> |
|
Copyright © 1997-2004 University of Cambridge. |
|
199 |
<p> |
<p> |
200 |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |
201 |
</p> |
</p> |