~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/regex/v3/cregex.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * Copyright (c) 1998-2002
 
4
 * Dr John Maddock
 
5
 *
 
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.
 
13
 *
 
14
 */
 
15
 
 
16
 /*
 
17
  *   LOCATION:    see http://www.boost.org for most recent version.
 
18
  *   FILE         cregex.cpp
 
19
  *   VERSION      see <boost/version.hpp>
 
20
  *   DESCRIPTION: Declares POSIX API functions
 
21
  *                + boost::RegEx high level wrapper.
 
22
  */
 
23
 
 
24
#ifndef BOOST_RE_CREGEX_HPP_INCLUDED
 
25
#define BOOST_RE_CREGEX_HPP_INCLUDED
 
26
 
 
27
#ifndef BOOST_REGEX_CONFIG_HPP
 
28
#include <boost/regex/config.hpp>
 
29
#endif
 
30
 
 
31
#ifdef __BORLANDC__
 
32
   #pragma option push -a8 -b -Vx -Ve -pc
 
33
#endif
 
34
 
 
35
/* include these defs only for POSIX compatablity */
 
36
#ifdef __cplusplus
 
37
namespace boost{
 
38
extern "C" {
 
39
#endif
 
40
 
 
41
#if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
 
42
typedef std::ptrdiff_t regoff_t;
 
43
typedef std::size_t regsize_t;
 
44
#else
 
45
typedef ptrdiff_t regoff_t;
 
46
typedef size_t regsize_t;
 
47
#endif
 
48
 
 
49
typedef struct
 
50
{
 
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 :-) */
 
56
} regex_tA;
 
57
 
 
58
#ifndef BOOST_NO_WREGEX
 
59
typedef struct
 
60
{
 
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 :-) */
 
66
} regex_tW;
 
67
#endif
 
68
 
 
69
typedef struct
 
70
{
 
71
   regoff_t rm_so;      /* start of match */
 
72
   regoff_t rm_eo;      /* end of match */
 
73
} regmatch_t;
 
74
 
 
75
/* regcomp() flags */
 
76
typedef enum{
 
77
   REG_BASIC = 0000,
 
78
   REG_EXTENDED = 0001,
 
79
   REG_ICASE = 0002,
 
80
   REG_NOSUB = 0004,
 
81
   REG_NEWLINE = 0010,
 
82
   REG_NOSPEC = 0020,
 
83
   REG_PEND = 0040,
 
84
   REG_DUMP = 0200,
 
85
   REG_NOCOLLATE = 0400,
 
86
   REG_ESCAPE_IN_LISTS = 01000,
 
87
   REG_NEWLINE_ALT = 02000,
 
88
 
 
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,
 
93
 
 
94
   REG_ASSERT = 15,
 
95
   REG_INVARG = 16,
 
96
   REG_ATOI = 255,   /* convert name to number (!) */
 
97
   REG_ITOA = 0400   /* convert number to name (!) */
 
98
} reg_comp_flags;
 
99
 
 
100
/* regexec() flags */
 
101
typedef enum{
 
102
   REG_NOTBOL =    00001,
 
103
   REG_NOTEOL =    00002,
 
104
   REG_STARTEND =  00004
 
105
} reg_exec_flags;
 
106
 
 
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*);
 
111
 
 
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*);
 
117
#endif
 
118
 
 
119
#ifdef UNICODE
 
120
#define regcomp regcompW
 
121
#define regerror regerrorW
 
122
#define regexec regexecW
 
123
#define regfree regfreeW
 
124
#define regex_t regex_tW
 
125
#else
 
126
#define regcomp regcompA
 
127
#define regerror regerrorA
 
128
#define regexec regexecA
 
129
#define regfree regfreeA
 
130
#define regex_t regex_tA
 
131
#endif
 
132
 
 
133
/* regerror() flags */
 
134
typedef enum
 
135
{
 
136
  REG_NOERROR = 0,   /* Success.  */
 
137
  REG_NOMATCH = 1,      /* Didn't find a match (for regexec).  */
 
138
 
 
139
  /* POSIX regcomp return error codes.  (In the order listed in the
 
140
     standard.)  */
 
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 */
 
159
} reg_errcode_t;
 
160
 
 
161
enum match_flags
 
162
{
 
163
   match_default = 0,
 
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
 
179
   
 
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
 
183
};
 
184
 
 
185
 
 
186
#ifdef __cplusplus
 
187
} // extern "C"
 
188
} // namespace
 
189
#endif
 
190
 
 
191
 
 
192
#ifdef __BORLANDC__
 
193
 #if __BORLANDC__ > 0x520
 
194
  #pragma option pop
 
195
 #endif
 
196
#endif
 
197
 
 
198
 
 
199
//
 
200
// C++ high level wrapper goes here:
 
201
//
 
202
#if defined(__cplusplus)
 
203
#include <string>
 
204
#include <vector>
 
205
namespace boost{
 
206
 
 
207
#ifdef __BORLANDC__
 
208
   #if __BORLANDC__ == 0x530
 
209
    #pragma option push -a4 -b
 
210
   #elif __BORLANDC__ > 0x530
 
211
    #pragma option push -a8 -b
 
212
   #endif
 
213
#endif
 
214
 
 
215
class RegEx;
 
216
 
 
217
namespace re_detail{
 
218
 
 
219
class RegExData;
 
220
struct pred1;
 
221
struct pred2;
 
222
struct pred3;
 
223
struct pred4;
 
224
 
 
225
}  // namespace re_detail
 
226
 
 
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);
 
231
#else
 
232
typedef bool (*GrepCallback)(const RegEx& expression);
 
233
typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
 
234
typedef bool (*FindFilesCallback)(const char* file);
 
235
#endif
 
236
 
 
237
class BOOST_REGEX_DECL RegEx
 
238
{
 
239
private:
 
240
   re_detail::RegExData* pdata;
 
241
public:
 
242
   RegEx();
 
243
   RegEx(const RegEx& o);
 
244
   ~RegEx();
 
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;
 
254
   //
 
255
   // now matching operators:
 
256
   //
 
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); }
 
272
#endif
 
273
 
 
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);
 
278
 
 
279
   std::size_t Split(std::vector<std::string>& v, std::string& s, unsigned flags = match_default, unsigned max_count = ~0);
 
280
   //
 
281
   // now operators for returning what matched in more detail:
 
282
   //
 
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); }
 
290
 
 
291
   static const unsigned int npos;
 
292
 
 
293
   friend struct re_detail::pred1;
 
294
   friend struct re_detail::pred2;
 
295
   friend struct re_detail::pred3;
 
296
   friend struct re_detail::pred4;
 
297
};
 
298
 
 
299
#ifdef __BORLANDC__
 
300
  #pragma option pop
 
301
#endif
 
302
 
 
303
} // namespace boost
 
304
 
 
305
#endif
 
306
 
 
307
#endif // include guard
 
308
 
 
309
 
 
310
 
 
311
 
 
312
 
 
313
 
 
314
 
 
315
 
 
316