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
00043 #ifndef HAVE_PCRE_PP_H
00044 #define HAVE_PCRE_PP_H
00045
00046 #include <string>
00047 #include <sstream>
00048 #include <vector>
00049 #include <stdexcept>
00050
00051 extern "C" {
00052 #include <pcre.h>
00053 }
00054
00055 #include "config.h"
00056
00057
00058
00060 typedef vector<string> Array;
00061
00063 typedef vector<string>::iterator ArrayIterator;
00064
00092 class Pcre {
00093 private:
00094 string _expression;
00095 unsigned int _flags;
00096 bool case_t, global_t;
00097 pcre *p_pcre;
00098 pcre_extra *p_pcre_extra;
00099 int sub_len;
00100 int *sub_vec;
00101 int erroffset;
00102 char *err_str;
00103 Array *resultset;
00104
00105
00106 void reset();
00107
00108
00109 void Compile(int flags);
00110
00111
00112 bool dosearch(const string& stuff, int OffSet);
00113
00114
00115 Array _split(const string& piece, int limit, int start_offset, int end_offset);
00116
00117
00118 string _replace_vars(const string& piece);
00119
00120
00121 void Pcre::zero();
00122
00123 public:
00124
00142 class exception : public runtime_error {
00143 private:
00144 string translate(int num) {
00145 string msg;
00146 switch(num) {
00147 case -1: msg = "PCRE_ERROR_NOMATCH"; break;
00148 case -2: msg = "PCRE_ERROR_NULL"; break;
00149 case -3: msg = "PCRE_ERROR_BADOPTION"; break;
00150 case -4: msg = "PCRE_ERROR_BADMAGIC"; break;
00151 case -5: msg = "PCRE_ERROR_UNKNOWN_NODE"; break;
00152 case -6: msg = "PCRE_ERROR_NOMEMORY"; break;
00153 case -7: msg = "PCRE_ERROR_NOSUBSTRING"; break;
00154 }
00155 return msg;
00156 }
00157 public:
00158 exception(const string & msg) : runtime_error(msg) { }
00159 exception(int num) : runtime_error(translate(num)) { }
00160 };
00161
00162
00163 bool did_match;
00164 int num_matches;
00177 Pcre();
00178
00187 Pcre(const string& expression);
00188
00214 Pcre(const string& expression, const string& flags);
00215
00223 Pcre(const Pcre &P);
00224
00235 const Pcre& operator = (const string& expression);
00236
00249 const Pcre& Pcre::operator = (const Pcre &P);
00250
00256 ~Pcre();
00257
00264 bool search(const string& stuff);
00265
00273 bool search(const string& stuff, int OffSet);
00274
00279 Array* get_sub_strings();
00280
00295 string get_match(int pos);
00296
00315 int get_match_start(int pos);
00316
00335 int get_match_end(int pos);
00336
00344 size_t get_match_length(int pos);
00345
00350 bool matched() { return did_match; };
00351
00355 int matches() { return num_matches; };
00356
00369 Array split(const string& piece);
00370
00384 Array split(const string& piece, int limit);
00385
00400 Array split(const string& piece, int limit, int start_offset);
00401
00417 Array split(const string& piece, int limit, int start_offset, int end_offset);
00418
00432 Array split(const string& piece, vector<int> positions);
00433
00442 string replace(const string& piece, const string& with);
00443 };
00444
00445 #endif