## include/boost/regex/v5/regex_grep.hpp

88.5% Lines (23/26) 100.0% List of functions (10/10)
regex_grep.hpp
f(x) Functions (10)
Function Calls Lines Blocks
unsigned int boost::regex_grep<IndexClassesPred, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(IndexClassesPred, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) :34 1x 46.2% 40.0% unsigned int boost::regex_grep<bool (*)(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > const&), __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(bool (*)(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > const&), __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) :34 1x 46.2% 40.0% unsigned int boost::regex_grep<bool (*)(boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > > const&), char const*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(bool (*)(boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > > const&), char const*, char const*, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) :34 1x 30.8% 29.0% unsigned int boost::regex_grep<boost::re_detail_600::split_pred<std::back_insert_iterator<std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::char_traits<char>, std::allocator<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(boost::re_detail_600::split_pred<std::back_insert_iterator<std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::char_traits<char>, std::allocator<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) :34 2x 46.2% 40.0% unsigned int boost::regex_grep<boost::re_detail_600::split_pred<std::ostream_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::char_traits<char> >, char, std::char_traits<char>, std::allocator<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(boost::re_detail_600::split_pred<std::ostream_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::char_traits<char> >, char, std::char_traits<char>, std::allocator<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) :34 99x 42.3% 33.0% unsigned int boost::regex_grep<grep_test_predicate<char, boost::c_regex_traits<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::c_regex_traits<char> >(grep_test_predicate<char, boost::c_regex_traits<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::c_regex_traits<char> > const&, boost::regex_constants::_match_flags) :34 23340x 84.6% 90.0% unsigned int boost::regex_grep<grep_test_predicate<char, boost::cpp_regex_traits<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::cpp_regex_traits<char> >(grep_test_predicate<char, boost::cpp_regex_traits<char> >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::cpp_regex_traits<char> > const&, boost::regex_constants::_match_flags) :34 23340x 84.6% 90.0% unsigned int boost::regex_grep<grep_test_predicate<wchar_t, boost::c_regex_traits<wchar_t> >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, wchar_t, boost::c_regex_traits<wchar_t> >(grep_test_predicate<wchar_t, boost::c_regex_traits<wchar_t> >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::basic_regex<wchar_t, boost::c_regex_traits<wchar_t> > const&, boost::regex_constants::_match_flags) :34 23448x 84.6% 90.0% unsigned int boost::regex_grep<grep_test_predicate<wchar_t, boost::cpp_regex_traits<wchar_t> >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, wchar_t, boost::cpp_regex_traits<wchar_t> >(grep_test_predicate<wchar_t, boost::cpp_regex_traits<wchar_t> >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::basic_regex<wchar_t, boost::cpp_regex_traits<wchar_t> > const&, boost::regex_constants::_match_flags) :34 23448x 84.6% 90.0% unsigned int boost::regex_grep<std::binder1st<std::mem_fun1_t<bool, class_index, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(std::binder1st<std::mem_fun1_t<bool, class_index, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) :34 1x 46.2% 40.0%

