Menu

[r1017]: / framework / branches / refactoring / regex.cpp  Maximize  Restore  History

Download this file

54 lines (47 with data), 1.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define CPPCMS_SOURCE
#include "regex.h"
#include "config.h"
#ifdef CPPCMS_USE_EXTERNAL_BOOST
# include <boost/regex.hpp>
#else // Internal Boost
# include <cppcms_boost/regex.hpp>
namespace boost = cppcms_boost;
#endif
namespace cppcms { namespace util {
struct regex_result::data {
std::string str;
boost::cmatch match;
};
regex_result::regex_result() : d(new data)
{
}
regex_result::~regex_result()
{
}
std::string regex_result::operator[](int n)
{
return d->match[n];
}
struct regex::data {
boost::regex r;
data(std::string const &e) : r(e) {}
};
regex::regex(std::string const &e) : d(new data(e))
{
}
regex::~regex()
{
}
bool regex::match(std::string const &str,regex_result &res) const
{
//
// Make sure that cmatch is valid, even if original string already is not
//
res.d->str = str;
return boost::regex_match(res.d->str.c_str(),res.d->match,d->r);
}
bool regex::match(std::string const &str) const
{
return boost::regex_match(str.c_str(),d->r);
}
}} // cppcms::util
MongoDB Logo MongoDB