00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SBUILD_REGEX_H
00020 #define SBUILD_REGEX_H
00021
00022 #include <istream>
00023 #include <ostream>
00024 #include <string>
00025
00026 #include <sbuild/sbuild-config.h>
00027 #ifdef HAVE_REGEX_REGEX
00028 # include <regex>
00029 #else
00030 # include <boost/regex.hpp>
00031 namespace std {
00032 using boost::regex;
00033 using boost::regex_error;
00034 using boost::regex_search;
00035 }
00036 #endif
00037
00038 namespace sbuild
00039 {
00040
00055 class regex
00056 {
00057 public:
00059 regex ():
00060 comp(),
00061 rstr()
00062 {}
00063
00071 regex (std::string const& pattern):
00072 comp(pattern, std::regex::extended),
00073 rstr(pattern)
00074 {}
00075
00083 regex (const char *pattern):
00084 comp(pattern, std::regex::extended),
00085 rstr(pattern)
00086 {}
00087
00089 ~regex ()
00090 {}
00091
00099 regex (const regex& rhs):
00100 comp(rhs.comp),
00101 rstr(rhs.rstr)
00102 {}
00103
00104 std::string const&
00105 str() const
00106 {
00107 return rstr;
00108 }
00109
00110 bool
00111 compare (regex const& rhs) const
00112 {
00113 return this->rstr != rhs.rstr;
00114 }
00115
00116 bool
00117 search (std::string const& str) const
00118 {
00119 return std::regex_search(str, this->comp);
00120 }
00121
00131 template <class charT, class traits>
00132 friend
00133 std::basic_istream<charT,traits>&
00134 operator >> (std::basic_istream<charT,traits>& stream,
00135 regex& rhs)
00136 {
00137 std::string regex;
00138
00139 if (std::getline(stream, regex))
00140 {
00141 rhs.comp.assign(regex, std::regex::extended);
00142 rhs.rstr = regex;
00143 }
00144
00145 return stream;
00146 }
00147
00155 template <class charT, class traits>
00156 friend
00157 std::basic_ostream<charT,traits>&
00158 operator << (std::basic_ostream<charT,traits>& stream,
00159 regex const& rhs)
00160 {
00161 return stream << rhs.str();
00162 }
00163
00164 private:
00166 std::regex comp;
00168 std::string rstr;
00169 };
00170
00174 inline bool
00175 regex_search (const std::string& str,
00176 regex const& regex)
00177 {
00178 return regex.search(str);
00179 }
00180
00181 }
00182
00183 #endif
00184
00185
00186
00187
00188
00189