1PCRE(3)                    Library Functions Manual                    PCRE(3)
2
3
4

NAME

6       PCRE - Perl-compatible regular expressions
7
8       #include <pcre.h>
9

PCRE 16-BIT API BASIC FUNCTIONS

11
12       pcre16 *pcre16_compile(PCRE_SPTR16 pattern, int options,
13            const char **errptr, int *erroffset,
14            const unsigned char *tableptr);
15
16       pcre16 *pcre16_compile2(PCRE_SPTR16 pattern, int options,
17            int *errorcodeptr,
18            const char **errptr, int *erroffset,
19            const unsigned char *tableptr);
20
21       pcre16_extra *pcre16_study(const pcre16 *code, int options,
22            const char **errptr);
23
24       void pcre16_free_study(pcre16_extra *extra);
25
26       int pcre16_exec(const pcre16 *code, const pcre16_extra *extra,
27            PCRE_SPTR16 subject, int length, int startoffset,
28            int options, int *ovector, int ovecsize);
29
30       int pcre16_dfa_exec(const pcre16 *code, const pcre16_extra *extra,
31            PCRE_SPTR16 subject, int length, int startoffset,
32            int options, int *ovector, int ovecsize,
33            int *workspace, int wscount);
34

PCRE 16-BIT API STRING EXTRACTION FUNCTIONS

36
37       int pcre16_copy_named_substring(const pcre16 *code,
38            PCRE_SPTR16 subject, int *ovector,
39            int stringcount, PCRE_SPTR16 stringname,
40            PCRE_UCHAR16 *buffer, int buffersize);
41
42       int pcre16_copy_substring(PCRE_SPTR16 subject, int *ovector,
43            int stringcount, int stringnumber, PCRE_UCHAR16 *buffer,
44            int buffersize);
45
46       int pcre16_get_named_substring(const pcre16 *code,
47            PCRE_SPTR16 subject, int *ovector,
48            int stringcount, PCRE_SPTR16 stringname,
49            PCRE_SPTR16 *stringptr);
50
51       int pcre16_get_stringnumber(const pcre16 *code,
52            PCRE_SPTR16 name);
53
54       int pcre16_get_stringtable_entries(const pcre16 *code,
55            PCRE_SPTR16 name, PCRE_UCHAR16 **first, PCRE_UCHAR16 **last);
56
57       int pcre16_get_substring(PCRE_SPTR16 subject, int *ovector,
58            int stringcount, int stringnumber,
59            PCRE_SPTR16 *stringptr);
60
61       int pcre16_get_substring_list(PCRE_SPTR16 subject,
62            int *ovector, int stringcount, PCRE_SPTR16 **listptr);
63
64       void pcre16_free_substring(PCRE_SPTR16 stringptr);
65
66       void pcre16_free_substring_list(PCRE_SPTR16 *stringptr);
67

PCRE 16-BIT API AUXILIARY FUNCTIONS

69
70       pcre16_jit_stack *pcre16_jit_stack_alloc(int startsize, int maxsize);
71
72       void pcre16_jit_stack_free(pcre16_jit_stack *stack);
73
74       void pcre16_assign_jit_stack(pcre16_extra *extra,
75            pcre16_jit_callback callback, void *data);
76
77       const unsigned char *pcre16_maketables(void);
78
79       int pcre16_fullinfo(const pcre16 *code, const pcre16_extra *extra,
80            int what, void *where);
81
82       int pcre16_refcount(pcre16 *code, int adjust);
83
84       int pcre16_config(int what, void *where);
85
86       const char *pcre16_version(void);
87
88       int pcre16_pattern_to_host_byte_order(pcre16 *code,
89            pcre16_extra *extra, const unsigned char *tables);
90

PCRE 16-BIT API INDIRECTED FUNCTIONS

92
93       void *(*pcre16_malloc)(size_t);
94
95       void (*pcre16_free)(void *);
96
97       void *(*pcre16_stack_malloc)(size_t);
98
99       void (*pcre16_stack_free)(void *);
100
101       int (*pcre16_callout)(pcre16_callout_block *);
102

PCRE 16-BIT API 16-BIT-ONLY FUNCTION

104
105       int pcre16_utf16_to_host_byte_order(PCRE_UCHAR16 *output,
106            PCRE_SPTR16 input, int length, int *byte_order,
107            int keep_boms);
108

THE PCRE 16-BIT LIBRARY

