00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "pcre++.h"
00043
00044 using namespace std;
00045
00046
00047
00048
00049 Pcre::Pcre(const string& expression) {
00050 _expression = expression;
00051 _flags = 0;
00052 case_t = global_t = false;
00053 zero();
00054 Compile(0);
00055 }
00056
00057 Pcre::Pcre(const string& expression, const string& flags) {
00058 _expression = expression;
00059 unsigned int FLAG = 0;
00060
00061 for(unsigned int flag=0; flag<flags.length(); flag++) {
00062 switch(flags[flag]) {
00063 case 'i': FLAG |= PCRE_CASELESS; case_t = true; break;
00064 case 'm': FLAG |= PCRE_MULTILINE; break;
00065 case 's': FLAG |= PCRE_DOTALL; break;
00066 case 'x': FLAG |= PCRE_EXTENDED; break;
00067 case 'g': global_t = true; break;
00068 }
00069 }
00070
00071 _flags = FLAG;
00072
00073 zero();
00074 Compile(FLAG);
00075 }
00076
00077 Pcre::Pcre(const Pcre &P) {
00078 _expression = P._expression;
00079 _flags = P._flags;
00080 case_t = P.case_t;
00081 global_t = P.global_t;
00082 zero();
00083 Compile(_flags);
00084 }
00085
00086 Pcre::Pcre() {
00087 zero();
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 Pcre::~Pcre() {
00100
00101 if (p_pcre != NULL) {
00102 pcre_free(p_pcre);
00103 }
00104 if (p_pcre_extra != NULL) {
00105 pcre_free(p_pcre_extra);
00106 }
00107 if(sub_vec != NULL) {
00108 delete[] sub_vec;
00109 }
00110 if(num_matches > 0) {
00111 delete resultset;
00112 }
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 const Pcre& Pcre::operator = (const string& expression) {
00122
00123 reset();
00124 _expression = expression;
00125 _flags = 0;
00126 case_t = global_t = false;
00127 Compile(0);
00128 return *this;
00129 }
00130
00131
00132 const Pcre& Pcre::operator = (const Pcre &P) {
00133 reset();
00134 _expression = P._expression;
00135 _flags = P._flags;
00136 case_t = P.case_t;
00137 global_t = P.global_t;
00138 zero();
00139 Compile(_flags);
00140 return *this;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 void Pcre::zero() {
00152
00153 p_pcre_extra = NULL;
00154 p_pcre = NULL;
00155 sub_vec = NULL;
00156 resultset = NULL;
00157 err_str = NULL;
00158 num_matches = -1;
00159 }
00160
00161 void Pcre::reset() {
00162 did_match = false;
00163 num_matches = -1;
00164 }
00165
00166
00167