/[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 566 by ph10, Wed Nov 3 18:32:55 2010 UTC revision 569 by ph10, Sun Nov 7 16:14:50 2010 UTC
# Line 435  If \fIerrptr\fP is NULL, \fBpcre_compile Line 435  If \fIerrptr\fP is NULL, \fBpcre_compile
435  Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fP returns  Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fP returns
436  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
437  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
438  not try to free it. The byte offset from the start of the pattern to the  not try to free it. The offset from the start of the pattern to the byte that
439  character that was being processed when the error was discovered is placed in  was being processed when the error was discovered is placed in the variable
440  the variable pointed to by \fIerroffset\fP, which must not be NULL. If it is,  pointed to by \fIerroffset\fP, which must not be NULL. If it is, an immediate
441  an immediate error is given. Some errors are not detected until checks are  error is given. Some errors are not detected until checks are carried out when
442  carried out when the whole pattern has been scanned; in this case the offset is  the whole pattern has been scanned; in this case the offset is set to the end
443  set to the end of the pattern.  of the pattern.
444    .P
445    Note that the offset is in bytes, not characters, even in UTF-8 mode. It may
446    point into the middle of a UTF-8 character (for example, when
447    PCRE_ERROR_BADUTF8 is returned for an invalid UTF-8 string).
448  .P  .P
449  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
450  \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 1515  in the main Line 1519  in the main
1519  \fBpcre\fP  \fBpcre\fP
1520  .\"  .\"
1521  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
1522  the error PCRE_ERROR_BADUTF8. If \fIstartoffset\fP contains an invalid value,  the error PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is
1523  PCRE_ERROR_BADUTF8_OFFSET is returned.  a truncated UTF-8 character at the end of the subject, PCRE_ERROR_SHORTUTF8. If
1524    \fIstartoffset\fP contains a value that does not point to the start of a UTF-8
1525    character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is
1526    returned.
1527  .P  .P
1528  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
1529  checks for performance reasons, you can set the PCRE_NO_UTF8_CHECK option when  checks for performance reasons, you can set the PCRE_NO_UTF8_CHECK option when
1530  calling \fBpcre_exec()\fP. You might want to do this for the second and  calling \fBpcre_exec()\fP. You might want to do this for the second and
1531  subsequent calls to \fBpcre_exec()\fP if you are making repeated calls to find  subsequent calls to \fBpcre_exec()\fP if you are making repeated calls to find
1532  all the matches in a single subject string. However, you should be sure that  all the matches in a single subject string. However, you should be sure that
1533  the value of \fIstartoffset\fP points to the start of a UTF-8 character. When  the value of \fIstartoffset\fP points to the start of a UTF-8 character (or the
1534  PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid UTF-8 string as a  end of the subject). When PCRE_NO_UTF8_CHECK is set, the effect of passing an
1535  subject, or a value of \fIstartoffset\fP that does not point to the start of a  invalid UTF-8 string as a subject or an invalid value of \fIstartoffset\fP is
1536  UTF-8 character, is undefined. Your program may crash.  undefined. Your program may crash.
1537  .sp  .sp
1538    PCRE_PARTIAL_HARD    PCRE_PARTIAL_HARD
1539    PCRE_PARTIAL_SOFT    PCRE_PARTIAL_SOFT
# Line 1555  discussion of partial and multi-segment Line 1562  discussion of partial and multi-segment
1562  .\"  .\"
1563  documentation.  documentation.
1564  .  .
1565    .
1566  .SS "The string to be matched by \fBpcre_exec()\fP"  .SS "The string to be matched by \fBpcre_exec()\fP"
1567  .rs  .rs
1568  .sp  .sp
1569  The subject string is passed to \fBpcre_exec()\fP as a pointer in  The subject string is passed to \fBpcre_exec()\fP as a pointer in
1570  \fIsubject\fP, a length (in bytes) in \fIlength\fP, and a starting byte offset  \fIsubject\fP, a length (in bytes) in \fIlength\fP, and a starting byte offset
1571  in \fIstartoffset\fP. In UTF-8 mode, the byte offset must point to the start of  in \fIstartoffset\fP. If this is negative or greater than the length of the
1572  a UTF-8 character. Unlike the pattern string, the subject may contain binary  subject, \fBpcre_exec()\fP returns PCRE_ERROR_BADOFFSET.
1573  zero bytes. When the starting offset is zero, the search for a match starts at  .P
1574  the beginning of the subject, and this is by far the most common case.  In UTF-8 mode, the byte offset must point to the start of a UTF-8 character (or
1575    the end of the subject). Unlike the pattern string, the subject may contain
1576    binary zero bytes. When the starting offset is zero, the search for a match
1577    starts at the beginning of the subject, and this is by far the most common
1578    case.
1579  .P  .P
1580  A non-zero starting offset is useful when searching for another match in the  A non-zero starting offset is useful when searching for another match in the
1581  same subject by calling \fBpcre_exec()\fP again after a previous success.  same subject by calling \fBpcre_exec()\fP again after a previous success.
# Line 1583  start of the subject, which is deemed to Line 1595  start of the subject, which is deemed to
1595  set to 4, it finds the second occurrence of "iss" because it is able to look  set to 4, it finds the second occurrence of "iss" because it is able to look
1596  behind the starting point to discover that it is preceded by a letter.  behind the starting point to discover that it is preceded by a letter.
1597  .P  .P
1598    Finding all the matches in a subject is tricky when the pattern can match an
1599    empty string. It is possible to emulate Perl's /g behaviour by first trying the
1600    match again at the same offset, with the PCRE_NOTEMPTY_ATSTART and
1601    PCRE_ANCHORED options, and then if that fails, advancing the starting offset
1602    and trying an ordinary match again. There is some code that demonstrates how to
1603    do this in the
1604    .\" HREF
1605    \fBpcredemo\fP
1606    .\"
1607    sample program. In the most general case, you have to check to see if the
1608    newline convention recognizes CRLF as a newline, and if so, and the current
1609    character is CR followed by LF, advance the starting offset by two characters
1610    instead of one.
1611    .P
1612  If a non-zero starting offset is passed when the pattern is anchored, one  If a non-zero starting offset is passed when the pattern is anchored, one
1613  attempt to match at the given offset is made. This can only succeed if the  attempt to match at the given offset is made. This can only succeed if the
1614  pattern does not require the match to be at the start of the subject.  pattern does not require the match to be at the start of the subject.
1615  .  .
1616    .
1617  .SS "How \fBpcre_exec()\fP returns captured substrings"  .SS "How \fBpcre_exec()\fP returns captured substrings"
1618  .rs  .rs
1619  .sp  .sp
# Line 1653  Offset values that correspond to unused Line 1680  Offset values that correspond to unused
1680  expression are also set to -1. For example, if the string "abc" is matched  expression are also set to -1. For example, if the string "abc" is matched
1681  against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The  against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The
1682  return from the function is 2, because the highest used capturing subpattern  return from the function is 2, because the highest used capturing subpattern
1683  number is 1. However, you can refer to the offsets for the second and third  number is 1, and the offsets for for the second and third capturing subpatterns
1684  capturing subpatterns if you wish (assuming the vector is large enough, of  (assuming the vector is large enough, of course) are set to -1.
1685  course).  .P
1686    \fBNote\fP: Elements of \fIovector\fP that do not correspond to capturing
1687    parentheses in the pattern are never changed. That is, if a pattern contains
1688    \fIn\fP capturing parentheses, no more than \fIovector[0]\fP to
1689    \fIovector[2n+1]\fP are set by \fBpcre_exec()\fP. The other elements retain
1690    whatever values they previously had.
1691  .P  .P
1692  Some convenience functions are provided for extracting the captured substrings  Some convenience functions are provided for extracting the captured substrings
1693  as separate strings. These are described below.  as separate strings. These are described below.
# Line 1730  documentation for details. Line 1762  documentation for details.
1762    PCRE_ERROR_BADUTF8        (-10)    PCRE_ERROR_BADUTF8        (-10)
1763  .sp  .sp
1764  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.
1765    However, if PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8
1766    character at the end of the subject, PCRE_ERROR_SHORTUTF8 is used instead.
1767  .sp  .sp
1768    PCRE_ERROR_BADUTF8_OFFSET (-11)    PCRE_ERROR_BADUTF8_OFFSET (-11)
1769  .sp  .sp
1770  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 valid, but the value
1771  of \fIstartoffset\fP did not point to the beginning of a UTF-8 character.  of \fIstartoffset\fP did not point to the beginning of a UTF-8 character or the
1772    end of the subject.
1773  .sp  .sp
1774    PCRE_ERROR_PARTIAL        (-12)    PCRE_ERROR_PARTIAL        (-12)
1775  .sp  .sp
# Line 1769  description above. Line 1804  description above.
1804    PCRE_ERROR_BADNEWLINE     (-23)    PCRE_ERROR_BADNEWLINE     (-23)
1805  .sp  .sp
1806  An invalid combination of PCRE_NEWLINE_\fIxxx\fP options was given.  An invalid combination of PCRE_NEWLINE_\fIxxx\fP options was given.
1807    .sp
1808      PCRE_ERROR_BADOFFSET      (-24)
1809    .sp
1810    The value of \fIstartoffset\fP was negative or greater than the length of the
1811    subject, that is, the value in \fIlength\fP.
1812    .sp
1813      PCRE_ERROR_SHORTUTF8      (-25)
1814    .sp
1815    The subject string ended with an incomplete (truncated) UTF-8 character, and
1816    the PCRE_PARTIAL_HARD option was set. Without this option, PCRE_ERROR_BADUTF8
1817    is returned in this situation.
1818  .P  .P
1819  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.
1820  .  .
# Line 2196  Cambridge CB2 3QH, England. Line 2242  Cambridge CB2 3QH, England.
2242  .rs  .rs
2243  .sp  .sp
2244  .nf  .nf
2245  Last updated: 01 November 2010  Last updated: 06 November 2010
2246  Copyright (c) 1997-2010 University of Cambridge.  Copyright (c) 1997-2010 University of Cambridge.
2247  .fi  .fi

Legend:
Removed from v.566  
changed lines
  Added in v.569

  ViewVC Help
Powered by ViewVC 1.1.5