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 #ifndef BOOST_NO_CXX11_HDR_REGEX 10 11 #include "performance.hpp" 12 #include <regex> 13 14 struct std_regex : public abstract_regex 15 { 16 private: 17 std::regex e; 18 std::cmatch what; 19 public: set_expressionstd_regex20 virtual bool set_expression(const char* pe, bool isperl) 21 { 22 try 23 { 24 e.assign(pe, isperl ? std::regex::ECMAScript : std::regex::extended); 25 } 26 catch(const std::exception&) 27 { 28 return false; 29 } 30 return true; 31 } 32 virtual bool match_test(const char* text); 33 virtual unsigned find_all(const char* text); 34 virtual std::string name(); 35 36 struct initializer 37 { initializerstd_regex::initializer38 initializer() 39 { 40 std_regex::register_instance(boost::shared_ptr<abstract_regex>(new std_regex)); 41 } do_nothingstd_regex::initializer42 void do_nothing()const {} 43 }; 44 static const initializer init; 45 }; 46 47 const std_regex::initializer std_regex::init; 48 49 match_test(const char * text)50bool std_regex::match_test(const char * text) 51 { 52 return regex_match(text, what, e); 53 } 54 find_all(const char * text)55unsigned std_regex::find_all(const char * text) 56 { 57 std::regex_iterator<const char*> i(text, text + std::strlen(text), e), j; 58 unsigned count = 0; 59 while(i != j) 60 { 61 ++i; 62 ++count; 63 } 64 return count; 65 } 66 name()67std::string std_regex::name() 68 { 69 init.do_nothing(); 70 return "std::regex"; 71 } 72 73 #endif 74