00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FXREX_H
00025 #define FXREX_H
00026
00027 #include "fxdefs.h"
00028
00029 namespace FX {
00030
00031
00033 enum FXRexError {
00034 REGERR_OK,
00035 REGERR_EMPTY,
00036 REGERR_PAREN,
00037 REGERR_BRACK,
00038 REGERR_BRACE,
00039 REGERR_RANGE,
00040 REGERR_ESC,
00041 REGERR_COUNT,
00042 REGERR_NOATOM,
00043 REGERR_REPEAT,
00044 REGERR_BACKREF,
00045 REGERR_CLASS,
00046 REGERR_COMPLEX,
00047 REGERR_MEMORY,
00048 REGERR_TOKEN
00049 };
00050
00051
00053 enum {
00054 REX_NORMAL = 0,
00055 REX_CAPTURE = 1,
00056 REX_ICASE = 2,
00057 REX_NEWLINE = 4,
00058 REX_VERBATIM = 8,
00059 REX_SYNTAX = 16
00060 };
00061
00062
00064 enum {
00065 REX_FORWARD = 0,
00066 REX_BACKWARD = 32,
00067 REX_NOT_BOL = 64,
00068 REX_NOT_EOL = 128,
00069 REX_NOT_EMPTY = 256
00070 };
00071
00072
00100 class FXAPI FXRex {
00101 private:
00102 FXint *code;
00103 private:
00104 static const FXchar *const errors[];
00105 static const FXint fallback[];
00106 public:
00107
00109 FXRex():code((FXint*)fallback){}
00110
00112 FXRex(const FXRex& orig);
00113
00115 FXRex(const FXchar* pattern,FXint mode=REX_NORMAL,FXRexError* error=NULL);
00116
00118 FXRex(const FXString& pattern,FXint mode=REX_NORMAL,FXRexError* error=NULL);
00119
00121 FXRex& operator=(const FXRex& orig);
00122
00128 bool empty() const { return (code==fallback); }
00129
00131 FXRexError parse(const FXchar* pattern,FXint mode=REX_NORMAL);
00132
00134 FXRexError parse(const FXString& pattern,FXint mode=REX_NORMAL);
00135
00143 bool match(const FXchar* string,FXint len,FXint* beg=NULL,FXint* end=NULL,FXint mode=REX_FORWARD,FXint npar=1,FXint fm=0,FXint to=2147483647) const;
00144
00146 bool match(const FXString& string,FXint* beg=NULL,FXint* end=NULL,FXint mode=REX_FORWARD,FXint npar=1,FXint fm=0,FXint to=2147483647) const;
00147
00155 static FXString substitute(const FXchar* string,FXint len,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
00156
00158 static FXString substitute(const FXString& string,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
00159
00161 static const FXchar* getError(FXRexError err){ return errors[err]; }
00162
00164 bool operator==(const FXRex& rex) const;
00165 bool operator!=(const FXRex& rex) const;
00166
00168 friend FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
00169 friend FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
00170
00172 ~FXRex();
00173 };
00174
00175
00176 extern FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
00177 extern FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
00178
00179 }
00180
00181 #endif