00001 #ifndef IONFLUX_TOOLS_REGEXP
00002 #define IONFLUX_TOOLS_REGEXP
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 #include <math.h>
00030 #include <pcre.h>
00031 #include <string>
00032 #include <iostream>
00033 #include <vector>
00034 #include <map>
00035 #include "ionflux/tools.hpp"
00036 #include "ionflux/Tree.hpp"
00037
00038 namespace Ionflux
00039 {
00040
00041 namespace Tools
00042 {
00043
00051
00052 typedef std::vector<std::string> ReMatch;
00054 typedef std::vector<ReMatch> ReMatchSet;
00055
00060 class RegExp
00061 {
00062 protected:
00064 pcre *regExp;
00066 std::string pattern;
00068 unsigned int maxSubpatterns;
00070 int pcreOptions;
00071
00072 public:
00077 RegExp();
00078
00085 RegExp(const std::string& initPattern);
00086
00096 RegExp(const std::string& initPattern, int initOptions);
00097
00102 virtual ~RegExp();
00103
00110 virtual void setPattern(const std::string& newPattern);
00111
00118 virtual std::string getPattern();
00119
00142 virtual void setOptions(int newOptions);
00143
00150 virtual int getOptions();
00151
00159 virtual void setMaxSubpatterns(unsigned int newMaxSubpatterns);
00160
00168 virtual unsigned int getMaxSubpatterns();
00169
00186 virtual bool match(const std::string& haystack,
00187 ReMatch* subPatterns = 0);
00188
00203 virtual unsigned int matchAll(const std::string& haystack,
00204 ReMatchSet* subPatterns);
00205
00218 virtual bool match(const std::string& needle,
00219 const std::string& haystack, ReMatch* subPatterns);
00220
00234 virtual unsigned int matchAll(const std::string& needle,
00235 const std::string& haystack, ReMatchSet* subPatterns);
00236
00244 virtual void replace(std::string& haystack,
00245 const std::string& replacement);
00246
00255 virtual void replaceSubpatterns(std::string& haystack,
00256 const std::vector<std::string>& replacement);
00257
00268 virtual void replaceAll(std::string& haystack,
00269 const std::string& replacement);
00270
00281 virtual void replaceAllSubpatterns(std::string& haystack,
00282 const std::vector<std::string>& replacement);
00283
00294 virtual void replace(const std::string& needle, std::string& haystack,
00295 const std::string& replacement);
00296
00307 virtual void replaceSubpatterns(const std::string& needle,
00308 std::string& haystack, const std::vector<std::string>& replacement);
00309
00322 virtual void replaceAll(const std::string& needle,
00323 std::string& haystack, const std::string& replacement);
00324
00337 virtual void replaceAllSubpatterns(const std::string& needle,
00338 std::string& haystack, const std::vector<std::string>& replacement);
00339
00357 static void createMatchMap(const ReMatch& match,
00358 const std::string& fields, const std::string& separator,
00359 const std::string& undefinedPrefix,
00360 std::map<std::string, std::string>& record);
00361
00378 static void createMatchMap(const ReMatch& match,
00379 const std::vector<std::string>& fields,
00380 const std::string& undefinedPrefix,
00381 std::map<std::string, std::string>& record);
00382
00400 static void createMatchTree(const ReMatch& match,
00401 const std::string& fields, const std::string& separator,
00402 const std::string& undefinedPrefix, Node& record);
00403
00420 static void createMatchTree(const ReMatch& match,
00421 const std::vector<std::string>& fields,
00422 const std::string& undefinedPrefix, Node& record);
00423
00424 };
00425
00427
00428 }
00429
00430 }
00431
00435 #endif