3 * Copyright (c) 1998-2002
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Declares POSIX API functions
17 * + boost::RegEx high level wrapper.
20 #ifndef BOOST_RE_CREGEX_HPP_INCLUDED
21 #define BOOST_RE_CREGEX_HPP_INCLUDED
23 #ifndef BOOST_REGEX_CONFIG_HPP
24 #include <boost/regex/config.hpp>
26 #include <boost/regex/v4/match_flags.hpp>
27 #include <boost/regex/v4/error_type.hpp>
37 #pragma warning(disable: 4103)
39 #ifdef BOOST_HAS_ABI_HEADERS
40 # include BOOST_ABI_PREFIX
46 /* include these defs only for POSIX compatablity */
52 #if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
53 typedef std::ptrdiff_t regoff_t
;
54 typedef std::size_t regsize_t
;
56 typedef ptrdiff_t regoff_t
;
57 typedef size_t regsize_t
;
62 unsigned int re_magic
;
64 std::size_t re_nsub
; /* number of parenthesized subexpressions */
68 const char* re_endp
; /* end pointer for REG_PEND */
69 void* guts
; /* none of your business :-) */
70 match_flag_type eflags
; /* none of your business :-) */
73 #ifndef BOOST_NO_WREGEX
76 unsigned int re_magic
;
78 std::size_t re_nsub
; /* number of parenthesized subexpressions */
82 const wchar_t* re_endp
; /* end pointer for REG_PEND */
83 void* guts
; /* none of your business :-) */
84 match_flag_type eflags
; /* none of your business :-) */
90 regoff_t rm_so
; /* start of match */
91 regoff_t rm_eo
; /* end of match */
104 REG_NOCOLLATE
= 0400,
105 REG_ESCAPE_IN_LISTS
= 01000,
106 REG_NEWLINE_ALT
= 02000,
109 REG_PERL
= REG_EXTENDED
| REG_NOCOLLATE
| REG_ESCAPE_IN_LISTS
| REG_PERLEX
,
110 REG_AWK
= REG_EXTENDED
| REG_ESCAPE_IN_LISTS
,
111 REG_GREP
= REG_BASIC
| REG_NEWLINE_ALT
,
112 REG_EGREP
= REG_EXTENDED
| REG_NEWLINE_ALT
,
116 REG_ATOI
= 255, /* convert name to number (!) */
117 REG_ITOA
= 0400 /* convert number to name (!) */
120 /* regexec() flags */
128 // POSIX error codes:
130 typedef unsigned reg_error_t
;
131 typedef reg_error_t reg_errcode_t
; // backwards compatibility
133 static const reg_error_t REG_NOERROR
= 0; /* Success. */
134 static const reg_error_t REG_NOMATCH
= 1; /* Didn't find a match (for regexec). */
136 /* POSIX regcomp return error codes. (In the order listed in the
138 static const reg_error_t REG_BADPAT
= 2; /* Invalid pattern. */
139 static const reg_error_t REG_ECOLLATE
= 3; /* Undefined collating element. */
140 static const reg_error_t REG_ECTYPE
= 4; /* Invalid character class name. */
141 static const reg_error_t REG_EESCAPE
= 5; /* Trailing backslash. */
142 static const reg_error_t REG_ESUBREG
= 6; /* Invalid back reference. */
143 static const reg_error_t REG_EBRACK
= 7; /* Unmatched left bracket. */
144 static const reg_error_t REG_EPAREN
= 8; /* Parenthesis imbalance. */
145 static const reg_error_t REG_EBRACE
= 9; /* Unmatched \{. */
146 static const reg_error_t REG_BADBR
= 10; /* Invalid contents of \{\}. */
147 static const reg_error_t REG_ERANGE
= 11; /* Invalid range end. */
148 static const reg_error_t REG_ESPACE
= 12; /* Ran out of memory. */
149 static const reg_error_t REG_BADRPT
= 13; /* No preceding re for repetition op. */
150 static const reg_error_t REG_EEND
= 14; /* unexpected end of expression */
151 static const reg_error_t REG_ESIZE
= 15; /* expression too big */
152 static const reg_error_t REG_ERPAREN
= 8; /* = REG_EPAREN : unmatched right parenthesis */
153 static const reg_error_t REG_EMPTY
= 17; /* empty expression */
154 static const reg_error_t REG_E_MEMORY
= 15; /* = REG_ESIZE : out of memory */
155 static const reg_error_t REG_ECOMPLEXITY
= 18; /* complexity too high */
156 static const reg_error_t REG_ESTACK
= 19; /* out of stack space */
157 static const reg_error_t REG_E_UNKNOWN
= 20; /* unknown error */
158 static const reg_error_t REG_ENOSYS
= 20; /* = REG_E_UNKNOWN : Reserved. */
160 BOOST_REGEX_DECL
int BOOST_REGEX_CCALL
regcompA(regex_tA
*, const char*, int);
161 BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL
regerrorA(int, const regex_tA
*, char*, regsize_t
);
162 BOOST_REGEX_DECL
int BOOST_REGEX_CCALL
regexecA(const regex_tA
*, const char*, regsize_t
, regmatch_t
*, int);
163 BOOST_REGEX_DECL
void BOOST_REGEX_CCALL
regfreeA(regex_tA
*);
165 #ifndef BOOST_NO_WREGEX
166 BOOST_REGEX_DECL
int BOOST_REGEX_CCALL
regcompW(regex_tW
*, const wchar_t*, int);
167 BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL
regerrorW(int, const regex_tW
*, wchar_t*, regsize_t
);
168 BOOST_REGEX_DECL
int BOOST_REGEX_CCALL
regexecW(const regex_tW
*, const wchar_t*, regsize_t
, regmatch_t
*, int);
169 BOOST_REGEX_DECL
void BOOST_REGEX_CCALL
regfreeW(regex_tW
*);
173 #define regcomp regcompW
174 #define regerror regerrorW
175 #define regexec regexecW
176 #define regfree regfreeW
177 #define regex_t regex_tW
179 #define regcomp regcompA
180 #define regerror regerrorA
181 #define regexec regexecA
182 #define regfree regfreeA
183 #define regex_t regex_tA
187 #pragma warning(push)
188 #pragma warning(disable: 4103)
190 #ifdef BOOST_HAS_ABI_HEADERS
191 # include BOOST_ABI_SUFFIX
203 // C++ high level wrapper goes here:
205 #if defined(__cplusplus)
211 #pragma warning(push)
212 #pragma warning(disable: 4103)
214 #ifdef BOOST_HAS_ABI_HEADERS
215 # include BOOST_ABI_PREFIX
231 } // namespace re_detail
233 #if (defined(BOOST_MSVC) || defined(__BORLANDC__)) && !defined(BOOST_DISABLE_WIN32)
234 typedef bool (__cdecl
*GrepCallback
)(const RegEx
& expression
);
235 typedef bool (__cdecl
*GrepFileCallback
)(const char* file
, const RegEx
& expression
);
236 typedef bool (__cdecl
*FindFilesCallback
)(const char* file
);
238 typedef bool (*GrepCallback
)(const RegEx
& expression
);
239 typedef bool (*GrepFileCallback
)(const char* file
, const RegEx
& expression
);
240 typedef bool (*FindFilesCallback
)(const char* file
);
243 class BOOST_REGEX_DECL RegEx
246 re_detail::RegExData
* pdata
;
249 RegEx(const RegEx
& o
);
251 explicit RegEx(const char* c
, bool icase
= false);
252 explicit RegEx(const std::string
& s
, bool icase
= false);
253 RegEx
& operator=(const RegEx
& o
);
254 RegEx
& operator=(const char* p
);
255 RegEx
& operator=(const std::string
& s
){ return this->operator=(s
.c_str()); }
256 unsigned int SetExpression(const char* p
, bool icase
= false);
257 unsigned int SetExpression(const std::string
& s
, bool icase
= false){ return SetExpression(s
.c_str(), icase
); }
258 std::string
Expression()const;
259 unsigned int error_code()const;
261 // now matching operators:
263 bool Match(const char* p
, match_flag_type flags
= match_default
);
264 bool Match(const std::string
& s
, match_flag_type flags
= match_default
) { return Match(s
.c_str(), flags
); }
265 bool Search(const char* p
, match_flag_type flags
= match_default
);
266 bool Search(const std::string
& s
, match_flag_type flags
= match_default
) { return Search(s
.c_str(), flags
); }
267 unsigned int Grep(GrepCallback cb
, const char* p
, match_flag_type flags
= match_default
);
268 unsigned int Grep(GrepCallback cb
, const std::string
& s
, match_flag_type flags
= match_default
) { return Grep(cb
, s
.c_str(), flags
); }
269 unsigned int Grep(std::vector
<std::string
>& v
, const char* p
, match_flag_type flags
= match_default
);
270 unsigned int Grep(std::vector
<std::string
>& v
, const std::string
& s
, match_flag_type flags
= match_default
) { return Grep(v
, s
.c_str(), flags
); }
271 unsigned int Grep(std::vector
<std::size_t>& v
, const char* p
, match_flag_type flags
= match_default
);
272 unsigned int Grep(std::vector
<std::size_t>& v
, const std::string
& s
, match_flag_type flags
= match_default
) { return Grep(v
, s
.c_str(), flags
); }
273 #ifndef BOOST_REGEX_NO_FILEITER
274 unsigned int GrepFiles(GrepFileCallback cb
, const char* files
, bool recurse
= false, match_flag_type flags
= match_default
);
275 unsigned int GrepFiles(GrepFileCallback cb
, const std::string
& files
, bool recurse
= false, match_flag_type flags
= match_default
) { return GrepFiles(cb
, files
.c_str(), recurse
, flags
); }
276 unsigned int FindFiles(FindFilesCallback cb
, const char* files
, bool recurse
= false, match_flag_type flags
= match_default
);
277 unsigned int FindFiles(FindFilesCallback cb
, const std::string
& files
, bool recurse
= false, match_flag_type flags
= match_default
) { return FindFiles(cb
, files
.c_str(), recurse
, flags
); }
280 std::string
Merge(const std::string
& in
, const std::string
& fmt
,
281 bool copy
= true, match_flag_type flags
= match_default
);
282 std::string
Merge(const char* in
, const char* fmt
,
283 bool copy
= true, match_flag_type flags
= match_default
);
285 std::size_t Split(std::vector
<std::string
>& v
, std::string
& s
, match_flag_type flags
= match_default
, unsigned max_count
= ~0);
287 // now operators for returning what matched in more detail:
289 std::size_t Position(int i
= 0)const;
290 std::size_t Length(int i
= 0)const;
291 bool Matched(int i
= 0)const;
292 std::size_t Marks()const;
293 std::string
What(int i
= 0)const;
294 std::string
operator[](int i
)const { return What(i
); }
296 static const std::size_t npos
;
298 friend struct re_detail::pred1
;
299 friend struct re_detail::pred2
;
300 friend struct re_detail::pred3
;
301 friend struct re_detail::pred4
;
305 #pragma warning(push)
306 #pragma warning(disable: 4103)
308 #ifdef BOOST_HAS_ABI_HEADERS
309 # include BOOST_ABI_SUFFIX
319 #endif // include guard