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

  ViewVC Help
Powered by ViewVC 1.1.5