]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/performance/std.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / regex / performance / std.cpp
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:
20 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 {
38 initializer()
39 {
40 std_regex::register_instance(boost::shared_ptr<abstract_regex>(new std_regex));
41 }
42 void do_nothing()const {}
43 };
44 static const initializer init;
45 };
46
47 const std_regex::initializer std_regex::init;
48
49
50 bool std_regex::match_test(const char * text)
51 {
52 return regex_match(text, what, e);
53 }
54
55 unsigned 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
67 std::string std_regex::name()
68 {
69 init.do_nothing();
70 return "std::regex";
71 }
72
73 #endif