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

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

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

revision 579 by ph10, Wed Nov 24 17:39:25 2010 UTC revision 659 by ph10, Tue Aug 16 09:48:29 2011 UTC
# Line 436  If \fIerrptr\fP is NULL, \fBpcre_compile Line 436  If \fIerrptr\fP is NULL, \fBpcre_compile
436  Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fP returns  Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fP returns
437  NULL, and sets the variable pointed to by \fIerrptr\fP to point to a textual  NULL, and sets the variable pointed to by \fIerrptr\fP to point to a textual
438  error message. This is a static string that is part of the library. You must  error message. This is a static string that is part of the library. You must
439  not try to free it. The offset from the start of the pattern to the byte that  not try to free it. Normally, the offset from the start of the pattern to the
440  was being processed when the error was discovered is placed in the variable  byte that was being processed when the error was discovered is placed in the
441  pointed to by \fIerroffset\fP, which must not be NULL. If it is, an immediate  variable pointed to by \fIerroffset\fP, which must not be NULL (if it is, an
442  error is given. Some errors are not detected until checks are carried out when  immediate error is given). However, for an invalid UTF-8 string, the offset is
443  the whole pattern has been scanned; in this case the offset is set to the end  that of the first byte of the failing character. Also, some errors are not
444  of the pattern.  detected until checks are carried out when the whole pattern has been scanned;
445    in these cases the offset passed back is the length of the pattern.
446  .P  .P
447  Note that the offset is in bytes, not characters, even in UTF-8 mode. It may  Note that the offset is in bytes, not characters, even in UTF-8 mode. It may
448  point into the middle of a UTF-8 character (for example, when  sometimes point into the middle of a UTF-8 character.
 PCRE_ERROR_BADUTF8 is returned for an invalid UTF-8 string).  