110
111       Starting  with  release  8.30, it is possible to compile a PCRE library
112       that supports 16-bit character strings, including  UTF-16  strings,  as
113       well  as  or instead of the original 8-bit library. The majority of the
114       work to make  this  possible  was  done  by  Zoltan  Herczeg.  The  two
115       libraries contain identical sets of functions, used in exactly the same
116       way. Only the names of the functions and the data types of their  argu‐
117       ments  and results are different. To avoid over-complication and reduce
118       the documentation maintenance load,  most  of  the  PCRE  documentation
119       describes  the  8-bit  library,  with only occasional references to the
120       16-bit library. This page describes what is different when you use  the
121       16-bit library.
122
123       WARNING:  A  single  application can be linked with both libraries, but
124       you must take care when processing any particular pattern to use  func‐
125       tions  from  just one library. For example, if you want to study a pat‐
126       tern that was compiled with  pcre16_compile(),  you  must  do  so  with
127       pcre16_study(), not pcre_study(), and you must free the study data with
128       pcre16_free_study().
129

THE HEADER FILE

131
132       There is only one header file, pcre.h. It contains prototypes  for  all
133       the functions in all libraries, as well as definitions of flags, struc‐
134       tures, error codes, etc.
135

THE LIBRARY NAME

137
138       In Unix-like systems, the 16-bit library is called libpcre16,  and  can
139       normally  be  accesss  by adding -lpcre16 to the command for linking an
140       application that uses PCRE.
141

STRING TYPES

143
144       In the 8-bit library, strings are passed to PCRE library  functions  as
145       vectors  of  bytes  with  the  C  type "char *". In the 16-bit library,
146       strings are passed as vectors of unsigned 16-bit quantities. The  macro
147       PCRE_UCHAR16  specifies  an  appropriate  data type, and PCRE_SPTR16 is
148       defined as "const PCRE_UCHAR16 *". In very  many  environments,  "short
149       int" is a 16-bit data type. When PCRE is built, it defines PCRE_UCHAR16
150       as "unsigned short int", but checks that it really  is  a  16-bit  data
151       type.  If  it is not, the build fails with an error message telling the
152       maintainer to modify the definition appropriately.
153

STRUCTURE TYPES

155
156       The types of the opaque structures that are used  for  compiled  16-bit
157       patterns  and  JIT stacks are pcre16 and pcre16_jit_stack respectively.
158       The  type  of  the  user-accessible  structure  that  is  returned   by
159       pcre16_study()  is  pcre16_extra, and the type of the structure that is
160       used for passing data to a callout  function  is  pcre16_callout_block.
161       These structures contain the same fields, with the same names, as their
162       8-bit counterparts. The only difference is that pointers  to  character
163       strings are 16-bit instead of 8-bit types.
164

16-BIT FUNCTIONS

166
167       For  every function in the 8-bit library there is a corresponding func‐
168       tion in the 16-bit library with a name that starts with pcre16_ instead
169       of  pcre_.  The  prototypes are listed above. In addition, there is one
170       extra function, pcre16_utf16_to_host_byte_order(). This  is  a  utility
171       function  that converts a UTF-16 character string to host byte order if
172       necessary. The other 16-bit  functions  expect  the  strings  they  are
173       passed to be in host byte order.
174
175       The input and output arguments of pcre16_utf16_to_host_byte_order() may
176       point to the same address, that is, conversion in place  is  supported.
177       The output buffer must be at least as long as the input.
178
179       The  length  argument  specifies the number of 16-bit data units in the
180       input string; a negative value specifies a zero-terminated string.
181
182       If byte_order is NULL, it is assumed that the string starts off in host
183       byte  order. This may be changed by byte-order marks (BOMs) anywhere in
184       the string (commonly as the first character).
185
186       If byte_order is not NULL, a non-zero value of the integer to which  it
187       points  means  that  the input starts off in host byte order, otherwise
188       the opposite order is assumed. Again, BOMs in  the  string  can  change
189       this. The final byte order is passed back at the end of processing.
190
191       If  keep_boms  is  not  zero,  byte-order  mark characters (0xfeff) are
192       copied into the output string. Otherwise they are discarded.
193
194       The result of the function is the number of 16-bit  units  placed  into
195       the  output  buffer,  including  the  zero terminator if the string was
196       zero-terminated.
197

SUBJECT STRING OFFSETS

199
200       The lengths and starting offsets of subject strings must  be  specified
201       in  16-bit  data units, and the offsets within subject strings that are
202       returned by the matching functions are in also 16-bit units rather than
203       bytes.
204

NAMED SUBPATTERNS

206
207       The  name-to-number translation table that is maintained for named sub‐
208       patterns uses 16-bit characters.  The  pcre16_get_stringtable_entries()
209       function returns the length of each entry in the table as the number of
210       16-bit data units.
211

OPTION NAMES

