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 <boost/config.hpp> 8 9 #include "performance.hpp" 10 #include <boost/xpressive/xpressive.hpp> 11 12 using namespace boost::xpressive; 13 14 struct xpressive_regex : public abstract_regex 15 { 16 private: 17 cregex e; 18 cmatch what; 19 public: set_expressionxpressive_regex20 virtual bool set_expression(const char* pe, bool isperl) 21 { 22 if(!isperl) 23 return false; 24 try 25 { 26 e = cregex::compile(pe, regex_constants::ECMAScript); 27 } 28 catch(const std::exception&) 29 { 30 return false; 31 } 32 return true; 33 } 34 virtual bool match_test(const char* text); 35 virtual unsigned find_all(const char* text); 36 virtual std::string name(); 37 38 struct initializer 39 { initializerxpressive_regex::initializer40 initializer() 41 { 42 xpressive_regex::register_instance(boost::shared_ptr<abstract_regex>(new xpressive_regex)); 43 } do_nothingxpressive_regex::initializer44 void do_nothing()const {} 45 }; 46 static const initializer init; 47 }; 48 49 const xpressive_regex::initializer xpressive_regex::init; 50 51 match_test(const char * text)52bool xpressive_regex::match_test(const char * text) 53 { 54 return regex_match(text, what, e); 55 } 56 find_all(const char * text)57unsigned xpressive_regex::find_all(const char * text) 58 { 59 cregex_token_iterator i(text, text + std::strlen(text), e), j; 60 unsigned count = 0; 61 while(i != j) 62 { 63 ++i; 64 ++count; 65 } 66 return count; 67 } 68 name()69std::string xpressive_regex::name() 70 { 71 init.do_nothing(); 72 return "boost::xpressive::cregex"; 73 } 74 75