os/ossrv/ossrv_pub/boost_apis/boost/regex/v4/cregex.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 *
sl@0
     3
 * Copyright (c) 1998-2002
sl@0
     4
 * John Maddock
sl@0
     5
 *
sl@0
     6
 * Use, modification and distribution are subject to the
sl@0
     7
 * Boost Software License, Version 1.0. (See accompanying file
sl@0
     8
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     9
 *
sl@0
    10
 */
sl@0
    11
sl@0
    12
 /*
sl@0
    13
  *   LOCATION:    see http://www.boost.org for most recent version.
sl@0
    14
  *   FILE         cregex.cpp
sl@0
    15
  *   VERSION      see <boost/version.hpp>
sl@0
    16
  *   DESCRIPTION: Declares POSIX API functions
sl@0
    17
  *                + boost::RegEx high level wrapper.
sl@0
    18
  */
sl@0
    19
sl@0
    20
#ifndef BOOST_RE_CREGEX_HPP_INCLUDED
sl@0
    21
#define BOOST_RE_CREGEX_HPP_INCLUDED
sl@0
    22
sl@0
    23
#ifndef BOOST_REGEX_CONFIG_HPP
sl@0
    24
#include <boost/regex/config.hpp>
sl@0
    25
#endif
sl@0
    26
#include <boost/regex/v4/match_flags.hpp>
sl@0
    27
#include <boost/regex/v4/error_type.hpp>
sl@0
    28
sl@0
    29
#ifdef __cplusplus
sl@0
    30
#include <cstddef>
sl@0
    31
#else
sl@0
    32
#include <stddef.h>
sl@0
    33
#endif
sl@0
    34
sl@0
    35
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
    36
#  include BOOST_ABI_PREFIX
sl@0
    37
#endif
sl@0
    38
sl@0
    39
/* include these defs only for POSIX compatablity */
sl@0
    40
#ifdef __cplusplus
sl@0
    41
namespace boost{
sl@0
    42
extern "C" {
sl@0
    43
#endif
sl@0
    44
sl@0
    45
#if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
sl@0
    46
typedef std::ptrdiff_t regoff_t;
sl@0
    47
typedef std::size_t regsize_t;
sl@0
    48
#else
sl@0
    49
typedef ptrdiff_t regoff_t;
sl@0
    50
typedef size_t regsize_t;
sl@0
    51
#endif
sl@0
    52
sl@0
    53
typedef struct
sl@0
    54
{
sl@0
    55
   unsigned int re_magic;
sl@0
    56
#ifdef __cplusplus
sl@0
    57
   std::size_t  re_nsub;      /* number of parenthesized subexpressions */
sl@0
    58
#else
sl@0
    59
   size_t re_nsub; 
sl@0
    60
#endif
sl@0
    61
   const char*  re_endp;       /* end pointer for REG_PEND */
sl@0
    62
   void* guts;                /* none of your business :-) */
sl@0
    63
   match_flag_type eflags;        /* none of your business :-) */
sl@0
    64
} regex_tA;
sl@0
    65
sl@0
    66
#ifndef BOOST_NO_WREGEX
sl@0
    67
typedef struct
sl@0
    68
{
sl@0
    69
   unsigned int re_magic;
sl@0
    70
#ifdef __cplusplus
sl@0
    71
   std::size_t  re_nsub;         /* number of parenthesized subexpressions */
sl@0
    72
#else
sl@0
    73
   size_t re_nsub;
sl@0
    74
#endif
sl@0
    75
   const wchar_t* re_endp;       /* end pointer for REG_PEND */
sl@0
    76
   void* guts;                   /* none of your business :-) */
sl@0
    77
   match_flag_type eflags;           /* none of your business :-) */
sl@0
    78
} regex_tW;
sl@0
    79
#endif
sl@0
    80
sl@0
    81
typedef struct
sl@0
    82
{
sl@0
    83
   regoff_t rm_so;      /* start of match */
sl@0
    84
   regoff_t rm_eo;      /* end of match */
sl@0
    85
} regmatch_t;
sl@0
    86
sl@0
    87
/* regcomp() flags */
sl@0
    88
typedef enum{
sl@0
    89
   REG_BASIC = 0000,
sl@0
    90
   REG_EXTENDED = 0001,
sl@0
    91
   REG_ICASE = 0002,
sl@0
    92
   REG_NOSUB = 0004,
sl@0
    93
   REG_NEWLINE = 0010,
sl@0
    94
   REG_NOSPEC = 0020,
sl@0
    95
   REG_PEND = 0040,
sl@0
    96
   REG_DUMP = 0200,
sl@0
    97
   REG_NOCOLLATE = 0400,
sl@0
    98
   REG_ESCAPE_IN_LISTS = 01000,
sl@0
    99
   REG_NEWLINE_ALT = 02000,
sl@0
   100
   REG_PERLEX = 04000,
sl@0
   101
sl@0
   102
   REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS | REG_PERLEX,
sl@0
   103
   REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS,
sl@0
   104
   REG_GREP = REG_BASIC | REG_NEWLINE_ALT,
sl@0
   105
   REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT,
sl@0
   106
sl@0
   107
   REG_ASSERT = 15,
sl@0
   108
   REG_INVARG = 16,
sl@0
   109
   REG_ATOI = 255,   /* convert name to number (!) */
sl@0
   110
   REG_ITOA = 0400   /* convert number to name (!) */
sl@0
   111
} reg_comp_flags;
sl@0
   112
sl@0
   113
/* regexec() flags */
sl@0
   114
typedef enum{
sl@0
   115
   REG_NOTBOL =    00001,
sl@0
   116
   REG_NOTEOL =    00002,
sl@0
   117
   REG_STARTEND =  00004
sl@0
   118
} reg_exec_flags;
sl@0
   119
sl@0
   120
//
sl@0
   121
// POSIX error codes:
sl@0
   122
//
sl@0
   123
typedef unsigned reg_error_t;
sl@0
   124
typedef reg_error_t reg_errcode_t;  // backwards compatibility
sl@0
   125
sl@0
   126
static const reg_error_t REG_NOERROR = 0;   /* Success.  */
sl@0
   127
static const reg_error_t REG_NOMATCH = 1;   /* Didn't find a match (for regexec).  */
sl@0
   128
sl@0
   129
  /* POSIX regcomp return error codes.  (In the order listed in the
sl@0
   130
     standard.)  */
sl@0
   131
static const reg_error_t REG_BADPAT = 2;    /* Invalid pattern.  */
sl@0
   132
static const reg_error_t REG_ECOLLATE = 3;  /* Undefined collating element.  */
sl@0
   133
static const reg_error_t REG_ECTYPE = 4;    /* Invalid character class name.  */
sl@0
   134
static const reg_error_t REG_EESCAPE = 5;   /* Trailing backslash.  */
sl@0
   135
static const reg_error_t REG_ESUBREG = 6;   /* Invalid back reference.  */
sl@0
   136
static const reg_error_t REG_EBRACK = 7;    /* Unmatched left bracket.  */
sl@0
   137
static const reg_error_t REG_EPAREN = 8;    /* Parenthesis imbalance.  */
sl@0
   138
static const reg_error_t REG_EBRACE = 9;    /* Unmatched \{.  */
sl@0
   139
static const reg_error_t REG_BADBR = 10;    /* Invalid contents of \{\}.  */
sl@0
   140
static const reg_error_t REG_ERANGE = 11;   /* Invalid range end.  */
sl@0
   141
static const reg_error_t REG_ESPACE = 12;   /* Ran out of memory.  */
sl@0
   142
static const reg_error_t REG_BADRPT = 13;   /* No preceding re for repetition op.  */
sl@0
   143
static const reg_error_t REG_EEND = 14;     /* unexpected end of expression */
sl@0
   144
static const reg_error_t REG_ESIZE = 15;    /* expression too big */
sl@0
   145
static const reg_error_t REG_ERPAREN = 8;   /* = REG_EPAREN : unmatched right parenthesis */
sl@0
   146
static const reg_error_t REG_EMPTY = 17;    /* empty expression */
sl@0
   147
static const reg_error_t REG_E_MEMORY = 15; /* = REG_ESIZE : out of memory */
sl@0
   148
static const reg_error_t REG_ECOMPLEXITY = 18; /* complexity too high */
sl@0
   149
static const reg_error_t REG_ESTACK = 19;   /* out of stack space */
sl@0
   150
static const reg_error_t REG_E_UNKNOWN = 20; /* unknown error */
sl@0
   151
static const reg_error_t REG_ENOSYS = 20;   /* = REG_E_UNKNOWN : Reserved. */
sl@0
   152
sl@0
   153
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int);
sl@0
   154
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t);
sl@0
   155
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int);
sl@0
   156
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*);
sl@0
   157