213
214       There   are   two   new   general   option   names,   PCRE_UTF16    and
215       PCRE_NO_UTF16_CHECK,     which     correspond    to    PCRE_UTF8    and
216       PCRE_NO_UTF8_CHECK in the 8-bit library. In  fact,  these  new  options
217       define  the  same bits in the options word. There is a discussion about
218       the validity of UTF-16 strings in the pcreunicode page.
219
220       For the pcre16_config() function there is an  option  PCRE_CONFIG_UTF16
221       that  returns  1  if UTF-16 support is configured, otherwise 0. If this
222       option  is  given  to  pcre_config()  or  pcre32_config(),  or  if  the
223       PCRE_CONFIG_UTF8  or  PCRE_CONFIG_UTF32  option is given to pcre16_con‐
224       fig(), the result is the PCRE_ERROR_BADOPTION error.
225

CHARACTER CODES

227
228       In 16-bit mode, when  PCRE_UTF16  is  not  set,  character  values  are
229       treated in the same way as in 8-bit, non UTF-8 mode, except, of course,
230       that they can range from 0 to 0xffff instead of 0  to  0xff.  Character
231       types  for characters less than 0xff can therefore be influenced by the
232       locale in the same way as before.  Characters greater  than  0xff  have
233       only one case, and no "type" (such as letter or digit).
234
235       In  UTF-16  mode,  the  character  code  is  Unicode, in the range 0 to
236       0x10ffff, with the exception of values in the range  0xd800  to  0xdfff
237       because  those  are "surrogate" values that are used in pairs to encode
238       values greater than 0xffff.
239
240       A UTF-16 string can indicate its endianness by special code knows as  a
241       byte-order mark (BOM). The PCRE functions do not handle this, expecting
242       strings  to  be  in  host  byte  order.  A  utility   function   called
243       pcre16_utf16_to_host_byte_order()  is  provided  to help with this (see
244       above).
245

ERROR NAMES

247
248       The errors PCRE_ERROR_BADUTF16_OFFSET and PCRE_ERROR_SHORTUTF16  corre‐
249       spond  to  their  8-bit  counterparts.  The error PCRE_ERROR_BADMODE is
250       given when a compiled pattern is passed to a  function  that  processes
251       patterns  in  the  other  mode, for example, if a pattern compiled with
252       pcre_compile() is passed to pcre16_exec().
253
254       There are new error codes whose names  begin  with  PCRE_UTF16_ERR  for
255       invalid  UTF-16  strings,  corresponding to the PCRE_UTF8_ERR codes for
256       UTF-8 strings that are described in the section entitled "Reason  codes
257       for  invalid UTF-8 strings" in the main pcreapi page. The UTF-16 errors
258       are:
259
260         PCRE_UTF16_ERR1  Missing low surrogate at end of string
261         PCRE_UTF16_ERR2  Invalid low surrogate follows high surrogate
262         PCRE_UTF16_ERR3  Isolated low surrogate
263         PCRE_UTF16_ERR4  Non-character
264

ERROR TEXTS

266
267       If there is an error while compiling a pattern, the error text that  is
268       passed  back by pcre16_compile() or pcre16_compile2() is still an 8-bit
269       character string, zero-terminated.
270

CALLOUTS

272
273       The subject and mark fields in the callout block that is  passed  to  a
274       callout function point to 16-bit vectors.
275

TESTING

277
278       The  pcretest  program continues to operate with 8-bit input and output
279       files, but it can be used for testing the 16-bit library. If it is  run
280       with the command line option -16, patterns and subject strings are con‐
281       verted from 8-bit to 16-bit before being passed to PCRE, and the 16-bit
282       library  functions  are used instead of the 8-bit ones. Returned 16-bit
283       strings are converted to 8-bit for output. If both the  8-bit  and  the
284       32-bit libraries were not compiled, pcretest defaults to 16-bit and the
285       -16 option is ignored.
286
287       When PCRE is being built, the RunTest script that is  called  by  "make
288       check"  uses  the  pcretest  -C  option to discover which of the 8-bit,
289       16-bit and 32-bit libraries has been built, and runs the  tests  appro‐
290       priately.
291

NOT SUPPORTED IN 16-BIT MODE

293
294       Not all the features of the 8-bit library are available with the 16-bit
295       library. The C++ and POSIX wrapper functions  support  only  the  8-bit
296       library, and the pcregrep program is at present 8-bit only.
297

AUTHOR

299
300       Philip Hazel
301       University Computing Service
302       Cambridge CB2 3QH, England.
303

REVISION

305
306       Last updated: 12 May 2013
307       Copyright (c) 1997-2013 University of Cambridge.
308
309
310
311PCRE 8.33                         12 May 2013                          PCRE(3)
Impressum