• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////
2 //  Copyright 2015 John Maddock. Distributed under the Boost
3 //  Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
5 //
6 
7 #include "performance.hpp"
8 #include <boost/regex.hpp>
9 #include <boost/version.hpp>
10 #include <boost/lexical_cast.hpp>
11 
12 struct boost_regex : public abstract_regex
13 {
14 private:
15    boost::regex e;
16    boost::cmatch what;
17 public:
set_expressionboost_regex18    virtual bool set_expression(const char* pe, bool isperl)
19    {
20       e.assign(pe, isperl ? boost::regex::perl : boost::regex::extended);
21       return e.status() == 0;
22    }
23    virtual bool match_test(const char* text);
24    virtual unsigned find_all(const char* text);
25    virtual std::string name();
26 
27    struct initializer
28    {
initializerboost_regex::initializer29       initializer()
30       {
31          boost_regex::register_instance(boost::shared_ptr<abstract_regex>(new boost_regex));
32       }
do_nothingboost_regex::initializer33       void do_nothing()const {}
34    };
35    static const initializer init;
36 };
37 
38 const boost_regex::initializer boost_regex::init;
39 
40 
match_test(const char * text)41 bool boost_regex::match_test(const char * text)
42 {
43    return regex_match(text, what, e);
44 }
45 
find_all(const char * text)46 unsigned boost_regex::find_all(const char * text)
47 {
48    boost::regex_iterator<const char*> i(text, text + std::strlen(text), e), j;
49    unsigned count = 0;
50    while(i != j)
51    {
52       ++i;
53       ++count;
54    }
55    return count;
56 }
57 
name()58 std::string boost_regex::name()
59 {
60    init.do_nothing();
61    return boost_name();
62 }
63