]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/performance/pcre.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_
10 #define PCRE2_CODE_UNIT_WIDTH 8
12 #include "performance.hpp"
14 #include <boost/version.hpp>
15 #include <boost/lexical_cast.hpp>
17 struct pcre_regex
: public abstract_regex
21 pcre2_match_data
* pdata
;
26 pdata
= pcre2_match_data_create(30, NULL
);
32 pcre2_match_data_free(pdata
);
34 virtual bool set_expression(const char* pat
, bool isperl
)
41 PCRE2_SIZE erroroffset
;
42 pe
= pcre2_compile((PCRE2_SPTR
)pat
, std::strlen(pat
), PCRE2_MULTILINE
, &errorcode
, &erroroffset
, NULL
);
43 return pe
? true : false;
45 virtual bool match_test(const char* text
);
46 virtual unsigned find_all(const char* text
);
47 virtual std::string
name();
53 pcre_regex::register_instance(boost::shared_ptr
<abstract_regex
>(new pcre_regex
));
55 void do_nothing()const {}
57 static const initializer init
;
60 const pcre_regex::initializer
pcre_regex::init
;
63 bool pcre_regex::match_test(const char * text
)
65 int r
= pcre2_match(pe
, (PCRE2_SPTR
)text
, std::strlen(text
), 0, PCRE2_ANCHORED
, pdata
, NULL
);
69 unsigned pcre_regex::find_all(const char * text
)
73 const char* end
= text
+ std::strlen(text
);
74 while(pcre2_match(pe
, (PCRE2_SPTR
)text
, end
- text
, 0, flags
, pdata
, NULL
) >= 0)
77 PCRE2_SIZE
* v
= pcre2_get_ovector_pointer(pdata
);
83 flags
= *(text
- 1) == '\n' ? 0 : PCRE2_NOTBOL
;
89 std::string
pcre_regex::name()
92 return std::string("PCRE-") + boost::lexical_cast
<std::string
>(PCRE2_MAJOR
) + "." + boost::lexical_cast
<std::string
>(PCRE2_MINOR
);