3
* Copyright (c) 1998-2002
6
* Permission to use, copy, modify, distribute and sell this software
7
* and its documentation for any purpose is hereby granted without fee,
8
* provided that the above copyright notice appear in all copies and
9
* that both that copyright notice and this permission notice appear
10
* in supporting documentation. Dr John Maddock makes no representations
11
* about the suitability of this software for any purpose.
12
* It is provided "as is" without express or implied warranty.
17
* LOCATION: see http://www.boost.org for most recent version.
19
* VERSION see <boost/version.hpp>
20
* DESCRIPTION: Declares POSIX API functions
21
* + boost::RegEx high level wrapper.
24
#ifndef BOOST_RE_CREGEX_HPP_INCLUDED
25
#define BOOST_RE_CREGEX_HPP_INCLUDED
27
#ifndef BOOST_REGEX_CONFIG_HPP
28
#include <boost/regex/config.hpp>
32
#pragma option push -a8 -b -Vx -Ve -pc
35
/* include these defs only for POSIX compatablity */
41
#if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
42
typedef std::ptrdiff_t regoff_t;
43
typedef std::size_t regsize_t;
45
typedef ptrdiff_t regoff_t;
46
typedef size_t regsize_t;
51
unsigned int re_magic;
52
unsigned int re_nsub; /* number of parenthesized subexpressions */
53
const char* re_endp; /* end pointer for REG_PEND */
54
void* guts; /* none of your business :-) */
55
unsigned int eflags; /* none of your business :-) */
58
#ifndef BOOST_NO_WREGEX
61
unsigned int re_magic;
62
unsigned int re_nsub; /* number of parenthesized subexpressions */
63
const wchar_t* re_endp; /* end pointer for REG_PEND */
64
void* guts; /* none of your business :-) */
65
unsigned int eflags; /* none of your business :-) */
71
regoff_t rm_so; /* start of match */
72
regoff_t rm_eo; /* end of match */
86
REG_ESCAPE_IN_LISTS = 01000,
87
REG_NEWLINE_ALT = 02000,
89
REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS,
90
REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS,
91
REG_GREP = REG_BASIC | REG_NEWLINE_ALT,
92
REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT,
96
REG_ATOI = 255, /* convert name to number (!) */
97
REG_ITOA = 0400 /* convert number to name (!) */
100
/* regexec() flags */
107
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int);
108
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t);
109
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int);
110
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*);
112
#ifndef BOOST_NO_WREGEX
113
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int);
114
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t);
115
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int);
116
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*);
120
#define regcomp regcompW
121
#define regerror regerrorW
122
#define regexec regexecW
123
#define regfree regfreeW
124
#define regex_t regex_tW
126
#define regcomp regcompA
127
#define regerror regerrorA
128
#define regexec regexecA
129
#define regfree regfreeA
130
#define regex_t regex_tA
133
/* regerror() flags */
136
REG_NOERROR = 0, /* Success. */
137
REG_NOMATCH = 1, /* Didn't find a match (for regexec). */
139
/* POSIX regcomp return error codes. (In the order listed in the
141
REG_BADPAT = 2, /* Invalid pattern. */
142
REG_ECOLLATE = 3, /* Undefined collating element. */
143
REG_ECTYPE = 4, /* Invalid character class name. */
144
REG_EESCAPE = 5, /* Trailing backslash. */
145
REG_ESUBREG = 6, /* Invalid back reference. */
146
REG_EBRACK = 7, /* Unmatched left bracket. */
147
REG_EPAREN = 8, /* Parenthesis imbalance. */
148
REG_EBRACE = 9, /* Unmatched \{. */
149
REG_BADBR = 10, /* Invalid contents of \{\}. */
150
REG_ERANGE = 11, /* Invalid range end. */
151
REG_ESPACE = 12, /* Ran out of memory. */
152
REG_BADRPT = 13, /* No preceding re for repetition op. */
153
REG_EEND = 14, /* unexpected end of expression */
154
REG_ESIZE = 15, /* expression too big */
155
REG_ERPAREN = 16, /* unmatched right parenthesis */
156
REG_EMPTY = 17, /* empty expression */
157
REG_E_MEMORY = REG_ESIZE, /* out of memory */
158
REG_E_UNKNOWN = 18 /* unknown error */
164
match_not_bol = 1, // first is not start of line
165
match_not_eol = match_not_bol << 1, // last is not end of line
166
match_not_bob = match_not_eol << 1, // first is not start of buffer
167
match_not_eob = match_not_bob << 1, // last is not end of buffer
168
match_not_bow = match_not_eob << 1, // first is not start of word
169
match_not_eow = match_not_bow << 1, // last is not end of word
170
match_not_dot_newline = match_not_eow << 1, // \n is not matched by '.'
171
match_not_dot_null = match_not_dot_newline << 1, // '\0' is not matched by '.'
172
match_prev_avail = match_not_dot_null << 1, // *--first is a valid expression
173
match_init = match_prev_avail << 1, // internal use
174
match_any = match_init << 1, // don't care what we match
175
match_not_null = match_any << 1, // string can't be null
176
match_continuous = match_not_null << 1, // each grep match must continue from
177
// uninterupted from the previous one
178
match_partial = match_continuous << 1, // find partial matches
180
match_stop = match_partial << 1, // stop after first match (grep)
181
match_all = match_stop << 1, // must find the whole of input even if match_any is set
182
match_max = match_all
193
#if __BORLANDC__ > 0x520
200
// C++ high level wrapper goes here:
202
#if defined(__cplusplus)
208
#if __BORLANDC__ == 0x530
209
#pragma option push -a4 -b
210
#elif __BORLANDC__ > 0x530
211
#pragma option push -a8 -b
225
} // namespace re_detail
227
#if defined(BOOST_MSVC) || defined(__BORLANDC__)
228
typedef bool (__cdecl *GrepCallback)(const RegEx& expression);
229
typedef bool (__cdecl *GrepFileCallback)(const char* file, const RegEx& expression);
230
typedef bool (__cdecl *FindFilesCallback)(const char* file);
232
typedef bool (*GrepCallback)(const RegEx& expression);
233
typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
234
typedef bool (*FindFilesCallback)(const char* file);
237
class BOOST_REGEX_DECL RegEx
240
re_detail::RegExData* pdata;
243
RegEx(const RegEx& o);
245
explicit RegEx(const char* c, bool icase = false);
246
explicit RegEx(const std::string& s, bool icase = false);
247
RegEx& operator=(const RegEx& o);
248
RegEx& operator=(const char* p);
249
RegEx& operator=(const std::string& s){ return this->operator=(s.c_str()); }
250
unsigned int SetExpression(const char* p, bool icase = false);
251
unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
252
std::string Expression()const;
253
unsigned int error_code()const;
255
// now matching operators:
257
bool Match(const char* p, unsigned int flags = match_default);
258
bool Match(const std::string& s, unsigned int flags = match_default) { return Match(s.c_str(), flags); }
259
bool Search(const char* p, unsigned int flags = match_default);
260
bool Search(const std::string& s, unsigned int flags = match_default) { return Search(s.c_str(), flags); }
261
unsigned int Grep(GrepCallback cb, const char* p, unsigned int flags = match_default);
262
unsigned int Grep(GrepCallback cb, const std::string& s, unsigned int flags = match_default) { return Grep(cb, s.c_str(), flags); }
263
unsigned int Grep(std::vector<std::string>& v, const char* p, unsigned int flags = match_default);
264
unsigned int Grep(std::vector<std::string>& v, const std::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); }
265
unsigned int Grep(std::vector<std::size_t>& v, const char* p, unsigned int flags = match_default);
266
unsigned int Grep(std::vector<std::size_t>& v, const std::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); }
267
#ifndef BOOST_REGEX_NO_FILEITER
268
unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default);
269
unsigned int GrepFiles(GrepFileCallback cb, const std::string& files, bool recurse = false, unsigned int flags = match_default) { return GrepFiles(cb, files.c_str(), recurse, flags); }
270
unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default);
271
unsigned int FindFiles(FindFilesCallback cb, const std::string& files, bool recurse = false, unsigned int flags = match_default) { return FindFiles(cb, files.c_str(), recurse, flags); }
274
std::string Merge(const std::string& in, const std::string& fmt,
275
bool copy = true, unsigned int flags = match_default);
276
std::string Merge(const char* in, const char* fmt,
277
bool copy = true, unsigned int flags = match_default);
279
std::size_t Split(std::vector<std::string>& v, std::string& s, unsigned flags = match_default, unsigned max_count = ~0);
281
// now operators for returning what matched in more detail:
283
std::size_t Position(int i = 0)const;
284
std::size_t Length(int i = 0)const;
285
bool Matched(int i = 0)const;
286
unsigned int Line()const;
287
unsigned int Marks()const;
288
std::string What(int i = 0)const;
289
std::string operator[](int i)const { return What(i); }
291
static const unsigned int npos;
293
friend struct re_detail::pred1;
294
friend struct re_detail::pred2;
295
friend struct re_detail::pred3;
296
friend struct re_detail::pred4;
307
#endif // include guard