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

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

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

revision 653 by ph10, Wed Nov 24 17:39:25 2010 UTC revision 654 by ph10, Tue Aug 2 11:00:40 2011 UTC
# Line 444  If <i>errptr</i> is NULL, <b>pcre_compil Line 444  If <i>errptr</i> is NULL, <b>pcre_compil
444  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns
445  NULL, and sets the variable pointed to by <i>errptr</i> to point to a textual  NULL, and sets the variable pointed to by <i>errptr</i> to point to a textual
446  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
447  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
448  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
449  pointed to by <i>erroffset</i>, which must not be NULL. If it is, an immediate  variable pointed to by <i>erroffset</i>, which must not be NULL (if it is, an
450  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
451  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
452  of the pattern.  detected until checks are carried out when the whole pattern has been scanned;
453    in these cases the offset passed back is the length of the pattern.
454  </P>  </P>
455  <P>  <P>
456  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
457  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).  
458  </P>  </P>
459  <P>  <P>
460  If <b>pcre_compile2()</b> is used instead of <b>pcre_compile()</b>, and the  If <b>pcre_compile2()</b> is used instead of <b>pcre_compile()</b>, and the
# Line 561  ignored. This is equivalent to Perl's /x Line 561  ignored. This is equivalent to Perl's /x
561  pattern by a (?x) option setting.  pattern by a (?x) option setting.
562  </P>  </P>
563  <P>  <P>
564  Which characters are interpreted as newlines  Which characters are interpreted as newlines is controlled by the options
565  is controlled by the options passed to <b>pcre_compile()</b> or by a special  passed to <b>pcre_compile()</b> or by a special sequence at the start of the
566  sequence at the start of the pattern, as described in the section entitled  pattern, as described in the section entitled
567  <a href="pcrepattern.html#newlines">"Newline conventions"</a>  <a href="pcrepattern.html#newlines">"Newline conventions"</a>
568  in the <b>pcrepattern</b> documentation. Note that the end of this type of  in the <b>pcrepattern</b> documentation. Note that the end of this type of
569  comment is a literal newline sequence in the pattern; escape sequences that  comment is a literal newline sequence in the pattern; escape sequences that
# Line 939  internal tables) to <b>pcre_exec()</b>. Line 939  internal tables) to <b>pcre_exec()</b>.
939  this facility could be used to match a pattern in a different locale from the  this facility could be used to match a pattern in a different locale from the
940  one in which it was compiled. Passing table pointers at run time is discussed  one in which it was compiled. Passing table pointers at run time is discussed
941  below in the section on matching a pattern.  below in the section on matching a pattern.
942  </P>  <a name="infoaboutpattern"></a></P>
943  <br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br>  <br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br>
944  <P>  <P>
945  <b>int pcre_fullinfo(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>  <b>int pcre_fullinfo(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>
# Line 1533  in the main Line 1533  in the main
1533  <a href="pcre.html"><b>pcre</b></a>  <a href="pcre.html"><b>pcre</b></a>
1534  page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns  page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns
1535  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
1536  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
1537  <i>startoffset</i> 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
1538  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
1539    return values from\fP <b>pcre_exec()</b>
1540    <a href="#errorlist">below).</a>
1541    If <i>startoffset</i> contains a value that does not point to the start of a
1542    UTF-8 character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is
1543  returned.  returned.
1544  </P>  </P>
1545  <P>  <P>
# Line 1784  documentation for details. Line 1788  documentation for details.
1788  <pre>  <pre>
1789    PCRE_ERROR_BADUTF8        (-10)    PCRE_ERROR_BADUTF8        (-10)
1790  </pre>  </pre>
1791  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,
1792  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
1793  character at the end of the subject, PCRE_ERROR_SHORTUTF8 is used instead.  (<i>ovecsize</i>) is at least 2, the byte offset to the start of the the invalid
1794    UTF-8 character is placed in the first element, and a reason code is placed in
1795    the second element. The reason codes are listed in the
1796    <a href="#badutf8reasons">following section.</a>
1797    For backward compatibility, if PCRE_PARTIAL_HARD is set and the problem is a
1798    truncated UTF-8 character at the end of the subject (reason codes 1 to 5),
1799    PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8.
1800  <pre>  <pre>
1801    PCRE_ERROR_BADUTF8_OFFSET (-11)    PCRE_ERROR_BADUTF8_OFFSET (-11)
1802  </pre>  </pre>
1803  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
1804  of <i>startoffset</i> 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
1805    <i>startoffset</i> did not point to the beginning of a UTF-8 character or the
1806  end of the subject.  end of the subject.
1807  <pre>  <pre>
1808    PCRE_ERROR_PARTIAL        (-12)    PCRE_ERROR_PARTIAL        (-12)
# Line 1833  subject, that is, the value in <i>length Line 1844  subject, that is, the value in <i>length
1844  <pre>  <pre>
1845    PCRE_ERROR_SHORTUTF8      (-25)    PCRE_ERROR_SHORTUTF8      (-25)
1846  </pre>  </pre>
1847  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
1848  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.
1849  is returned in this situation.  Information about the failure is returned as for PCRE_ERROR_BADUTF8. It is in
1850    fact sufficient to detect this case, but this special error code for
1851    PCRE_PARTIAL_HARD precedes the implementation of returned information; it is
1852    retained for backwards compatibility.
1853    <pre>
1854      PCRE_ERROR_RECURSELOOP    (-26)
1855    </pre>
1856    This error is returned when <b>pcre_exec()</b> detects a recursion loop within
1857    the pattern. Specifically, it means that either the whole pattern or a
1858    subpattern has been called recursively for the second time at the same position
1859    in the subject string. Some simple patterns that might do this are detected and
1860    faulted at compile time, but more complicated cases, in particular mutual
1861    recursions between two different subpatterns, cannot be detected until run
1862    time.
1863  </P>  </P>
1864  <P>  <P>
1865  Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.  Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.
1866    <a name="badutf8reasons"></a></P>
1867    <br><b>
1868    Reason codes for invalid UTF-8 strings
1869    </b><br>
1870    <P>
1871    When <b>pcre_exec()</b> returns either PCRE_ERROR_BADUTF8 or
1872    PCRE_ERROR_SHORTUTF8, and the size of the output vector (<i>ovecsize</i>) is at
1873    least 2, the offset of the start of the invalid UTF-8 character is placed in
1874    the first output vector element (<i>ovector[0]</i>) and a reason code is placed
1875    in the second element (<i>ovector[1]</i>). The reason codes are given names in
1876    the <b>pcre.h</b> header file:
1877    <pre>
1878      PCRE_UTF8_ERR1
1879      PCRE_UTF8_ERR2
1880      PCRE_UTF8_ERR3
1881      PCRE_UTF8_ERR4
1882      PCRE_UTF8_ERR5
1883    </pre>
1884    The string ends with a truncated UTF-8 character; the code specifies how many
1885    bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 characters to be
1886    no longer than 4 bytes, the encoding scheme (originally defined by RFC 2279)
1887    allows for up to 6 bytes, and this is checked first; hence the possibility of
1888    4 or 5 missing bytes.
1889    <pre>
1890      PCRE_UTF8_ERR6
1891      PCRE_UTF8_ERR7
1892      PCRE_UTF8_ERR8
1893      PCRE_UTF8_ERR9
1894      PCRE_UTF8_ERR10
1895    </pre>
1896    The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of the
1897    character do not have the binary value 0b10 (that is, either the most
1898    significant bit is 0, or the next bit is 1).
1899    <pre>
1900      PCRE_UTF8_ERR11
1901      PCRE_UTF8_ERR12
1902    </pre>
1903    A character that is valid by the RFC 2279 rules is either 5 or 6 bytes long;
1904    these code points are excluded by RFC 3629.
1905    <pre>
1906      PCRE_UTF8_ERR13
1907    </pre>
1908    A 4-byte character has a value greater than 0x10fff; these code points are
1909    excluded by RFC 3629.
1910    <pre>
1911      PCRE_UTF8_ERR14
1912    </pre>
1913    A 3-byte character has a value in the range 0xd800 to 0xdfff; this range of
1914    code points are reserved by RFC 3629 for use with UTF-16, and so are excluded
1915    from UTF-8.
1916    <pre>
1917      PCRE_UTF8_ERR15
1918      PCRE_UTF8_ERR16
1919      PCRE_UTF8_ERR17
1920      PCRE_UTF8_ERR18
1921      PCRE_UTF8_ERR19
1922    </pre>
1923    A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes for a
1924    value that can be represented by fewer bytes, which is invalid. For example,
1925    the two bytes 0xc0, 0xae give the value 0x2e, whose correct coding uses just
1926    one byte.
1927    <pre>
1928      PCRE_UTF8_ERR20
1929    </pre>
1930    The two most significant bits of the first byte of a character have the binary
1931    value 0b10 (that is, the most significant bit is 1 and the second is 0). Such a
1932    byte can only validly occur as the second or subsequent byte of a multi-byte
1933    character.
1934    <pre>
1935      PCRE_UTF8_ERR21
1936    </pre>
1937    The first byte of a character has the value 0xfe or 0xff. These values can
1938    never occur in a valid UTF-8 string.
1939  </P>  </P>
1940  <br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br>  <br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br>
1941  <P>  <P>
# Line 2032  fourth are pointers to variables which a Line 2129  fourth are pointers to variables which a
2129  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
2130  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
2131  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
2132  described above in the section entitled <i>Information about a pattern</i>.  described above in the section entitled <i>Information about a pattern</i>
2133    <a href="#infoaboutpattern">above.</a>
2134  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
2135  numbers, and hence the captured data, if any.  numbers, and hence the captured data, if any.
2136  </P>  </P>
# Line 2245  Cambridge CB2 3QH, England. Line 2343  Cambridge CB2 3QH, England.
2343  </P>  </P>
2344  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
2345  <P>  <P>
2346  Last updated: 21 November 2010  Last updated: 28 July 2011
2347  <br>  <br>
2348  Copyright &copy; 1997-2010 University of Cambridge.  Copyright &copy; 1997-2011 University of Cambridge.
2349  <br>  <br>
2350  <p>  <p>
2351  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.653  
changed lines
  Added in v.654

  ViewVC Help
Powered by ViewVC 1.1.5