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>
28 #ifdef BOOST_HAS_ABI_HEADERS
29 # include BOOST_ABI_PREFIX
32 /* include these defs only for POSIX compatablity */
38 #if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
39 typedef std::ptrdiff_t regoff_t;
40 typedef std::size_t regsize_t;
42 typedef ptrdiff_t regoff_t;
43 typedef size_t regsize_t;
48 unsigned int re_magic;
49 unsigned int re_nsub; /* number of parenthesized subexpressions */
50 const char* re_endp; /* end pointer for REG_PEND */
51 void* guts; /* none of your business :-) */
52 match_flag_type eflags; /* none of your business :-) */
55 #ifndef BOOST_NO_WREGEX
58 unsigned int re_magic;
59 unsigned int re_nsub; /* number of parenthesized subexpressions */
60 const wchar_t* re_endp; /* end pointer for REG_PEND */
61 void* guts; /* none of your business :-) */
62 match_flag_type eflags; /* none of your business :-) */
68 regoff_t rm_so; /* start of match */
69 regoff_t rm_eo; /* end of match */
83 REG_ESCAPE_IN_LISTS = 01000,
84 REG_NEWLINE_ALT = 02000,
87 REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS | REG_PERLEX,
88 REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS,
89 REG_GREP = REG_BASIC | REG_NEWLINE_ALT,
90 REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT,
94 REG_ATOI = 255, /* convert name to number (!) */
95 REG_ITOA = 0400 /* convert number to name (!) */
105 BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int);
106 BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t);
107 BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int);
108 BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*);
110 #ifndef BOOST_NO_WREGEX
111 BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int);
112 BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t);
113 BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int);
114 BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*);
118 #define regcomp regcompW
119 #define regerror regerrorW
120 #define regexec regexecW
121 #define regfree regfreeW
122 #define regex_t regex_tW
124 #define regcomp regcompA
125 #define regerror regerrorA
126 #define regexec regexecA
127 #define regfree regfreeA
128 #define regex_t regex_tA
131 /* regerror() flags */
134 REG_NOERROR = 0, /* Success. */
135 REG_NOMATCH = 1, /* Didn't find a match (for regexec). */
137 /* POSIX regcomp return error codes. (In the order listed in the
139 REG_BADPAT = 2, /* Invalid pattern. */
140 REG_ECOLLATE = 3, /* Undefined collating element. */
141 REG_ECTYPE = 4, /* Invalid character class name. */
142 REG_EESCAPE = 5, /* Trailing backslash. */
143 REG_ESUBREG = 6, /* Invalid back reference. */
144 REG_EBRACK = 7, /* Unmatched left bracket. */
145 REG_EPAREN = 8, /* Parenthesis imbalance. */
146 REG_EBRACE = 9, /* Unmatched \{. */
147 REG_BADBR = 10, /* Invalid contents of \{\}. */
148 REG_ERANGE = 11, /* Invalid range end. */
149 REG_ESPACE = 12, /* Ran out of memory. */
150 REG_BADRPT = 13, /* No preceding re for repetition op. */
151 REG_EEND = 14, /* unexpected end of expression */
152 REG_ESIZE = 15, /* expression too big */
153 REG_ERPAREN = 16, /* unmatched right parenthesis */
154 REG_EMPTY = 17, /* empty expression */
155 REG_E_MEMORY = REG_ESIZE, /* out of memory */
156 REG_E_UNKNOWN = 18 /* unknown error */
159 #ifdef BOOST_HAS_ABI_HEADERS
160 # include BOOST_ABI_SUFFIX
169 // C++ high level wrapper goes here:
171 #if defined(__cplusplus)
176 #ifdef BOOST_HAS_ABI_HEADERS
177 # include BOOST_ABI_PREFIX
190 } // namespace re_detail
192 #if (defined(BOOST_MSVC) || defined(__BORLANDC__)) && !defined(BOOST_DISABLE_WIN32)
193 typedef bool (__cdecl *GrepCallback)(const RegEx& expression);
194 typedef bool (__cdecl *GrepFileCallback)(const char* file, const RegEx& expression);
195 typedef bool (__cdecl *FindFilesCallback)(const char* file);
197 typedef bool (*GrepCallback)(const RegEx& expression);
198 typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
199 typedef bool (*FindFilesCallback)(const char* file);
202 class BOOST_REGEX_DECL RegEx
205 re_detail::RegExData* pdata;
208 RegEx(const RegEx& o);
210 explicit RegEx(const char* c, bool icase = false);
211 explicit RegEx(const std::string& s, bool icase = false);
212 RegEx& operator=(const RegEx& o);
213 RegEx& operator=(const char* p);
214 RegEx& operator=(const std::string& s){ return this->operator=(s.c_str()); }
215 unsigned int SetExpression(const char* p, bool icase = false);
216 unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
217 std::string Expression()const;
218 unsigned int error_code()const;
220 // now matching operators:
222 bool Match(const char* p, match_flag_type flags = match_default);
223 bool Match(const std::string& s, match_flag_type flags = match_default) { return Match(s.c_str(), flags); }
224 bool Search(const char* p, match_flag_type flags = match_default);
225 bool Search(const std::string& s, match_flag_type flags = match_default) { return Search(s.c_str(), flags); }
226 unsigned int Grep(GrepCallback cb, const char* p, match_flag_type flags = match_default);
227 unsigned int Grep(GrepCallback cb, const std::string& s, match_flag_type flags = match_default) { return Grep(cb, s.c_str(), flags); }
228 unsigned int Grep(std::vector<std::string>& v, const char* p, match_flag_type flags = match_default);
229 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); }
230 unsigned int Grep(std::vector<std::size_t>& v, const char* p, match_flag_type flags = match_default);
231 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); }
232 #ifndef BOOST_REGEX_NO_FILEITER
233 unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, match_flag_type flags = match_default);
234 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); }
235 unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, match_flag_type flags = match_default);
236 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); }
239 std::string Merge(const std::string& in, const std::string& fmt,
240 bool copy = true, match_flag_type flags = match_default);
241 std::string Merge(const char* in, const char* fmt,
242 bool copy = true, match_flag_type flags = match_default);
244 std::size_t Split(std::vector<std::string>& v, std::string& s, match_flag_type flags = match_default, unsigned max_count = ~0);
246 // now operators for returning what matched in more detail:
248 std::size_t Position(int i = 0)const;
249 std::size_t Length(int i = 0)const;
250 bool Matched(int i = 0)const;
251 unsigned int Marks()const;
252 std::string What(int i = 0)const;
253 std::string operator[](int i)const { return What(i); }
255 static const unsigned int npos;
257 friend struct re_detail::pred1;
258 friend struct re_detail::pred2;
259 friend struct re_detail::pred3;
260 friend struct re_detail::pred4;
263 #ifdef BOOST_HAS_ABI_HEADERS
264 # include BOOST_ABI_SUFFIX
271 #endif // include guard