sl@0
   158
#ifndef BOOST_NO_WREGEX
sl@0
   159
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int);
sl@0
   160
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t);
sl@0
   161
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int);
sl@0
   162
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*);
sl@0
   163
#endif
sl@0
   164
sl@0
   165
#ifdef UNICODE
sl@0
   166
#define regcomp regcompW
sl@0
   167
#define regerror regerrorW
sl@0
   168
#define regexec regexecW
sl@0
   169
#define regfree regfreeW
sl@0
   170
#define regex_t regex_tW
sl@0
   171
#else
sl@0
   172
#define regcomp regcompA
sl@0
   173
#define regerror regerrorA
sl@0
   174
#define regexec regexecA
sl@0
   175
#define regfree regfreeA
sl@0
   176
#define regex_t regex_tA
sl@0
   177
#endif
sl@0
   178
sl@0
   179
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
   180
#  include BOOST_ABI_SUFFIX
sl@0
   181
#endif
sl@0
   182
sl@0
   183
#ifdef __cplusplus
sl@0
   184
} // extern "C"
sl@0
   185
} // namespace
sl@0
   186
#endif
sl@0
   187
sl@0
   188
//
sl@0
   189
// C++ high level wrapper goes here:
sl@0
   190
//
sl@0
   191
#if defined(__cplusplus)
sl@0
   192
