ViewVC logotype

Contents of /code/trunk/doc/html/pcreunicode.html

Parent Directory Parent Directory | Revision Log Revision Log

Revision 678 - (show annotations)
Sun Aug 28 15:23:03 2011 UTC (8 years, 2 months ago) by ph10
File MIME type: text/html
File size: 7706 byte(s)
Documentation for JIT support.
1 <html>
2 <head>
3 <title>pcreunicode specification</title>
4 </head>
5 <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6 <h1>pcreunicode man page</h1>
7 <p>
8 Return to the <a href="index.html">PCRE index page</a>.
9 </p>
10 <p>
11 This page is part of the PCRE HTML documentation. It was generated automatically
12 from the original man page. If there is any nonsense in it, please consult the
13 man page, in case the conversion went wrong.
14 <br>
15 <br><b>
17 </b><br>
18 <P>
19 In order process UTF-8 strings, you must build PCRE to include UTF-8 support in
20 the code, and, in addition, you must call
21 <a href="pcre_compile.html"><b>pcre_compile()</b></a>
22 with the PCRE_UTF8 option flag, or the pattern must start with the sequence
23 (*UTF8). When either of these is the case, both the pattern and any subject
24 strings that are matched against it are treated as UTF-8 strings instead of
25 strings of 1-byte characters. PCRE does not support any other formats (in
26 particular, it does not support UTF-16).
27 </P>
28 <P>
29 If you compile PCRE with UTF-8 support, but do not use it at run time, the
30 library will be a bit bigger, but the additional run time overhead is limited
31 to testing the PCRE_UTF8 flag occasionally, so should not be very big.
32 </P>
33 <P>
34 If PCRE is built with Unicode character property support (which implies UTF-8
35 support), the escape sequences \p{..}, \P{..}, and \X are supported.
36 The available properties that can be tested are limited to the general
37 category properties such as Lu for an upper case letter or Nd for a decimal
38 number, the Unicode script names such as Arabic or Han, and the derived
39 properties Any and L&. A full list is given in the
40 <a href="pcrepattern.html"><b>pcrepattern</b></a>
41 documentation. Only the short names for properties are supported. For example,
42 \p{L} matches a letter. Its Perl synonym, \p{Letter}, is not supported.
43 Furthermore, in Perl, many properties may optionally be prefixed by "Is", for
44 compatibility with Perl 5.6. PCRE does not support this.
45 <a name="utf8strings"></a></P>
46 <br><b>
47 Validity of UTF-8 strings
48 </b><br>
49 <P>
50 When you set the PCRE_UTF8 flag, the strings passed as patterns and subjects
51 are (by default) checked for validity on entry to the relevant functions. From
52 release 7.3 of PCRE, the check is according the rules of RFC 3629, which are
53 themselves derived from the Unicode specification. Earlier releases of PCRE
54 followed the rules of RFC 2279, which allows the full range of 31-bit values (0
55 to 0x7FFFFFFF). The current check allows only values in the range U+0 to
56 U+10FFFF, excluding U+D800 to U+DFFF.
57 </P>
58 <P>
59 The excluded code points are the "Low Surrogate Area" of Unicode, of which the
60 Unicode Standard says this: "The Low Surrogate Area does not contain any
61 character assignments, consequently no character code charts or namelists are
62 provided for this area. Surrogates are reserved for use with UTF-16 and then
63 must be used in pairs." The code points that are encoded by UTF-16 pairs are
64 available as independent code points in the UTF-8 encoding. (In other words,
65 the whole surrogate thing is a fudge for UTF-16 which unfortunately messes up
66 UTF-8.)
67 </P>
68 <P>
69 If an invalid UTF-8 string is passed to PCRE, an error return is given. At
70 compile time, the only additional information is the offset to the first byte
71 of the failing character. The runtime functions <b>pcre_exec()</b> and
72 <b>pcre_dfa_exec()</b> also pass back this information, as well as a more
73 detailed reason code if the caller has provided memory in which to do this.
74 </P>
75 <P>
76 In some situations, you may already know that your strings are valid, and
77 therefore want to skip these checks in order to improve performance. If you set
78 the PCRE_NO_UTF8_CHECK flag at compile time or at run time, PCRE assumes that
79 the pattern or subject it is given (respectively) contains only valid UTF-8
80 codes. In this case, it does not diagnose an invalid UTF-8 string.
81 </P>
82 <P>
83 If you pass an invalid UTF-8 string when PCRE_NO_UTF8_CHECK is set, what
84 happens depends on why the string is invalid. If the string conforms to the
85 "old" definition of UTF-8 (RFC 2279), it is processed as a string of characters
86 in the range 0 to 0x7FFFFFFF. In other words, apart from the initial validity
87 test, PCRE (when in UTF-8 mode) handles strings according to the more liberal
88 rules of RFC 2279. However, if the string does not even conform to RFC 2279,
89 the result is undefined. Your program may crash.
90 </P>
91 <P>
92 If you want to process strings of values in the full range 0 to 0x7FFFFFFF,
93 encoded in a UTF-8-like manner as per the old RFC, you can set
94 PCRE_NO_UTF8_CHECK to bypass the more restrictive test. However, in this
95 situation, you will have to apply your own validity check.
96 </P>
97 <br><b>
98 General comments about UTF-8 mode
99 </b><br>
100 <P>
101 1. An unbraced hexadecimal escape sequence (such as \xb3) matches a two-byte
102 UTF-8 character if the value is greater than 127.
103 </P>
104 <P>
105 2. Octal numbers up to \777 are recognized, and match two-byte UTF-8
106 characters for values greater than \177.
107 </P>
108 <P>
109 3. Repeat quantifiers apply to complete UTF-8 characters, not to individual
110 bytes, for example: \x{100}{3}.
111 </P>
112 <P>
113 4. The dot metacharacter matches one UTF-8 character instead of a single byte.
114 </P>
115 <P>
116 5. The escape sequence \C can be used to match a single byte in UTF-8 mode,
117 but its use can lead to some strange effects. This facility is not available in
118 the alternative matching function, <b>pcre_dfa_exec()</b>.
119 </P>
120 <P>
121 6. The character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly
122 test characters of any code value, but, by default, the characters that PCRE
123 recognizes as digits, spaces, or word characters remain the same set as before,
124 all with values less than 256. This remains true even when PCRE is built to
125 include Unicode property support, because to do otherwise would slow down PCRE
126 in many common cases. Note in particular that this applies to \b and \B,
127 because they are defined in terms of \w and \W. If you really want to test
128 for a wider sense of, say, "digit", you can use explicit Unicode property tests
129 such as \p{Nd}. Alternatively, if you set the PCRE_UCP option, the way that
130 the character escapes work is changed so that Unicode properties are used to
131 determine which characters match. There are more details in the section on
132 <a href="pcrepattern.html#genericchartypes">generic character types</a>
133 in the
134 <a href="pcrepattern.html"><b>pcrepattern</b></a>
135 documentation.
136 </P>
137 <P>
138 7. Similarly, characters that match the POSIX named character classes are all
139 low-valued characters, unless the PCRE_UCP option is set.
140 </P>
141 <P>
142 8. However, the horizontal and vertical whitespace matching escapes (\h, \H,
143 \v, and \V) do match all the appropriate Unicode characters, whether or not
144 PCRE_UCP is set.
145 </P>
146 <P>
147 9. Case-insensitive matching applies only to characters whose values are less
148 than 128, unless PCRE is built with Unicode property support. Even when Unicode
149 property support is available, PCRE still uses its own character tables when
150 checking the case of low-valued characters, so as not to degrade performance.
151 The Unicode property information is used only for characters with higher
152 values. Furthermore, PCRE supports case-insensitive matching only when there is
153 a one-to-one mapping between a letter's cases. There are a small number of
154 many-to-one mappings in Unicode; these are not supported by PCRE.
155 </P>
156 <br><b>
158 </b><br>
159 <P>
160 Philip Hazel
161 <br>
162 University Computing Service
163 <br>
164 Cambridge CB2 3QH, England.
165 <br>
166 </P>
167 <br><b>
169 </b><br>
170 <P>
171 Last updated: 24 August 2011
172 <br>
173 Copyright &copy; 1997-2011 University of Cambridge.
174 <br>
175 <p>
176 Return to the <a href="index.html">PCRE index page</a>.
177 </p>

  ViewVC Help
Powered by ViewVC 1.1.5