449  .P  .P
450  If \fBpcre_compile2()\fP is used instead of \fBpcre_compile()\fP, and the  If \fBpcre_compile2()\fP is used instead of \fBpcre_compile()\fP, and the
451  \fIerrorcodeptr\fP argument is not NULL, a non-zero error code number is  \fIerrorcodeptr\fP argument is not NULL, a non-zero error code number is
# Line 552  unescaped # outside a character class an Line 552  unescaped # outside a character class an
552  ignored. This is equivalent to Perl's /x option, and it can be changed within a  ignored. This is equivalent to Perl's /x option, and it can be changed within a
553  pattern by a (?x) option setting.  pattern by a (?x) option setting.
554  .P  .P
555  Which characters are interpreted as newlines  Which characters are interpreted as newlines is controlled by the options
556  is controlled by the options passed to \fBpcre_compile()\fP or by a special  passed to \fBpcre_compile()\fP or by a special sequence at the start of the
557  sequence at the start of the pattern, as described in the section entitled  pattern, as described in the section entitled
558  .\" HTML <a href="pcrepattern.html#newlines">  .\" HTML <a href="pcrepattern.html#newlines">
559  .\" </a>  .\" </a>
560  "Newline conventions"  "Newline conventions"
# Line 777  out of use. To avoid confusion, they hav Line 777  out of use. To avoid confusion, they hav
777    34  character value in \ex{...} sequence is too large    34  character value in \ex{...} sequence is too large
778    35  invalid condition (?(0)    35  invalid condition (?(0)
779    36  \eC not allowed in lookbehind assertion    36  \eC not allowed in lookbehind assertion
780    37  PCRE does not support \eL, \el, \eN, \eU, or \eu    37  PCRE does not support \eL, \el, \eN{name}, \eU, or \eu
781    38  number after (?C is > 255    38  number after (?C is > 255
782    39  closing ) for (?C expected    39  closing ) for (?C expected
783    40  recursive call could loop indefinitely    40  recursive call could loop indefinitely
# Line 811  out of use. To avoid confusion, they hav Line 811  out of use. To avoid confusion, they hav
811          not allowed          not allowed
812    66  (*MARK) must have an argument    66  (*MARK) must have an argument
813    67  this version of PCRE is not compiled with PCRE_UCP support    67  this version of PCRE is not compiled with PCRE_UCP support
814      68  \ec must be followed by an ASCII character
815      69  \ek is not followed by a braced, angle-bracketed, or quoted name
816  .sp  .sp
817  The numbers 32 and 10000 in errors 48 and 49 are defaults; different values may  The numbers 32 and 10000 in errors 48 and 49 are defaults; different values may
818  be used if the limits were changed when PCRE was built.  be used if the limits were changed when PCRE was built.
819  .  .
820  .  .
821    .\" HTML <a name="studyingapattern"></a>
822  .SH "STUDYING A PATTERN"  .SH "STUDYING A PATTERN"
823  .rs  .rs
824  .sp  .sp
# Line 946  one in which it was compiled. Passing ta Line 949  one in which it was compiled. Passing ta
949  below in the section on matching a pattern.  below in the section on matching a pattern.
950  .  .
951  .  .
952    .\" HTML <a name="infoaboutpattern"></a>
953  .SH "INFORMATION ABOUT A PATTERN"  .SH "INFORMATION ABOUT A PATTERN"
954  .rs  .rs
955  .sp  .sp
# Line 1164  variable. Line 1168  variable.
1168  .sp  .sp
1169    PCRE_INFO_STUDYSIZE    PCRE_INFO_STUDYSIZE
1170  .sp  .sp
1171  Return the size of the data block pointed to by the \fIstudy_data\fP field in  Return the size of the data block pointed to by the \fIstudy_data\fP field in a
1172  a \fBpcre_extra\fP block. That is, it is the value that was passed to  \fBpcre_extra\fP block. If \fBpcre_extra\fP is NULL, or there is no study data,
1173  \fBpcre_malloc()\fP when PCRE was getting memory into which to place the data  zero is returned. The fourth argument should point to a \fBsize_t\fP variable.
1174  created by \fBpcre_study()\fP. If \fBpcre_extra\fP is NULL, or there is no  The \fIstudy_data\fP field is set by \fBpcre_study()\fP to record information
1175  study data, zero is returned. The fourth argument should point to a  that will speed up matching (see the section entitled
1176  \fBsize_t\fP variable.  .\" HTML <a href="#studyingapattern">
1177    .\" </a>
1178    "Studying a pattern"
1179    .\"
1180    above). The format of the \fIstudy_data\fP block is private, but its length
1181    is made available via this option so that it can be saved and restored (see the
1182    .\" HREF
1183    \fBpcreprecompile\fP
1184    .\"
1185    documentation for details).
1186  .  .
1187  .  .
1188  .SH "OBSOLETE INFO FUNCTION"  .SH "OBSOLETE INFO FUNCTION"
# Line 1264  Here is an example of a simple call to \ Line 1277  Here is an example of a simple call to \
1277      ovector,        /* vector of integers for substring information */      ovector,        /* vector of integers for substring information */
1278      30);            /* number of elements (NOT size in bytes) */      30);            /* number of elements (NOT size in bytes) */
1279  .  .
1280    .
1281  .\" HTML <a name="extradata"></a>  .\" HTML <a name="extradata"></a>
1282  .SS "Extra data for \fBpcre_exec()\fR"  .SS "Extra data for \fBpcre_exec()\fR"
1283  .rs  .rs
# Line 1547  in the main Line 1561  in the main
1561  .\"  .\"
1562  page. If an invalid UTF-8 sequence of bytes is found, \fBpcre_exec()\fP returns  page. If an invalid UTF-8 sequence of bytes is found, \fBpcre_exec()\fP returns
1563  the error PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is  the error PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is
1564  a truncated UTF-8 character at the end of the subject, PCRE_ERROR_SHORTUTF8. If  a truncated UTF-8 character at the end of the subject, PCRE_ERROR_SHORTUTF8. In
1565  \fIstartoffset\fP contains a value that does not point to the start of a UTF-8  both cases, information about the precise nature of the error may also be
1566  character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is  returned (see the descriptions of these errors in the section entitled \fIError
1567    return values from\fP \fBpcre_exec()\fP
1568    .\" HTML <a href="#errorlist">
1569    .\" </a>
1570    below).
1571    .\"
1572    If \fIstartoffset\fP contains a value that does not point to the start of a
1573    UTF-8 character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is
1574  returned.  returned.
1575  .P  .P
1576  If you already know that your subject is valid, and you want to skip these  If you already know that your subject is valid, and you want to skip these
# Line 1717  whatever values they previously had. Line 1738  whatever values they previously had.
1738  Some convenience functions are provided for extracting the captured substrings  Some convenience functions are provided for extracting the captured substrings
1739  as separate strings. These are described below.  as separate strings. These are described below.
1740  .  .
1741    .
1742  .\" HTML <a name="errorlist"></a>  .\" HTML <a name="errorlist"></a>
1743  .SS "Error return values from \fBpcre_exec()\fP"  .SS "Error return values from \fBpcre_exec()\fP"
1744  .rs  .rs
# Line 1786  documentation for details. Line 1808  documentation for details.
1808  .sp  .sp
1809    PCRE_ERROR_BADUTF8        (-10)    PCRE_ERROR_BADUTF8        (-10)
1810  .sp  .sp
1811  A string that contains an invalid UTF-8 byte sequence was passed as a subject.  A string that contains an invalid UTF-8 byte sequence was passed as a subject,
1812  However, if PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8  and the PCRE_NO_UTF8_CHECK option was not set. If the size of the output vector
1813  character at the end of the subject, PCRE_ERROR_SHORTUTF8 is used instead.  (\fIovecsize\fP) is at least 2, the byte offset to the start of the the invalid
1814    UTF-8 character is placed in the first element, and a reason code is placed in
1815    the second element. The reason codes are listed in the
1816    .\" HTML <a href="#badutf8reasons">
1817    .\" </a>
1818    following section.
1819    .\"
1820    For backward compatibility, if PCRE_PARTIAL_HARD is set and the problem is a
1821    truncated UTF-8 character at the end of the subject (reason codes 1 to 5),
1822    PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8.
1823  .sp  .sp
1824    PCRE_ERROR_BADUTF8_OFFSET (-11)    PCRE_ERROR_BADUTF8_OFFSET (-11)
1825  .sp  .sp
1826  The UTF-8 byte sequence that was passed as a subject was valid, but the value  The UTF-8 byte sequence that was passed as a subject was checked and found to
1827  of \fIstartoffset\fP did not point to the beginning of a UTF-8 character or the  be valid (the PCRE_NO_UTF8_CHECK option was not set), but the value of
1828    \fIstartoffset\fP did not point to the beginning of a UTF-8 character or the
1829  end of the subject.  end of the subject.
1830  .sp  .sp
1831    PCRE_ERROR_PARTIAL        (-12)    PCRE_ERROR_PARTIAL        (-12)
# Line 1837  subject, that is, the value in \fIlength Line 1869  subject, that is, the value in \fIlength
1869  .sp  .sp
1870    PCRE_ERROR_SHORTUTF8      (-25)    PCRE_ERROR_SHORTUTF8      (-25)
1871  .sp  .sp
1872  The subject string ended with an incomplete (truncated) UTF-8 character, and  This error is returned instead of PCRE_ERROR_BADUTF8 when the subject string
1873  the PCRE_PARTIAL_HARD option was set. Without this option, PCRE_ERROR_BADUTF8  ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD option is set.
1874  is returned in this situation.  Information about the failure is returned as for PCRE_ERROR_BADUTF8. It is in
1875    fact sufficient to detect this case, but this special error code for
1876    PCRE_PARTIAL_HARD precedes the implementation of returned information; it is
1877    retained for backwards compatibility.
1878    .sp
1879      PCRE_ERROR_RECURSELOOP    (-26)
1880    .sp
1881    This error is returned when \fBpcre_exec()\fP detects a recursion loop within
1882    the pattern. Specifically, it means that either the whole pattern or a
1883    subpattern has been called recursively for the second time at the same position
1884    in the subject string. Some simple patterns that might do this are detected and
1885    faulted at compile time, but more complicated cases, in particular mutual
1886    recursions between two different subpatterns, cannot be detected until run
1887    time.
1888  .P  .P
1889  Error numbers -16 to -20 and -22 are not used by \fBpcre_exec()\fP.  Error numbers -16 to -20 and -22 are not used by \fBpcre_exec()\fP.
1890  .  .
1891  .  .
1892    .\" HTML <a name="badutf8reasons"></a>
1893    .SS "Reason codes for invalid UTF-8 strings"
1894    .rs
1895    .sp
1896    When \fBpcre_exec()\fP returns either PCRE_ERROR_BADUTF8 or
1897    PCRE_ERROR_SHORTUTF8, and the size of the output vector (\fIovecsize\fP) is at
1898    least 2, the offset of the start of the invalid UTF-8 character is placed in
1899    the first output vector element (\fIovector[0]\fP) and a reason code is placed
1900    in the second element (\fIovector[1]\fP). The reason codes are given names in
1901    the \fBpcre.h\fP header file:
1902    .sp
1903      PCRE_UTF8_ERR1
1904      PCRE_UTF8_ERR2
1905      PCRE_UTF8_ERR3
1906      PCRE_UTF8_ERR4
1907      PCRE_UTF8_ERR5
1908    .sp
1909    The string ends with a truncated UTF-8 character; the code specifies how many
1910    bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 characters to be
1911    no longer than 4 bytes, the encoding scheme (originally defined by RFC 2279)
1912    allows for up to 6 bytes, and this is checked first; hence the possibility of
1913    4 or 5 missing bytes.
1914    .sp
1915      PCRE_UTF8_ERR6
1916      PCRE_UTF8_ERR7
1917      PCRE_UTF8_ERR8
1918      PCRE_UTF8_ERR9
1919      PCRE_UTF8_ERR10
1920    .sp
1921    The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of the
1922    character do not have the binary value 0b10 (that is, either the most
1923    significant bit is 0, or the next bit is 1).
1924    .sp
1925      PCRE_UTF8_ERR11
1926      PCRE_UTF8_ERR12
1927    .sp
1928    A character that is valid by the RFC 2279 rules is either 5 or 6 bytes long;
1929    these code points are excluded by RFC 3629.
1930    .sp
1931      PCRE_UTF8_ERR13
1932    .sp
1933    A 4-byte character has a value greater than 0x10fff; these code points are
1934    excluded by RFC 3629.
1935    .sp
1936      PCRE_UTF8_ERR14
1937    .sp
1938    A 3-byte character has a value in the range 0xd800 to 0xdfff; this range of
1939    code points are reserved by RFC 3629 for use with UTF-16, and so are excluded
1940    from UTF-8.
1941    .sp
1942      PCRE_UTF8_ERR15
1943      PCRE_UTF8_ERR16
1944      PCRE_UTF8_ERR17
1945      PCRE_UTF8_ERR18
1946      PCRE_UTF8_ERR19
1947    .sp
1948    A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes for a
1949    value that can be represented by fewer bytes, which is invalid. For example,
1950    the two bytes 0xc0, 0xae give the value 0x2e, whose correct coding uses just
1951    one byte.
1952    .sp
1953      PCRE_UTF8_ERR20
1954    .sp
1955    The two most significant bits of the first byte of a character have the binary
1956    value 0b10 (that is, the most significant bit is 1 and the second is 0). Such a
1957    byte can only validly occur as the second or subsequent byte of a multi-byte
1958    character.
1959    .sp
1960      PCRE_UTF8_ERR21
1961    .sp
1962    The first byte of a character has the value 0xfe or 0xff. These values can
1963    never occur in a valid UTF-8 string.
1964    .
1965    .
1966  .SH "EXTRACTING CAPTURED SUBSTRINGS BY NUMBER"  .SH "EXTRACTING CAPTURED SUBSTRINGS BY NUMBER"
1967  .rs  .rs
1968  .sp  .sp
# Line 2039  fourth are pointers to variables which a Line 2158  fourth are pointers to variables which a
2158  has run, they point to the first and last entries in the name-to-number table  has run, they point to the first and last entries in the name-to-number table
2159  for the given name. The function itself returns the length of each entry, or  for the given name. The function itself returns the length of each entry, or
2160  PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is  PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is
2161  described above in the section entitled \fIInformation about a pattern\fP.  described above in the section entitled \fIInformation about a pattern\fP
2162    .\" HTML <a href="#infoaboutpattern">
2163    .\" </a>
2164    above.
2165    .\"
2166  Given all the relevant entries for the name, you can extract each of their  Given all the relevant entries for the name, you can extract each of their
2167  numbers, and hence the captured data, if any.  numbers, and hence the captured data, if any.
2168  .  .
# Line 2169  match. There is more discussion of this Line 2292  match. There is more discussion of this
2292  .\"  .\"
2293  documentation.  documentation.
2294  .  .
2295    .
2296  .SS "Successful returns from \fBpcre_dfa_exec()\fP"  .SS "Successful returns from \fBpcre_dfa_exec()\fP"
2297  .rs  .rs
2298  .sp  .sp
# Line 2202  matching string is given first. If there Line 2326  matching string is given first. If there
2326  \fIovector\fP, the yield of the function is zero, and the vector is filled with  \fIovector\fP, the yield of the function is zero, and the vector is filled with
2327  the longest matches.  the longest matches.
2328  .  .
2329    .
2330  .SS "Error returns from \fBpcre_dfa_exec()\fP"  .SS "Error returns from \fBpcre_dfa_exec()\fP"
2331  .rs  .rs
2332  .sp  .sp
# Line 2267  Cambridge CB2 3QH, England. Line 2392  Cambridge CB2 3QH, England.
2392  .rs  .rs
2393  .sp  .sp
2394  .nf  .nf
2395  Last updated: 21 November 2010  Last updated: 13 August 2011
2396  Copyright (c) 1997-2010 University of Cambridge.  Copyright (c) 1997-2011 University of Cambridge.
2397  .fi  .fi

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

  ViewVC Help
Powered by ViewVC 1.1.5