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

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

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

revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC revision 577 by ph10, Sun Nov 21 18:51:22 2010 UTC
# Line 1  Line 1 
1  .TH PCRE 3  .TH PCRECALLOUT 3
2  .SH NAME  .SH NAME
3  PCRE - Perl-compatible regular expressions  PCRE - Perl-compatible regular expressions
4  .SH "PCRE CALLOUTS"  .SH "PCRE CALLOUTS"
# Line 17  function is to be called. Different call Line 17  function is to be called. Different call
17  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.
18  For example, this pattern has two callout points:  For example, this pattern has two callout points:
19  .sp  .sp
20    (?C1)\deabc(?C2)def    (?C1)abc(?C2)def
21  .sp  .sp
22  If the PCRE_AUTO_CALLOUT option bit is set when \fBpcre_compile()\fP is called,  If the PCRE_AUTO_CALLOUT option bit is set when \fBpcre_compile()\fP or
23  PCRE automatically inserts callouts, all with number 255, before each item in  \fBpcre_compile2()\fP is called, PCRE automatically inserts callouts, all with
24  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
25    is used with the pattern
26  .sp  .sp
27    A(\ed{2}|--)    A(\ed{2}|--)
28  .sp  .sp
# Line 44  trying to optimize the performance of a Line 45  trying to optimize the performance of a
45  .rs  .rs
46  .sp  .sp
47  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
48  patterns, callouts sometimes do not happen. For example, if the pattern is  patterns by default, callouts sometimes do not happen. For example, if the
49    pattern is
50  .sp  .sp
51    ab(?C4)cd    ab(?C4)cd
52  .sp  .sp
# Line 52  PCRE knows that any matching string must Line 54  PCRE knows that any matching string must
54  string is "abyz", the lack of "d" means that matching doesn't ever start, and  string is "abyz", the lack of "d" means that matching doesn't ever start, and
55  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
56  no match, the callout is obeyed.  no match, the callout is obeyed.
57    .P
58    If the pattern is studied, PCRE knows the minimum length of a matching string,
59    and will immediately give a "no match" return without actually running a match
60    if the subject is not long enough, or, for unanchored patterns, if it has
61    been scanned far enough.
62    .P
63    You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE
64    option to \fBpcre_compile()\fP, \fBpcre_exec()\fP, or \fBpcre_dfa_exec()\fP,
65    or by starting the pattern with (*NO_START_OPT). This slows down the matching
66    process, but does ensure that callouts such as the example above are obeyed.
67  .  .
68  .  .
69  .SH "THE CALLOUT INTERFACE"  .SH "THE CALLOUT INTERFACE"
70  .rs  .rs
71  .sp  .sp
72  During matching, when PCRE reaches a callout point, the external function  During matching, when PCRE reaches a callout point, the external function
73  defined by \fIpcre_callout\fP is called (if it is set). The only argument is a  defined by \fIpcre_callout\fP is called (if it is set). This applies to both
74  pointer to a \fBpcre_callout\fP block. This structure contains the following  the \fBpcre_exec()\fP and the \fBpcre_dfa_exec()\fP matching functions. The
75  fields:  only argument to the callout function is a pointer to a \fBpcre_callout\fP
76    block. This structure contains the following fields:
77  .sp  .sp
78    int          \fIversion\fP;    int          \fIversion\fP;
79    int          \fIcallout_number\fP;    int          \fIcallout_number\fP;
# Line 85  into the pattern (that is, the number af Line 98  into the pattern (that is, the number af
98  automatically generated callouts).  automatically generated callouts).
99  .P  .P
100  The \fIoffset_vector\fP field is a pointer to the vector of offsets that was  The \fIoffset_vector\fP field is a pointer to the vector of offsets that was
101  passed by the caller to \fBpcre_exec()\fP. The contents can be inspected in  passed by the caller to \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP. When
102  order to extract substrings that have been matched so far, in the same way as  \fBpcre_exec()\fP is used, the contents can be inspected in order to extract
103  for extracting substrings after a match has completed.  substrings that have been matched so far, in the same way as for extracting
104    substrings after a match has completed. For \fBpcre_dfa_exec()\fP this field is
105    not useful.
106  .P  .P
107  The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values  The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values
108  that were passed to \fBpcre_exec()\fP.  that were passed to \fBpcre_exec()\fP.
109  .P  .P
110  The \fIstart_match\fP field contains the offset within the subject at which the  The \fIstart_match\fP field normally contains the offset within the subject at
111  current match attempt started. If the pattern is not anchored, the callout  which the current match attempt started. However, if the escape sequence \eK
112  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
113  different starting points in the subject.  point. If the pattern is not anchored, the callout function may be called
114    several times from the same point in the pattern for different starting points
115    in the subject.
116  .P  .P
117  The \fIcurrent_position\fP field contains the offset within the subject of the  The \fIcurrent_position\fP field contains the offset within the subject of the
118  current match pointer.  current match pointer.
119  .P  .P
120  The \fIcapture_top\fP field contains one more than the number of the highest  When the \fBpcre_exec()\fP function is used, the \fIcapture_top\fP field
121  numbered captured substring so far. If no substrings have been captured,  contains one more than the number of the highest numbered captured substring so
122  the value of \fIcapture_top\fP is one.  far. If no substrings have been captured, the value of \fIcapture_top\fP is
123    one. This is always the case when \fBpcre_dfa_exec()\fP is used, because it
124    does not support captured substrings.
125  .P  .P
126  The \fIcapture_last\fP field contains the number of the most recently captured  The \fIcapture_last\fP field contains the number of the most recently captured
127  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
128    the case when \fBpcre_dfa_exec()\fP is used.
129  .P  .P
130  The \fIcallout_data\fP field contains a value that is passed to  The \fIcallout_data\fP field contains a value that is passed to
131  \fBpcre_exec()\fP by the caller specifically so that it can be passed back in  \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP specifically so that it can be
132  callouts. It is passed in the \fIpcre_callout\fP field of the \fBpcre_extra\fP  passed back in callouts. It is passed in the \fIpcre_callout\fP field of the
133  data structure. If no such data was passed, the value of \fIcallout_data\fP in  \fBpcre_extra\fP data structure. If no such data was passed, the value of
134  a \fBpcre_callout\fP block is NULL. There is a description of the  \fIcallout_data\fP in a \fBpcre_callout\fP block is NULL. There is a
135  \fBpcre_extra\fP structure in the  description of the \fBpcre_extra\fP structure in the
136  .\" HREF  .\" HREF
137  \fBpcreapi\fP  \fBpcreapi\fP
138  .\"  .\"
# Line 139  same callout number. However, they are s Line 159  same callout number. However, they are s
159  .sp  .sp
160  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,
161  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
162  at the current point, but backtracking to test other matching possibilities  at the current point, but the testing of other matching possibilities goes
163  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
164  than zero, the match is abandoned, and \fBpcre_exec()\fP returns the negative  zero, the match is abandoned, and \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP
165  value.  returns the negative value.
166  .P  .P
167  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
168  values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.  values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
169  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;
170  it will never be used by PCRE itself.  it will never be used by PCRE itself.
171  .P  .
172  .in 0  .
173  Last updated: 09 September 2004  .SH AUTHOR
174  .br  .rs
175  Copyright (c) 1997-2004 University of Cambridge.  .sp
176    .nf
177    Philip Hazel
178    University Computing Service
179    Cambridge CB2 3QH, England.
180    .fi
181    .
182    .
183    .SH REVISION
184    .rs
185    .sp
186    .nf
187    Last updated: 21 November 2010
188    Copyright (c) 1997-2010 University of Cambridge.
189    .fi

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

  ViewVC Help
Powered by ViewVC 1.1.5