/[pcre]/code/trunk/doc/html/pcrecallout.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcrecallout.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC revision 579 by ph10, Wed Nov 24 17:39:25 2010 UTC
# Line 17  man page, in case the conversion went wr Line 17  man page, in case the conversion went wr
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>
# Line 35  function is to be called. Different call Line 37  function is to be called. Different call
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>
# Line 60  trying to optimize the performance of a Line 63  trying to optimize the performance of a
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>
# Line 69  string is "abyz", the lack of "d" means Line 73  string is "abyz", the lack of "d" means
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
91  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
92  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
93  fields:  only argument to the callout function is a pointer to a <b>pcre_callout</b>
94    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>;
# Line 101  automatically generated callouts). Line 118  automatically generated callouts).
118  </P>  </P>
119  <P>  <P>
120  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
121  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
122  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
123  for extracting substrings after a match has completed.  substrings that have been matched so far, in the same way as for extracting
124    substrings after a match has completed. For <b>pcre_dfa_exec()</b> this field is
125    not useful.
126  </P>  </P>
127  <P>  <P>
128  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
129  that were passed to <b>pcre_exec()</b>.  that were passed to <b>pcre_exec()</b>.
130  </P>  </P>
131  <P>  <P>
132  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
133  current match attempt started. If the pattern is not anchored, the callout  which the current match attempt started. However, if the escape sequence \K
134  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
135  different starting points in the subject.  point. If the pattern is not anchored, the callout function may be called
136    several times from the same point in the pattern for different starting points
137    in the subject.
138  </P>  </P>
139  <P>  <P>
140  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
141  current match pointer.  current match pointer.
142  </P>  </P>
143  <P>  <P>
144  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
145  numbered captured substring so far. If no substrings have been captured,  contains one more than the number of the highest numbered captured substring so
146  the value of <i>capture_top</i> is one.  far. If no substrings have been captured, the value of <i>capture_top</i> is
147    one. This is always the case when <b>pcre_dfa_exec()</b> is used, because it
148    does not support captured substrings.
149  </P>  </P>
150  <P>  <P>
151  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
152  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
153    the case when <b>pcre_dfa_exec()</b> is used.
154  </P>  </P>
155  <P>  <P>
156  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
157  <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
158  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
159  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
160  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
161  <b>pcre_extra</b> structure in the  description of the <b>pcre_extra</b> structure in the
162  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
163  documentation.  documentation.
164  </P>  </P>
# Line 160  same callout number. However, they are s Line 184  same callout number. However, they are s
184  <P>  <P>
185  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,
186  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
187  at the current point, but backtracking to test other matching possibilities  at the current point, but the testing of other matching possibilities goes
188  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
189  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>
190  value.  returns the negative value.
191  </P>  </P>
192  <P>  <P>
193  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
# Line 171  values. In particular, PCRE_ERROR_NOMATC Line 195  values. In particular, PCRE_ERROR_NOMATC
195  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;
196  it will never be used by PCRE itself.  it will never be used by PCRE itself.
197  </P>  </P>
198    <br><a name="SEC5" href="#TOC1">AUTHOR</a><br>
199    <P>
200    Philip Hazel
201    <br>
202    University Computing Service
203    <br>
204    Cambridge CB2 3QH, England.
205    <br>
206    </P>
207    <br><a name="SEC6" href="#TOC1">REVISION</a><br>
208  <P>  <P>
209  Last updated: 09 September 2004  Last updated: 21 November 2010
210    <br>
211    Copyright &copy; 1997-2010 University of Cambridge.
212  <br>  <br>
 Copyright &copy; 1997-2004 University of Cambridge.  
213  <p>  <p>
214  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.
215  </p>  </p>

Legend:
Removed from v.75  
changed lines
  Added in v.579

  ViewVC Help
Powered by ViewVC 1.1.5