ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1055 - (show annotations)
Tue Oct 16 15:53:30 2012 UTC (7 years ago) by chpe
File size: 13117 byte(s)
pcre32: Add 32-bit library

Create libpcre32 that operates on 32-bit characters (UTF-32).

This turned out to be surprisingly simple after the UTF-16 support
was introduced; mostly just extra ifdefs and adjusting and adding
some tests.
1 .TH PCRE 3 "24 June 2012" "PCRE 8.31"
3 PCRE - Perl-compatible regular expressions
4 .sp
5 .B #include <pcre.h>
6 .
7 .
9 .rs
10 .sp
11 .SM
12 .B pcre32 *pcre32_compile(PCRE_SPTR32 \fIpattern\fP, int \fIoptions\fP,
13 .ti +5n
14 .B const char **\fIerrptr\fP, int *\fIerroffset\fP,
15 .ti +5n
16 .B const unsigned char *\fItableptr\fP);
17 .PP
18 .B pcre32 *pcre32_compile2(PCRE_SPTR32 \fIpattern\fP, int \fIoptions\fP,
19 .ti +5n
20 .B int *\fIerrorcodeptr\fP,
21 .ti +5n
22 .B const char **\fIerrptr\fP, int *\fIerroffset\fP,
23 .ti +5n
24 .B const unsigned char *\fItableptr\fP);
25 .PP
26 .B pcre32_extra *pcre32_study(const pcre32 *\fIcode\fP, int \fIoptions\fP,
27 .ti +5n
28 .B const char **\fIerrptr\fP);
29 .PP
30 .B void pcre32_free_study(pcre32_extra *\fIextra\fP);
31 .PP
32 .B int pcre32_exec(const pcre32 *\fIcode\fP, "const pcre32_extra *\fIextra\fP,"
33 .ti +5n
34 .B "PCRE_SPTR32 \fIsubject\fP," int \fIlength\fP, int \fIstartoffset\fP,
35 .ti +5n
36 .B int \fIoptions\fP, int *\fIovector\fP, int \fIovecsize\fP);
37 .PP
38 .B int pcre32_dfa_exec(const pcre32 *\fIcode\fP, "const pcre32_extra *\fIextra\fP,"
39 .ti +5n
40 .B "PCRE_SPTR32 \fIsubject\fP," int \fIlength\fP, int \fIstartoffset\fP,
41 .ti +5n
42 .B int \fIoptions\fP, int *\fIovector\fP, int \fIovecsize\fP,
43 .ti +5n
44 .B int *\fIworkspace\fP, int \fIwscount\fP);
45 .
46 .
48 .rs
49 .sp
50 .B int pcre32_copy_named_substring(const pcre32 *\fIcode\fP,
51 .ti +5n
52 .B PCRE_SPTR32 \fIsubject\fP, int *\fIovector\fP,
53 .ti +5n
54 .B int \fIstringcount\fP, PCRE_SPTR32 \fIstringname\fP,
55 .ti +5n
56 .B PCRE_UCHAR32 *\fIbuffer\fP, int \fIbuffersize\fP);
57 .PP
58 .B int pcre32_copy_substring(PCRE_SPTR32 \fIsubject\fP, int *\fIovector\fP,
59 .ti +5n
60 .B int \fIstringcount\fP, int \fIstringnumber\fP, PCRE_UCHAR32 *\fIbuffer\fP,
61 .ti +5n
62 .B int \fIbuffersize\fP);
63 .PP
64 .B int pcre32_get_named_substring(const pcre32 *\fIcode\fP,
65 .ti +5n
66 .B PCRE_SPTR32 \fIsubject\fP, int *\fIovector\fP,
67 .ti +5n
68 .B int \fIstringcount\fP, PCRE_SPTR32 \fIstringname\fP,
69 .ti +5n
70 .B PCRE_SPTR32 *\fIstringptr\fP);
71 .PP
72 .B int pcre32_get_stringnumber(const pcre32 *\fIcode\fP,
73 .ti +5n
74 .B PCRE_SPTR32 \fIname\fP);
75 .PP
76 .B int pcre32_get_stringtable_entries(const pcre32 *\fIcode\fP,
77 .ti +5n
78 .B PCRE_SPTR32 \fIname\fP, PCRE_UCHAR32 **\fIfirst\fP, PCRE_UCHAR32 **\fIlast\fP);
79 .PP
80 .B int pcre32_get_substring(PCRE_SPTR32 \fIsubject\fP, int *\fIovector\fP,
81 .ti +5n
82 .B int \fIstringcount\fP, int \fIstringnumber\fP,
83 .ti +5n
84 .B PCRE_SPTR32 *\fIstringptr\fP);
85 .PP
86 .B int pcre32_get_substring_list(PCRE_SPTR32 \fIsubject\fP,
87 .ti +5n
88 .B int *\fIovector\fP, int \fIstringcount\fP, "PCRE_SPTR32 **\fIlistptr\fP);"
89 .PP
90 .B void pcre32_free_substring(PCRE_SPTR32 \fIstringptr\fP);
91 .PP
92 .B void pcre32_free_substring_list(PCRE_SPTR32 *\fIstringptr\fP);
93 .
94 .
96 .rs
97 .sp
98 .B pcre32_jit_stack *pcre32_jit_stack_alloc(int \fIstartsize\fP, int \fImaxsize\fP);
99 .PP
100 .B void pcre32_jit_stack_free(pcre32_jit_stack *\fIstack\fP);
101 .PP
102 .B void pcre32_assign_jit_stack(pcre32_extra *\fIextra\fP,
103 .ti +5n
104 .B pcre32_jit_callback \fIcallback\fP, void *\fIdata\fP);
105 .PP
106 .B const unsigned char *pcre32_maketables(void);
107 .PP
108 .B int pcre32_fullinfo(const pcre32 *\fIcode\fP, "const pcre32_extra *\fIextra\fP,"
109 .ti +5n
110 .B int \fIwhat\fP, void *\fIwhere\fP);
111 .PP
112 .B int pcre32_refcount(pcre32 *\fIcode\fP, int \fIadjust\fP);
113 .PP
114 .B int pcre32_config(int \fIwhat\fP, void *\fIwhere\fP);
115 .PP
116 .B const char *pcre32_version(void);
117 .PP
118 .B int pcre32_pattern_to_host_byte_order(pcre32 *\fIcode\fP,
119 .ti +5n
120 .B pcre32_extra *\fIextra\fP, const unsigned char *\fItables\fP);
121 .
122 .
124 .rs
125 .sp
126 .B void *(*pcre32_malloc)(size_t);
127 .PP
128 .B void (*pcre32_free)(void *);
129 .PP
130 .B void *(*pcre32_stack_malloc)(size_t);
131 .PP
132 .B void (*pcre32_stack_free)(void *);
133 .PP
134 .B int (*pcre32_callout)(pcre32_callout_block *);
135 .
136 .
138 .rs
139 .sp
140 .B int pcre32_utf32_to_host_byte_order(PCRE_UCHAR32 *\fIoutput\fP,
141 .ti +5n
142 .B PCRE_SPTR32 \fIinput\fP, int \fIlength\fP, int *\fIbyte_order\fP,
143 .ti +5n
144 .B int \fIkeep_boms\fP);
145 .
146 .
148 .rs
149 .sp
150 Starting with release 8.FIXME, it is possible to compile a PCRE library that
151 supports 32-bit character strings, including UTF-32 strings, as well as or
152 instead of the original 8-bit library. The majority of the work to make this
153 possible was done by Zoltan Herczeg for the 16-bit library. All three libraries
154 contain identical sets of functions, used in exactly the same way. Only the
155 names of the functions and the data types of their arguments and results are
156 different. To avoid over-complication and reduce the documentation maintenance
157 load, most of the PCRE documentation describes the 8-bit library, with only
158 occasional references to the 16-bit and 32-bit libraries. This page describes
159 what is different when you use the 32-bit library.
160 .P
161 WARNING: A single application can be linked with all or any of the three
162 libraries, but you must take care when processing any particular pattern
163 to use functions from just one library. For example, if you want to study
164 a pattern that was compiled with \fBpcre32_compile()\fP, you must do so
165 with \fBpcre32_study()\fP, not \fBpcre_study()\fP, and you must free the
166 study data with \fBpcre32_free_study()\fP.
167 .
168 .
170 .rs
171 .sp
172 There is only one header file, \fBpcre.h\fP. It contains prototypes for all the
173 functions in both libraries, as well as definitions of flags, structures, error
174 codes, etc.
175 .
176 .
178 .rs
179 .sp
180 In Unix-like systems, the 32-bit library is called \fBlibpcre32\fP, and can
181 normally be accesss by adding \fB-lpcre32\fP to the command for linking an
182 application that uses PCRE.
183 .
184 .
186 .rs
187 .sp
188 In the 8-bit library, strings are passed to PCRE library functions as vectors
189 of bytes with the C type "char *". In the 32-bit library, strings are passed as
190 vectors of unsigned 32-bit quantities. The macro PCRE_UCHAR32 specifies an
191 appropriate data type, and PCRE_SPTR32 is defined as "const PCRE_UCHAR32 *". In
192 very many environments, "unsigned int" is a 32-bit data type. When PCRE is built,
193 it defines PCRE_UCHAR32 as "unsigned int", but checks that it really is a 32-bit
194 data type. If it is not, the build fails with an error message telling the
195 maintainer to modify the definition appropriately.
196 .
197 .
199 .rs
200 .sp
201 The types of the opaque structures that are used for compiled 32-bit patterns
202 and JIT stacks are \fBpcre32\fP and \fBpcre32_jit_stack\fP respectively. The
203 type of the user-accessible structure that is returned by \fBpcre32_study()\fP
204 is \fBpcre32_extra\fP, and the type of the structure that is used for passing
205 data to a callout function is \fBpcre32_callout_block\fP. These structures
206 contain the same fields, with the same names, as their 8-bit counterparts. The
207 only difference is that pointers to character strings are 32-bit instead of
208 8-bit types.
209 .
210 .
212 .rs
213 .sp
214 For every function in the 8-bit library there is a corresponding function in
215 the 32-bit library with a name that starts with \fBpcre32_\fP instead of
216 \fBpcre_\fP. The prototypes are listed above. In addition, there is one extra
217 function, \fBpcre32_utf32_to_host_byte_order()\fP. This is a utility function
218 that converts a UTF-32 character string to host byte order if necessary. The
219 other 32-bit functions expect the strings they are passed to be in host byte
220 order.
221 .P
222 The \fIinput\fP and \fIoutput\fP arguments of
223 \fBpcre32_utf32_to_host_byte_order()\fP may point to the same address, that is,
224 conversion in place is supported. The output buffer must be at least as long as
225 the input.
226 .P
227 The \fIlength\fP argument specifies the number of 32-bit data units in the
228 input string; a negative value specifies a zero-terminated string.
229 .P
230 If \fIbyte_order\fP is NULL, it is assumed that the string starts off in host
231 byte order. This may be changed by byte-order marks (BOMs) anywhere in the
232 string (commonly as the first character).
233 .P
234 If \fIbyte_order\fP is not NULL, a non-zero value of the integer to which it
235 points means that the input starts off in host byte order, otherwise the
236 opposite order is assumed. Again, BOMs in the string can change this. The final
237 byte order is passed back at the end of processing.
238 .P
239 If \fIkeep_boms\fP is not zero, byte-order mark characters (0xfeff) are copied
240 into the output string. Otherwise they are discarded.
241 .P
242 The result of the function is the number of 32-bit units placed into the output
243 buffer, including the zero terminator if the string was zero-terminated.
244 .
245 .
247 .rs
248 .sp
249 The offsets within subject strings that are returned by the matching functions
250 are in 32-bit units rather than bytes.
251 .
252 .
254 .rs
255 .sp
256 The name-to-number translation table that is maintained for named subpatterns
257 uses 32-bit characters. The \fBpcre32_get_stringtable_entries()\fP function
258 returns the length of each entry in the table as the number of 32-bit data
259 units.
260 .
261 .
263 .rs
264 .sp
265 There are two new general option names, PCRE_UTF32 and PCRE_NO_UTF32_CHECK,
266 which correspond to PCRE_UTF8 and PCRE_NO_UTF8_CHECK in the 8-bit library. In
267 fact, these new options define the same bits in the options word. There is a
268 discussion about the
269 .\" HTML <a href="pcreunicode.html#utf32strings">
270 .\" </a>
271 validity of UTF-32 strings
272 .\"
273 in the
274 .\" HREF
275 \fBpcreunicode\fP
276 .\"
277 page.
278 .P
279 For the \fBpcre32_config()\fP function there is an option PCRE_CONFIG_UTF32
280 that returns 1 if UTF-32 support is configured, otherwise 0. If this option is
281 given to \fBpcre_config()\fP or \fBpcre16_config()\fP, or if the
282 PCRE_CONFIG_UTF8 or PCRE_CONFIG_UTF16 option is given to \fBpcre32_config()\fP,
283 the result is the PCRE_ERROR_BADOPTION error.
284 .
285 .
287 .rs
288 .sp
289 In 32-bit mode, when PCRE_UTF32 is not set, character values are treated in the
290 same way as in 8-bit, non UTF-8 mode, except, of course, that they can range
291 from 0 to 0x7fffffff instead of 0 to 0xff. Character types for characters less
292 than 0xff can therefore be influenced by the locale in the same way as before.
293 Characters greater than 0xff have only one case, and no "type" (such as letter
294 or digit).
295 .P
296 In UTF-32 mode, the character code is Unicode, in the range 0 to 0x10ffff, with
297 the exception of values in the range 0xd800 to 0xdfff because those are
298 "surrogate" values that are ill-formed in UTF-32.
299 .P
300 A UTF-32 string can indicate its endianness by special code knows as a
301 byte-order mark (BOM). The PCRE functions do not handle this, expecting strings
302 to be in host byte order. A utility function called
303 \fBpcre32_utf32_to_host_byte_order()\fP is provided to help with this (see
304 above).
305 .
306 .
308 .rs
309 .sp
310 The error PCRE_ERROR_BADUTF32_OFFSET correspond to its 8-bit counterpart.
311 The error PCRE_ERROR_BADMODE is given when a compiled
312 pattern is passed to a function that processes patterns in the other
313 mode, for example, if a pattern compiled with \fBpcre_compile()\fP is passed to
314 \fBpcre32_exec()\fP.
315 .P
316 There are new error codes whose names begin with PCRE_UTF32_ERR for invalid
317 UTF-32 strings, corresponding to the PCRE_UTF8_ERR codes for UTF-8 strings that
318 are described in the section entitled
319 .\" HTML <a href="pcreapi.html#badutf8reasons">
320 .\" </a>
321 "Reason codes for invalid UTF-8 strings"
322 .\"
323 in the main
324 .\" HREF
325 \fBpcreapi\fP
326 .\"
327 page. The UTF-32 errors are:
328 .sp
329 PCRE_UTF32_ERR1 Surrogate character (range from 0xd800 to 0xdfff)
330 PCRE_UTF32_ERR2 Invalid character 0xfffe
331 .
332 .
334 .rs
335 .sp
336 If there is an error while compiling a pattern, the error text that is passed
337 back by \fBpcre32_compile()\fP or \fBpcre32_compile2()\fP is still an 8-bit
338 character string, zero-terminated.
339 .
340 .
342 .rs
343 .sp
344 The \fIsubject\fP and \fImark\fP fields in the callout block that is passed to
345 a callout function point to 32-bit vectors.
346 .
347 .
349 .rs
350 .sp
351 The \fBpcretest\fP program continues to operate with 8-bit input and output
352 files, but it can be used for testing the 32-bit library. If it is run with the
353 command line option \fB-32\fP, patterns and subject strings are converted from
354 8-bit to 32-bit before being passed to PCRE, and the 32-bit library functions
355 are used instead of the 8-bit ones. Returned 32-bit strings are converted to
356 8-bit for output. If both the 8-bit and the 16-bit libraries were not compiled,
357 \fBpcretest\fP defaults to 32-bit and the \fB-32\fP option is ignored.
358 .P
359 When PCRE is being built, the \fBRunTest\fP script that is called by "make
360 check" uses the \fBpcretest\fP \fB-C\fP option to discover which of the 8-bit,
361 16-bit and 32-bit libraries has been built, and runs the tests appropriately.
362 .
363 .
365 .rs
366 .sp
367 Not all the features of the 8-bit library are available with the 32-bit
368 library. The C++ and POSIX wrapper functions support only the 8-bit library,
369 and the \fBpcregrep\fP program is at present 8-bit only.
370 .
371 .
373 .rs
374 .sp
375 .nf
376 Philip Hazel
377 University Computing Service
378 Cambridge CB2 3QH, England.
379 .fi
380 .
381 .
383 .rs
384 .sp
385 .nf
386 Last updated: 24 June 2012
387 Copyright (c) 1997-2012 University of Cambridge.
388 .fi

  ViewVC Help
Powered by ViewVC 1.1.5