00001 #pragma ident "$Id: RegExp.hpp 2978 2011-11-23 03:36:44Z ocibu $"
00002
00008 #ifndef GPSTK_REGEXP_HPP
00009 #define GPSTK_REGEXP_HPP
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <string>
00034 #include <vector>
00035 #include <regex.h>
00036
00037
00038 #if !defined(REG_NOERROR)
00039 #define REG_NOERROR 0
00040 #endif
00041
00042 namespace gpstk
00043 {
00056 class RegExp
00057 {
00058 public:
00059 typedef std::vector<std::string>::const_iterator Iterator;
00060
00061 public:
00062 RegExp(const std::string& pattern = "*",
00063 const int& options = REG_EXTENDED );
00064
00065 RegExp(const RegExp& right);
00066
00067 virtual ~RegExp();
00068
00069 int setPattern(const std::string& pattern);
00070
00071 std::string pattern();
00072
00073 bool match(const std::string& str);
00074
00075 size_t size() const;
00076
00077 size_t count() const;
00078
00079 size_t matchedLength() const;
00080
00081 std::vector<std::string> matchedStrings() const;
00082
00083 std::string operator[] (size_t nth) const;
00084
00085 Iterator begin() const;
00086
00087 Iterator end() const;
00088
00089 RegExp& operator=(const RegExp& right);
00090
00091 bool operator!=(const RegExp& right);
00092
00093 bool operator==(const RegExp& right);
00094
00095 void set_eflags( int mask ) { _eflags |= mask; }
00096
00097 void reset_eflags( int mask ) { _eflags &= ~mask;}
00098
00099
00100
00101
00102
00103 static std::string replace(const std::string& str,
00104 const std::string& pattern,
00105 const std::string& newstr,
00106 const int& flag = 0);
00107
00108 protected:
00109
00110 void handleError(int rc, regex_t& re);
00111
00112 protected:
00113
00114 std::string _pattern;
00115 std::string _subject;
00116 std::vector<std::string> _matched;
00117
00118 regex_t _regex;
00119 int _cflags;
00120 int _eflags;
00121 int _regerr;
00122
00123 };
00124
00125 }
00126
00127
00128 #endif //GPSTK_REGEXP_HPP
00129