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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1194 - (show annotations)
Wed Oct 31 17:42:29 2012 UTC (6 years, 7 months ago) by ph10
File MIME type: text/html
File size: 13297 byte(s)
More documentation updates
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>
16 UTF-8, UTF-16, AND UNICODE PROPERTY SUPPORT
17 </b><br>
18 <P>
19 From Release 8.30, in addition to its previous UTF-8 support, PCRE also
20 supports UTF-16 by means of a separate 16-bit library. This can be built as
21 well as, or instead of, the 8-bit library.
22 </P>
23 <P>
24 From Release 8.32, in addition to its previous UTF-8 and UTF-16 support,
25 PCRE also supports UTF-32 by means of a separate 32-bit library. This can be
26 built as well as, or instead of, the 8-bit and 16-bit libraries.
27 </P>
28 <br><b>
29 UTF-8 SUPPORT
30 </b><br>
31 <P>
32 In order process UTF-8 strings, you must build PCRE's 8-bit library with UTF
33 support, and, in addition, you must call
34 <a href="pcre_compile.html"><b>pcre_compile()</b></a>
35 with the PCRE_UTF8 option flag, or the pattern must start with the sequence
36 (*UTF8). When either of these is the case, both the pattern and any subject
37 strings that are matched against it are treated as UTF-8 strings instead of
38 strings of 1-byte characters.
39 </P>
40 <br><b>
41 UTF-16 SUPPORT
42 </b><br>
43 <P>
44 In order process UTF-16 strings, you must build PCRE's 16-bit library with UTF
45 support, and, in addition, you must call
46 <a href="pcre_compile.html"><b>pcre16_compile()</b></a>
47 with the PCRE_UTF16 option flag, or the pattern must start with the sequence
48 (*UTF16). When either of these is the case, both the pattern and any subject
49 strings that are matched against it are treated as UTF-16 strings instead of
50 strings of 16-bit characters.
51 </P>
52 <br><b>
53 UTF-32 SUPPORT
54 </b><br>
55 <P>
56 In order process UTF-32 strings, you must build PCRE's 32-bit library with UTF
57 support, and, in addition, you must call
58 <a href="pcre_compile.html"><b>pcre32_compile()</b></a>
59 with the PCRE_UTF32 option flag, or the pattern must start with the sequence
60 (*UTF32). When either of these is the case, both the pattern and any subject
61 strings that are matched against it are treated as UTF-32 strings instead of
62 strings of 32-bit characters.
63 </P>
64 <br><b>
65 UTF SUPPORT OVERHEAD
66 </b><br>
67 <P>
68 If you compile PCRE with UTF support, but do not use it at run time, the
69 library will be a bit bigger, but the additional run time overhead is limited
70 to testing the PCRE_UTF[8|16|32] flag occasionally, so should not be very big.
71 </P>
72 <br><b>
73 UNICODE PROPERTY SUPPORT
74 </b><br>
75 <P>
76 If PCRE is built with Unicode character property support (which implies UTF
77 support), the escape sequences \p{..}, \P{..}, and \X can be used.
78 The available properties that can be tested are limited to the general
79 category properties such as Lu for an upper case letter or Nd for a decimal
80 number, the Unicode script names such as Arabic or Han, and the derived
81 properties Any and L&. A full list is given in the
82 <a href="pcrepattern.html"><b>pcrepattern</b></a>
83 documentation. Only the short names for properties are supported. For example,
84 \p{L} matches a letter. Its Perl synonym, \p{Letter}, is not supported.
85 Furthermore, in Perl, many properties may optionally be prefixed by "Is", for
86 compatibility with Perl 5.6. PCRE does not support this.
87 <a name="utf8strings"></a></P>
88 <br><b>
89 Validity of UTF-8 strings
90 </b><br>
91 <P>
92 When you set the PCRE_UTF8 flag, the byte strings passed as patterns and
93 subjects are (by default) checked for validity on entry to the relevant
94 functions. The entire string is checked before any other processing takes
95 place. From release 7.3 of PCRE, the check is according the rules of RFC 3629,
96 which are themselves derived from the Unicode specification. Earlier releases
97 of PCRE followed the rules of RFC 2279, which allows the full range of 31-bit
98 values (0 to 0x7FFFFFFF). The current check allows only values in the range U+0
99 to U+10FFFF, excluding the surrogate area, and the non-characters.
100 </P>
101 <P>
102 Excluded code points are the "Surrogate Area" of Unicode. They are reserved
103 for use by UTF-16, where they are used in pairs to encode codepoints with
104 values greater than 0xFFFF. The code points that are encoded by UTF-16 pairs
105 are available independently in the UTF-8 encoding. (In other words, the whole
106 surrogate thing is a fudge for UTF-16 which unfortunately messes up UTF-8.)
107 </P>
108 <P>
109 Also excluded are the "Non-Characters" code points, which are U+FDD0 to U+FDEF
110 and the last two code points in each plane, U+??FFFE and U+??FFFF.
111 </P>
112 <P>
113 If an invalid UTF-8 string is passed to PCRE, an error return is given. At
114 compile time, the only additional information is the offset to the first byte
115 of the failing character. The run-time functions <b>pcre_exec()</b> and
116 <b>pcre_dfa_exec()</b> also pass back this information, as well as a more
117 detailed reason code if the caller has provided memory in which to do this.
118 </P>
119 <P>
120 In some situations, you may already know that your strings are valid, and
121 therefore want to skip these checks in order to improve performance, for
122 example in the case of a long subject string that is being scanned repeatedly
123 with different patterns. If you set the PCRE_NO_UTF8_CHECK flag at compile time
124 or at run time, PCRE assumes that the pattern or subject it is given
125 (respectively) contains only valid UTF-8 codes. In this case, it does not
126 diagnose an invalid UTF-8 string.
127 </P>
128 <P>
129 If you pass an invalid UTF-8 string when PCRE_NO_UTF8_CHECK is set, what
130 happens depends on why the string is invalid. If the string conforms to the
131 "old" definition of UTF-8 (RFC 2279), it is processed as a string of characters
132 in the range 0 to 0x7FFFFFFF by <b>pcre_dfa_exec()</b> and the interpreted
133 version of <b>pcre_exec()</b>. In other words, apart from the initial validity
134 test, these functions (when in UTF-8 mode) handle strings according to the more
135 liberal rules of RFC 2279. However, the just-in-time (JIT) optimization for
136 <b>pcre_exec()</b> supports only RFC 3629. If you are using JIT optimization, or
137 if the string does not even conform to RFC 2279, the result is undefined. Your
138 program may crash.
139 </P>
140 <P>
141 If you want to process strings of values in the full range 0 to 0x7FFFFFFF,
142 encoded in a UTF-8-like manner as per the old RFC, you can set
143 PCRE_NO_UTF8_CHECK to bypass the more restrictive test. However, in this
144 situation, you will have to apply your own validity check, and avoid the use of
145 JIT optimization.
146 <a name="utf16strings"></a></P>
147 <br><b>
148 Validity of UTF-16 strings
149 </b><br>
150 <P>
151 When you set the PCRE_UTF16 flag, the strings of 16-bit data units that are
152 passed as patterns and subjects are (by default) checked for validity on entry
153 to the relevant functions. Values other than those in the surrogate range
154 U+D800 to U+DFFF are independent code points. Values in the surrogate range
155 must be used in pairs in the correct manner.
156 </P>
157 <P>
158 Excluded are the "Non-Characters" code points, which are U+FDD0 to U+FDEF
159 and the last two code points in each plane, U+??FFFE and U+??FFFF.
160 </P>
161 <P>
162 If an invalid UTF-16 string is passed to PCRE, an error return is given. At
163 compile time, the only additional information is the offset to the first data
164 unit of the failing character. The run-time functions <b>pcre16_exec()</b> and
165 <b>pcre16_dfa_exec()</b> also pass back this information, as well as a more
166 detailed reason code if the caller has provided memory in which to do this.
167 </P>
168 <P>
169 In some situations, you may already know that your strings are valid, and
170 therefore want to skip these checks in order to improve performance. If you set
171 the PCRE_NO_UTF16_CHECK flag at compile time or at run time, PCRE assumes that
172 the pattern or subject it is given (respectively) contains only valid UTF-16
173 sequences. In this case, it does not diagnose an invalid UTF-16 string.
174 <a name="utf32strings"></a></P>
175 <br><b>
176 Validity of UTF-32 strings
177 </b><br>
178 <P>
179 When you set the PCRE_UTF32 flag, the strings of 32-bit data units that are
180 passed as patterns and subjects are (by default) checked for validity on entry
181 to the relevant functions. This check allows only values in the range U+0
182 to U+10FFFF, excluding the surrogate area U+D800 to U+DFFF, and the
183 "Non-Characters" code points, which are U+FDD0 to U+FDEF and the last two
184 characters in each plane, U+??FFFE and U+??FFFF.
185 </P>
186 <P>
187 If an invalid UTF-32 string is passed to PCRE, an error return is given. At
188 compile time, the only additional information is the offset to the first data
189 unit of the failing character. The run-time functions <b>pcre32_exec()</b> and
190 <b>pcre32_dfa_exec()</b> also pass back this information, as well as a more
191 detailed reason code if the caller has provided memory in which to do this.
192 </P>
193 <P>
194 In some situations, you may already know that your strings are valid, and
195 therefore want to skip these checks in order to improve performance. If you set
196 the PCRE_NO_UTF32_CHECK flag at compile time or at run time, PCRE assumes that
197 the pattern or subject it is given (respectively) contains only valid UTF-32
198 sequences. In this case, it does not diagnose an invalid UTF-32 string.
199 </P>
200 <P>
201 UTF-32 only uses the lowest 21 bits of the 32 bit characters, and the
202 application may use the upper bits for internal purposes. To allow you to
203 pass these strings to PCRE unmodified (thus avoiding the costly operation of
204 creating a copy of the string with the upper bits masked), PCRE accepts
205 these 32-bit character strings as-is, but only uses the lowest 21 bits for
206 matching, if you pass the PCRE_NO_UTF32_CHECK flag to <b>pcre32_exec()</b> and
207 <b>pcre32_dfa_exec()</b>. However, in this situation, you will have to apply
208 your own validity check, and avoid the use of JIT optimization.
209 (The latter restriction may be lifter in a later version of PCRE.)
210 </P>
211 <br><b>
212 General comments about UTF modes
213 </b><br>
214 <P>
215 1. Codepoints less than 256 can be specified by either braced or unbraced
216 hexadecimal escape sequences (for example, \x{b3} or \xb3). Larger values
217 have to use braced sequences.
218 </P>
219 <P>
220 2. Octal numbers up to \777 are recognized, and in UTF-8 mode, they match
221 two-byte characters for values greater than \177.
222 </P>
223 <P>
224 3. Repeat quantifiers apply to complete UTF characters, not to individual
225 data units, for example: \x{100}{3}.
226 </P>
227 <P>
228 4. The dot metacharacter matches one UTF character instead of a single data
229 unit.
230 </P>
231 <P>
232 5. The escape sequence \C can be used to match a single byte in UTF-8 mode, or
233 a single 16-bit data unit in UTF-16 mode, or a single 32-bit data unit in
234 UTF-32 mode, but its use can lead to some strange effects because it breaks up
235 multi-unit characters (see the description of \C in the
236 <a href="pcrepattern.html"><b>pcrepattern</b></a>
237 documentation). The use of \C is not supported in the alternative matching
238 function <b>pcre[16|32]_dfa_exec()</b>, nor is it supported in UTF mode by the JIT
239 optimization of <b>pcre[16|32]_exec()</b>. If JIT optimization is requested for a
240 UTF pattern that contains \C, it will not succeed, and so the matching will
241 be carried out by the normal interpretive function.
242 </P>
243 <P>
244 6. The character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly
245 test characters of any code value, but, by default, the characters that PCRE
246 recognizes as digits, spaces, or word characters remain the same set as in
247 non-UTF mode, all with values less than 256. This remains true even when PCRE
248 is built to include Unicode property support, because to do otherwise would
249 slow down PCRE in many common cases. Note in particular that this applies to
250 \b and \B, because they are defined in terms of \w and \W. If you really
251 want to test for a wider sense of, say, "digit", you can use explicit Unicode
252 property tests such as \p{Nd}. Alternatively, if you set the PCRE_UCP option,
253 the way that the character escapes work is changed so that Unicode properties
254 are used to determine which characters match. There are more details in the
255 section on
256 <a href="pcrepattern.html#genericchartypes">generic character types</a>
257 in the
258 <a href="pcrepattern.html"><b>pcrepattern</b></a>
259 documentation.
260 </P>
261 <P>
262 7. Similarly, characters that match the POSIX named character classes are all
263 low-valued characters, unless the PCRE_UCP option is set.
264 </P>
265 <P>
266 8. However, the horizontal and vertical white space matching escapes (\h, \H,
267 \v, and \V) do match all the appropriate Unicode characters, whether or not
268 PCRE_UCP is set.
269 </P>
270 <P>
271 9. Case-insensitive matching applies only to characters whose values are less
272 than 128, unless PCRE is built with Unicode property support. A few Unicode
273 characters such as Greek sigma have more than two codepoints that are
274 case-equivalent. Up to and including PCRE release 8.31, only one-to-one case
275 mappings were supported, but later releases (with Unicode property support) do
276 treat as case-equivalent all versions of characters such as Greek sigma.
277 </P>
278 <br><b>
279 AUTHOR
280 </b><br>
281 <P>
282 Philip Hazel
283 <br>
284 University Computing Service
285 <br>
286 Cambridge CB2 3QH, England.
287 <br>
288 </P>
289 <br><b>
290 REVISION
291 </b><br>
292 <P>
293 Last updated: 25 September 2012
294 <br>
295 Copyright &copy; 1997-2012 University of Cambridge.
296 <br>
297 <p>
298 Return to the <a href="index.html">PCRE index page</a>.
299 </p>

  ViewVC Help
Powered by ViewVC 1.1.5