#include <string>
sl@0
   193
#include <vector>
sl@0
   194
namespace boost{
sl@0
   195
sl@0
   196
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
   197
#  include BOOST_ABI_PREFIX
sl@0
   198
#endif
sl@0
   199
sl@0
   200
class RegEx;
sl@0
   201
sl@0
   202
namespace re_detail{
sl@0
   203
sl@0
   204
class RegExData;
sl@0
   205
struct pred1;
sl@0
   206
struct pred2;
sl@0
   207
struct pred3;
sl@0
   208
struct pred4;
sl@0
   209
sl@0
   210
}  // namespace re_detail
sl@0
   211
sl@0
   212
#if (defined(BOOST_MSVC) || defined(__BORLANDC__)) && !defined(BOOST_DISABLE_WIN32)
sl@0
   213
typedef bool (__cdecl *GrepCallback)(const RegEx& expression);
sl@0
   214
typedef bool (__cdecl *GrepFileCallback)(const char* file, const RegEx& expression);
sl@0
   215
typedef bool (__cdecl *FindFilesCallback)(const char* file);
sl@0
   216
#else
sl@0
   217
typedef bool (*GrepCallback)(const RegEx& expression);
sl@0
   218
typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
sl@0
   219
typedef bool (*FindFilesCallback)(const char* file);
sl@0
   220
#endif
sl@0
   221
sl@0
   222
class BOOST_REGEX_DECL RegEx
sl@0
   223
{
sl@0
   224
private:
sl@0
   225
   re_detail::RegExData* pdata;
sl@0
   226
public:
sl@0
   227
   RegEx();
sl@0
   228
   RegEx(const RegEx& o);
sl@0
   229
   ~RegEx();
sl@0
   230
   explicit RegEx(const char* c, bool icase = false);
sl@0
   231
   explicit RegEx(const std::string& s, bool icase = false);
sl@0
   232
   RegEx& operator=(const RegEx& o);
sl@0
   233
   RegEx& operator=(const char* p);
sl@0
   234
   RegEx& operator=(const std::string& s){ return this->operator=(s.c_str()); }
sl@0
   235
   unsigned int SetExpression(const char* p, bool icase = false);
sl@0
   236
   unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
sl@0
   237
   std::string Expression()const;
sl@0
   238
   unsigned int error_code()const;
sl@0
   239
   //
sl@0
   240
   // now matching operators:
sl@0
   241
   //
sl@0
   242
   bool Match(const char* p, match_flag_type flags = match_default);
sl@0
   243
   bool Match(const std::string& s, match_flag_type flags = match_default) { return Match(s.c_str(), flags); }
sl@0
   244
   bool Search(const char* p, match_flag_type flags = match_default);
sl@0
   245
   bool Search(const std::string& s, match_flag_type flags = match_default) { return Search(s.c_str(), flags); }
sl@0
   246
   unsigned int Grep(GrepCallback cb, const char* p, match_flag_type flags = match_default);
sl@0
   247
   unsigned int Grep(GrepCallback cb, const std::string& s, match_flag_type flags = match_default) { return Grep(cb, s.c_str(), flags); }
sl@0
   248
   unsigned int Grep(std::vector<std::string>& v, const char* p, match_flag_type flags = match_default);
sl@0
   249
   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); }
