]> git.lyx.org Git - lyx.git/blob - boost/boost/regex/v4/cregex.hpp
15c92b52af57b58966261739b86fafb595b5194d
[lyx.git] / boost / boost / regex / v4 / cregex.hpp
1 /*
2  *
3  * Copyright (c) 1998-2002
4  * Dr John Maddock
5  *
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)
9  *
10  */
11
12  /*
13   *   LOCATION:    see http://www.boost.org for most recent version.
14   *   FILE         cregex.cpp
15   *   VERSION      see <boost/version.hpp>
16   *   DESCRIPTION: Declares POSIX API functions
17   *                + boost::RegEx high level wrapper.
18   */
19
20 #ifndef BOOST_RE_CREGEX_HPP_INCLUDED
21 #define BOOST_RE_CREGEX_HPP_INCLUDED
22
23 #ifndef BOOST_REGEX_CONFIG_HPP
24 #include <boost/regex/config.hpp>
25 #endif
26 #include <boost/regex/v4/match_flags.hpp>
27
28 #ifdef BOOST_HAS_ABI_HEADERS
29 #  include BOOST_ABI_PREFIX
30 #endif
31
32 /* include these defs only for POSIX compatablity */
33 #ifdef __cplusplus
34 namespace boost{
35 extern "C" {
36 #endif
37
38 #if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
39 typedef std::ptrdiff_t regoff_t;
40 typedef std::size_t regsize_t;
41 #else
42 typedef ptrdiff_t regoff_t;
43 typedef size_t regsize_t;
44 #endif
45
46 typedef struct
47 {
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 :-) */
53 } regex_tA;
54
55 #ifndef BOOST_NO_WREGEX
56 typedef struct
57 {
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 :-) */
63 } regex_tW;
64 #endif
65
66 typedef struct
67 {
68    regoff_t rm_so;      /* start of match */
69    regoff_t rm_eo;      /* end of match */
70 } regmatch_t;
71
72 /* regcomp() flags */
73 typedef enum{
74    REG_BASIC = 0000,
75    REG_EXTENDED = 0001,
76    REG_ICASE = 0002,
77    REG_NOSUB = 0004,
78    REG_NEWLINE = 0010,
79    REG_NOSPEC = 0020,
80    REG_PEND = 0040,
81    REG_DUMP = 0200,
82    REG_NOCOLLATE = 0400,
83    REG_ESCAPE_IN_LISTS = 01000,
84    REG_NEWLINE_ALT = 02000,
85    REG_PERLEX = 04000,
86
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,
91
92    REG_ASSERT = 15,
93    REG_INVARG = 16,
94    REG_ATOI = 255,   /* convert name to number (!) */
95    REG_ITOA = 0400   /* convert number to name (!) */
96 } reg_comp_flags;
97
98 /* regexec() flags */
99 typedef enum{
100    REG_NOTBOL =    00001,
101    REG_NOTEOL =    00002,
102    REG_STARTEND =  00004
103 } reg_exec_flags;
104
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*);
109
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*);
115 #endif
116
117 #ifdef UNICODE
118 #define regcomp regcompW
119 #define regerror regerrorW
120 #define regexec regexecW
121 #define regfree regfreeW
122 #define regex_t regex_tW
123 #else
124 #define regcomp regcompA
125 #define regerror regerrorA
126 #define regexec regexecA
127 #define regfree regfreeA
128 #define regex_t regex_tA
129 #endif
130
131 /* regerror() flags */
132 typedef enum
133 {
134   REG_NOERROR = 0,   /* Success.  */
135   REG_NOMATCH = 1,      /* Didn't find a match (for regexec).  */
136
137   /* POSIX regcomp return error codes.  (In the order listed in the
138      standard.)  */
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 */
157 } reg_errcode_t;
158
159 #ifdef BOOST_HAS_ABI_HEADERS
160 #  include BOOST_ABI_SUFFIX
161 #endif
162
163 #ifdef __cplusplus
164 } // extern "C"
165 } // namespace
166 #endif
167
168 //
169 // C++ high level wrapper goes here:
170 //
171 #if defined(__cplusplus)
172 #include <string>
173 #include <vector>
174 namespace boost{
175
176 #ifdef BOOST_HAS_ABI_HEADERS
177 #  include BOOST_ABI_PREFIX
178 #endif
179
180 class RegEx;
181
182 namespace re_detail{
183
184 class RegExData;
185 struct pred1;
186 struct pred2;
187 struct pred3;
188 struct pred4;
189
190 }  // namespace re_detail
191
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);
196 #else
197 typedef bool (*GrepCallback)(const RegEx& expression);
198 typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
199 typedef bool (*FindFilesCallback)(const char* file);
200 #endif
201
202 class BOOST_REGEX_DECL RegEx
203 {
204 private:
205    re_detail::RegExData* pdata;
206 public:
207    RegEx();
208    RegEx(const RegEx& o);
209    ~RegEx();
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;
219    //
220    // now matching operators:
221    //
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); }
237 #endif
238
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);
243
244    std::size_t Split(std::vector<std::string>& v, std::string& s, match_flag_type flags = match_default, unsigned max_count = ~0);
245    //
246    // now operators for returning what matched in more detail:
247    //
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); }
254
255    static const unsigned int npos;
256
257    friend struct re_detail::pred1;
258    friend struct re_detail::pred2;
259    friend struct re_detail::pred3;
260    friend struct re_detail::pred4;
261 };
262
263 #ifdef BOOST_HAS_ABI_HEADERS
264 #  include BOOST_ABI_SUFFIX
265 #endif
266
267 } // namespace boost
268
269 #endif
270
271 #endif // include guard
272
273
274
275
276
277
278
279
280
281