Line | TLA | Hits | Source Code
--- | --- | --- | ---
1 |  |  | /*
2 |  |  | *
3 |  |  | * Copyright (c) 1998-2002
4 |  |  | * John Maddock
5 |  |  | *
6 |  |  | * Use, modification and distribution are subject to the
7 |  |  | * Boost Software License, Version 1.0. (See accompanying file
8 |  |  | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 |  |  | *
10 |  |  | */
11 |  |  |
12 |  |  | /*
13 |  |  | * LOCATION: see http://www.boost.org for most recent version.
14 |  |  | * FILE regex_grep.hpp
15 |  |  | * VERSION see <boost/version.hpp>
16 |  |  | * DESCRIPTION: Provides regex_grep implementation.
17 |  |  | */
18 |  |  |
19 |  |  | #ifndef BOOST_REGEX_V5_REGEX_GREP_HPP
20 |  |  | #define BOOST_REGEX_V5_REGEX_GREP_HPP
21 |  |  |
22 |  |  | #include <boost/regex/v5/basic_regex.hpp>
23 |  |  | #include <boost/regex/v5/match_flags.hpp>
24 |  |  | #include <boost/regex/v5/match_results.hpp>
25 |  |  | #include <boost/regex/v5/perl_matcher.hpp>
26 |  |  |
27 |  |  | namespace boost{
28 |  |  |
29 |  |  | //
30 |  |  | // regex_grep:
31 |  |  | // find all non-overlapping matches within the sequence first last:
32 |  |  | //
33 |  |  | BOOST_REGEX_MODULE_EXPORT template <class Predicate, class BidiIterator, class charT, class traits>
34 |  | 93681x | inline unsigned int regex_grep(Predicate foo,
35 |  |  | BidiIterator first,
36 |  |  | BidiIterator last,
37 |  |  | const basic_regex<charT, traits>& e,
38 |  |  | match_flag_type flags = match_default)
39 |  |  | {
40 |  | 93681x | if(e.flags() & regex_constants::failbit)
41 |  | ✗ | return false;
42 |  |  |
43 |  |  | typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
44 |  |  |
45 |  | 93681x | match_results<BidiIterator> m;
46 |  | 93681x | BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
47 |  | 93681x | unsigned int count = 0;
48 |  | 215815x | while(BOOST_REGEX_DETAIL_NS::factory_find(matcher))
49 |  |  | {
50 |  | 84183x | ++count;
51 |  | 84183x | if(0 == foo(m))
52 |  | 98x | return count; // caller doesn't want to go on
53 |  | 84085x | if(m[0].second == last)
54 |  | 55632x | return count; // we've reached the end, don't try and find an extra null match.
55 |  | 28453x | if(m.length() == 0)
56 |  |  | {
57 |  | 4128x | if(m[0].second == last)
58 |  | ✗ | return count;
59 |  |  | // we found a NULL-match, now try to find
60 |  |  | // a non-NULL one at the same position:
61 |  | 4128x | match_results<BidiIterator, match_allocator_type> m2(m);
62 |  | 4128x | matcher.setf(match_not_null | match_continuous);
63 |  | 4128x | if(BOOST_REGEX_DETAIL_NS::factory_find(matcher))
64 |  |  | {
65 |  | 480x | ++count;
66 |  | 480x | if(0 == foo(m))
67 |  | ✗ | return count;
68 |  |  | }
69 |  |  | else
70 |  |  | {
71 |  |  | // reset match back to where it was:
72 |  | 3648x | m = m2;
73 |  |  | }
74 |  | 4128x | matcher.unsetf((match_not_null | match_continuous) & ~flags);
75 |  | 4128x | }
76 |  |  | }
77 |  | 37951x | return count;
78 |  | 93681x | }
79 |  |  |
80 |  |  | //
81 |  |  | // regex_grep convenience interfaces:
82 |  |  | //
83 |  |  | BOOST_REGEX_MODULE_EXPORT template <class Predicate, class charT, class traits>
84 |  |  | inline unsigned int regex_grep(Predicate foo, const charT* str,
85 |  |  | const basic_regex<charT, traits>& e,
86 |  |  | match_flag_type flags = match_default)
87 |  |  | {
88 |  |  | return regex_grep(foo, str, str + traits::length(str), e, flags);
89 |  |  | }
90 |  |  |
91 |  |  | BOOST_REGEX_MODULE_EXPORT template <class Predicate, class ST, class SA, class charT, class traits>
92 |  |  | inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
93 |  |  | const basic_regex<charT, traits>& e,
94 |  |  | match_flag_type flags = match_default)
95 |  |  | {
96 |  |  | return regex_grep(foo, s.begin(), s.end(), e, flags);
97 |  |  | }
98 |  |  |
99 |  |  | } // namespace boost
100 |  |  |
101 |  |  | #endif // BOOST_REGEX_V5_REGEX_GREP_HPP
102 |  |  |
103 |  |  |