ionflux.org | Impressum

RegExp.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_REGEXP
00002 #define IONFLUX_TOOLS_REGEXP
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * RegExp.hpp                 Regular expression pattern matching
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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

Generated on Tue Mar 14 20:58:29 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6