]>
git.saurik.com Git - apple/libc.git/blob - regex/TRE/lib/tre.h
2 tre.h - TRE public API definitions
4 This software is released under a BSD-style license.
5 See the file LICENSE for details and copyright.
12 #include "tre-config.h"
14 #ifdef HAVE_SYS_TYPES_H
15 #include <sys/types.h>
16 #endif /* HAVE_SYS_TYPES_H */
20 #endif /* HAVE_LIBUTF8_H */
22 #ifdef TRE_USE_SYSTEM_REGEX_H
23 /* Include the system regex.h to make TRE ABI compatible with the
25 #include TRE_SYSTEM_REGEX_H_PATH
26 #define tre_regcomp regcomp
27 #define tre_regexec regexec
28 #define tre_regerror regerror
29 #define tre_regfree regfree
32 #define tre_regaexec regaexec
33 #define tre_reganexec reganexec
34 #define tre_regawexec regawexec
35 #define tre_regawnexec regawnexec
36 #endif /* TRE_APPROX */
37 #define tre_regncomp regncomp
38 #define tre_regnexec regnexec
39 #define tre_regwcomp regwcomp
40 #define tre_regwexec regwexec
41 #define tre_regwncomp regwncomp
42 #define tre_regwnexec regwnexec
44 #define tre_regcomp_l regcomp_l
45 #define tre_regncomp_l regncomp_l
46 #define tre_regwcomp_l regwcomp_l
47 #define tre_regwncomp_l regwncomp_l
48 #endif /* TRE_USE_SYSTEM_REGEX_H */
54 #ifdef TRE_USE_SYSTEM_REGEX_H
60 #ifndef HAVE_REG_ERRCODE_T
61 typedef int reg_errcode_t
;
62 #endif /* !HAVE_REG_ERRCODE_T */
64 #if !defined(REG_NOSPEC) && !defined(REG_LITERAL)
65 #define REG_LITERAL 0x1000
68 /* Extra tre_regcomp() flags. */
71 #endif /* !REG_BASIC */
73 #define REG_LEFT_ASSOC (REG_LITERAL << 1)
74 #define REG_UNGREEDY (REG_LEFT_ASSOC << 1)
76 /* Extra tre_regexec() flags. */
77 #define REG_APPROX_MATCHER 0x1000
78 #define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
81 #define RE_MAGIC ((('r'^0200)<<8) | 'e')
83 #else /* !TRE_USE_SYSTEM_REGEX_H */
85 /* If the we're not using system regex.h, we need to define the
86 structs and enums ourselves. */
90 size_t re_nsub
; /* Number of parenthesized subexpressions. */
91 const void *re_endp
; /* regex string end pointer (REG_PEND) */
92 void *value
; /* For internal use only. */
102 REG_OK
= 0, /* No error. */
103 /* POSIX tre_regcomp() return error codes. (In the order listed in the
105 REG_NOMATCH
, /* No match. */
106 REG_BADPAT
, /* Invalid regexp. */
107 REG_ECOLLATE
, /* Unknown collating element. */
108 REG_ECTYPE
, /* Unknown character class name. */
109 REG_EESCAPE
, /* Trailing backslash. */
110 REG_ESUBREG
, /* Invalid back reference. */
111 REG_EBRACK
, /* "[]" imbalance */
112 REG_EPAREN
, /* "\(\)" or "()" imbalance */
113 REG_EBRACE
, /* "\{\}" or "{}" imbalance */
114 REG_BADBR
, /* Invalid content of {} */
115 REG_ERANGE
, /* Invalid use of range operator */
116 REG_ESPACE
, /* Out of memory. */
117 REG_BADRPT
, /* Invalid use of repetition operators. */
118 REG_INVARG
, /* Invalid argument, e.g. negative-length string */
119 REG_ILLSEQ
, /* illegal byte sequence (bad multibyte character) */
122 /* POSIX tre_regcomp() flags. */
123 #define REG_EXTENDED 1
124 #define REG_ICASE (REG_EXTENDED << 1)
125 #define REG_NEWLINE (REG_ICASE << 1)
126 #define REG_NOSUB (REG_NEWLINE << 1)
128 /* Extra tre_regcomp() flags. */
130 #define REG_LITERAL (REG_NOSUB << 1)
131 #define REG_LEFT_ASSOC (REG_LITERAL << 1)
132 #define REG_UNGREEDY (REG_LEFT_ASSOC << 1)
133 #define REG_PEND (REG_UNGREEDY << 1)
135 /* POSIX tre_regexec() flags. */
137 #define REG_NOTEOL (REG_NOTBOL << 1)
139 /* Extra tre_regexec() flags. */
140 #define REG_APPROX_MATCHER (REG_NOTEOL << 1)
141 #define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
142 #define REG_STARTEND (REG_BACKTRACKING_MATCHER << 1)
144 #endif /* !TRE_USE_SYSTEM_REGEX_H */
146 /* REG_NOSPEC and REG_LITERAL mean the same thing. */
147 #if defined(REG_LITERAL) && !defined(REG_NOSPEC)
148 #define REG_NOSPEC REG_LITERAL
149 #elif defined(REG_NOSPEC) && !defined(REG_LITERAL)
150 #define REG_LITERAL REG_NOSPEC
151 #endif /* defined(REG_NOSPEC) */
153 /* The maximum number of iterations in a bound expression. */
155 #define RE_DUP_MAX 255
157 /* The POSIX.2 regexp functions */
159 tre_regcomp(regex_t
* __restrict preg
, const char * __restrict regex
, int cflags
);
162 tre_regexec(const regex_t
* __restrict preg
, const char * __restrict string
, size_t nmatch
,
163 regmatch_t pmatch
[ __restrict
], int eflags
);
166 tre_regerror(int errcode
, const regex_t
* __restrict preg
, char * __restrict errbuf
,
170 tre_regfree(regex_t
*preg
);
175 #endif /* HAVE_WCHAR_H */
177 /* Wide character versions (not in POSIX.2). */
179 tre_regwcomp(regex_t
* __restrict preg
, const wchar_t * __restrict regex
, int cflags
);
182 tre_regwexec(const regex_t
* __restrict preg
, const wchar_t * __restrict string
,
183 size_t nmatch
, regmatch_t pmatch
[ __restrict
], int eflags
);
184 #endif /* TRE_WCHAR */
186 /* Versions with a maximum length argument and therefore the capability to
187 handle null characters in the middle of the strings (not in POSIX.2). */
189 tre_regncomp(regex_t
* __restrict preg
, const char * __restrict regex
, size_t len
, int cflags
);
192 tre_regnexec(const regex_t
* __restrict preg
, const char * __restrict string
, size_t len
,
193 size_t nmatch
, regmatch_t pmatch
[ __restrict
], int eflags
);
197 tre_regwncomp(regex_t
* __restrict preg
, const wchar_t * __restrict regex
, size_t len
, int cflags
);
200 tre_regwnexec(const regex_t
* __restrict preg
, const wchar_t * __restrict string
, size_t len
,
201 size_t nmatch
, regmatch_t pmatch
[ __restrict
], int eflags
);
202 #endif /* TRE_WCHAR */
204 /* Extended locale versions */
208 tre_regcomp_l(regex_t
* __restrict preg
, const char * __restrict regex
, int cflags
, locale_t __restrict loc
);
212 tre_regwcomp_l(regex_t
* __restrict preg
, const wchar_t * __restrict regex
, int cflags
, locale_t __restrict loc
);
213 #endif /* TRE_WCHAR */
216 tre_regncomp_l(regex_t
* __restrict preg
, const char * __restrict regex
, size_t len
, int cflags
, locale_t __restrict loc
);
220 tre_regwncomp_l(regex_t
* __restrict preg
, const wchar_t * __restrict regex
, size_t len
, int cflags
, locale_t __restrict loc
);
221 #endif /* TRE_WCHAR */
225 /* Approximate matching parameter struct. */
227 int cost_ins
; /* Default cost of an inserted character. */
228 int cost_del
; /* Default cost of a deleted character. */
229 int cost_subst
; /* Default cost of a substituted character. */
230 int max_cost
; /* Maximum allowed cost of a match. */
232 int max_ins
; /* Maximum allowed number of inserts. */
233 int max_del
; /* Maximum allowed number of deletes. */
234 int max_subst
; /* Maximum allowed number of substitutes. */
235 int max_err
; /* Maximum allowed number of errors total. */
238 /* Approximate matching result struct. */
240 size_t nmatch
; /* Length of pmatch[] array. */
241 regmatch_t
*pmatch
; /* Submatch data. */
242 int cost
; /* Cost of the match. */
243 int num_ins
; /* Number of inserts in the match. */
244 int num_del
; /* Number of deletes in the match. */
245 int num_subst
; /* Number of substitutes in the match. */
249 /* Approximate matching functions. */
251 tre_regaexec(const regex_t
* __restrict preg
, const char * __restrict string
,
252 regamatch_t
* __restrict match
, regaparams_t params
, int eflags
);
255 tre_reganexec(const regex_t
* __restrict preg
, const char * __restrict string
, size_t len
,
256 regamatch_t
* __restrict match
, regaparams_t params
, int eflags
);
258 /* Wide character approximate matching. */
260 tre_regawexec(const regex_t
* __restrict preg
, const wchar_t * __restrict string
,
261 regamatch_t
* __restrict match
, regaparams_t params
, int eflags
);
264 tre_regawnexec(const regex_t
* __restrict preg
, const wchar_t * __restrict string
, size_t len
,
265 regamatch_t
* __restrict match
, regaparams_t params
, int eflags
);
266 #endif /* TRE_WCHAR */
268 /* Sets the parameters to default values. */
270 tre_regaparams_default(regaparams_t
*params
);
271 #endif /* TRE_APPROX */
274 typedef wchar_t tre_char_t
;
275 #else /* !TRE_WCHAR */
276 typedef unsigned char tre_char_t
;
277 #endif /* !TRE_WCHAR */
281 int (*get_next_char
)(tre_char_t
*c
, unsigned int *pos_add
, void *context
);
282 void (*rewind
)(size_t pos
, void *context
);
283 int (*compare
)(size_t pos1
, size_t pos2
, size_t len
, void *context
);
288 tre_reguexec(const regex_t
* __restrict preg
, const tre_str_source
* __restrict string
,
289 size_t nmatch
, regmatch_t pmatch
[ __restrict
], int eflags
);
290 #endif /* TRE_STR_USER */
293 /* Returns the version string. The returned string is static. */
297 /* Returns the value for a config parameter. The type to which `result'
298 must point to depends of the value of `query', see documentation for
301 tre_config(int query
, void *result
);
306 TRE_CONFIG_MULTIBYTE
,
307 TRE_CONFIG_SYSTEM_ABI
,
311 /* Returns 1 if the compiled pattern has back references, 0 if not. */
313 tre_have_backrefs(const regex_t
*preg
);
316 /* Returns 1 if the compiled pattern uses approximate matching features,
319 tre_have_approx(const regex_t
*preg
);
320 #endif /* TRE_APPROX */
321 #endif /* !__LIBC__ */