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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5