sl@0
   250
   unsigned int Grep(std::vector<std::size_t>& v, const char* p, match_flag_type flags = match_default);
sl@0
   251
   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); }
sl@0
   252
#ifndef BOOST_REGEX_NO_FILEITER
sl@0
   253
   unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, match_flag_type flags = match_default);
sl@0
   254
   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); }
sl@0
   255
   unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, match_flag_type flags = match_default);
sl@0
   256
   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); }
sl@0
   257
#endif
sl@0
   258
sl@0
   259
   std::string Merge(const std::string& in, const std::string& fmt,
sl@0
   260
                       bool copy = true, match_flag_type flags = match_default);
sl@0
   261
   std::string Merge(const char* in, const char* fmt,
sl@0
   262
                       bool copy = true, match_flag_type flags = match_default);
sl@0
   263
sl@0
   264
   std::size_t Split(std::vector<std::string>& v, std::string& s, match_flag_type flags = match_default, unsigned max_count = ~0);
sl@0
   265
   //
sl@0
   266
   // now operators for returning what matched in more detail:
sl@0
   267
   //
sl@0
   268
   std::size_t Position(int i = 0)const;
sl@0
   269
   std::size_t Length(int i = 0)const;
sl@0
   270
   bool Matched(int i = 0)const;
sl@0
   271
   std::size_t Marks()const;
sl@0
   272
   std::string What(int i = 0)const;
sl@0
   273
   std::string operator[](int i)const { return What(i); }
sl@0
   274
sl@0
   275
   static const std::size_t npos;
sl@0
   276
sl@0
   277
   friend struct re_detail::pred1;
sl@0
   278
   friend struct re_detail::pred2;
sl@0
   279
   friend struct re_detail::pred3;
sl@0
   280
   friend struct re_detail::pred4;
sl@0
   281
};
sl@0
   282
sl@0
   283
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
   284
#  include BOOST_ABI_SUFFIX
sl@0
   285
#endif
sl@0
   286
sl@0
   287
} // namespace boost
sl@0
   288
sl@0
   289
#endif
sl@0
   290
sl@0
   291
#endif // include guard
sl@0
   292
sl@0
   293
sl@0
   294
sl@0
   295
sl@0
   296
sl@0
   297
sl@0
   298
sl@0
   299
sl@0
   300
sl@0
   301