annotate DEPENDENCIES/generic/include/boost/regex/v4/regex_grep.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 *
Chris@16 3 * Copyright (c) 1998-2002
Chris@16 4 * John Maddock
Chris@16 5 *
Chris@16 6 * Use, modification and distribution are subject to the
Chris@16 7 * Boost Software License, Version 1.0. (See accompanying file
Chris@16 8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 *
Chris@16 10 */
Chris@16 11
Chris@16 12 /*
Chris@16 13 * LOCATION: see http://www.boost.org for most recent version.
Chris@16 14 * FILE regex_grep.hpp
Chris@16 15 * VERSION see <boost/version.hpp>
Chris@16 16 * DESCRIPTION: Provides regex_grep implementation.
Chris@16 17 */
Chris@16 18
Chris@16 19 #ifndef BOOST_REGEX_V4_REGEX_GREP_HPP
Chris@16 20 #define BOOST_REGEX_V4_REGEX_GREP_HPP
Chris@16 21
Chris@16 22
Chris@16 23 namespace boost{
Chris@16 24
Chris@16 25 #ifdef BOOST_MSVC
Chris@16 26 #pragma warning(push)
Chris@16 27 #pragma warning(disable: 4103)
Chris@16 28 #endif
Chris@16 29 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 30 # include BOOST_ABI_PREFIX
Chris@16 31 #endif
Chris@16 32 #ifdef BOOST_MSVC
Chris@16 33 #pragma warning(pop)
Chris@16 34 #endif
Chris@16 35
Chris@16 36 //
Chris@16 37 // regex_grep:
Chris@16 38 // find all non-overlapping matches within the sequence first last:
Chris@16 39 //
Chris@16 40 template <class Predicate, class BidiIterator, class charT, class traits>
Chris@16 41 inline unsigned int regex_grep(Predicate foo,
Chris@16 42 BidiIterator first,
Chris@16 43 BidiIterator last,
Chris@16 44 const basic_regex<charT, traits>& e,
Chris@16 45 match_flag_type flags = match_default)
Chris@16 46 {
Chris@16 47 if(e.flags() & regex_constants::failbit)
Chris@16 48 return false;
Chris@16 49
Chris@16 50 typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
Chris@16 51
Chris@16 52 match_results<BidiIterator> m;
Chris@16 53 re_detail::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
Chris@16 54 unsigned int count = 0;
Chris@16 55 while(matcher.find())
Chris@16 56 {
Chris@16 57 ++count;
Chris@16 58 if(0 == foo(m))
Chris@16 59 return count; // caller doesn't want to go on
Chris@16 60 if(m[0].second == last)
Chris@16 61 return count; // we've reached the end, don't try and find an extra null match.
Chris@16 62 if(m.length() == 0)
Chris@16 63 {
Chris@16 64 if(m[0].second == last)
Chris@16 65 return count;
Chris@16 66 // we found a NULL-match, now try to find
Chris@16 67 // a non-NULL one at the same position:
Chris@16 68 match_results<BidiIterator, match_allocator_type> m2(m);
Chris@16 69 matcher.setf(match_not_null | match_continuous);
Chris@16 70 if(matcher.find())
Chris@16 71 {
Chris@16 72 ++count;
Chris@16 73 if(0 == foo(m))
Chris@16 74 return count;
Chris@16 75 }
Chris@16 76 else
Chris@16 77 {
Chris@16 78 // reset match back to where it was:
Chris@16 79 m = m2;
Chris@16 80 }
Chris@16 81 matcher.unsetf((match_not_null | match_continuous) & ~flags);
Chris@16 82 }
Chris@16 83 }
Chris@16 84 return count;
Chris@16 85 }
Chris@16 86
Chris@16 87 //
Chris@16 88 // regex_grep convenience interfaces:
Chris@16 89 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
Chris@16 90 //
Chris@16 91 // this isn't really a partial specialisation, but template function
Chris@16 92 // overloading - if the compiler doesn't support partial specialisation
Chris@16 93 // then it really won't support this either:
Chris@16 94 template <class Predicate, class charT, class traits>
Chris@16 95 inline unsigned int regex_grep(Predicate foo, const charT* str,
Chris@16 96 const basic_regex<charT, traits>& e,
Chris@16 97 match_flag_type flags = match_default)
Chris@16 98 {
Chris@16 99 return regex_grep(foo, str, str + traits::length(str), e, flags);
Chris@16 100 }
Chris@16 101
Chris@16 102 template <class Predicate, class ST, class SA, class charT, class traits>
Chris@16 103 inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
Chris@16 104 const basic_regex<charT, traits>& e,
Chris@16 105 match_flag_type flags = match_default)
Chris@16 106 {
Chris@16 107 return regex_grep(foo, s.begin(), s.end(), e, flags);
Chris@16 108 }
Chris@16 109 #else // partial specialisation
Chris@16 110 inline unsigned int regex_grep(bool (*foo)(const cmatch&), const char* str,
Chris@16 111 const regex& e,
Chris@16 112 match_flag_type flags = match_default)
Chris@16 113 {
Chris@16 114 return regex_grep(foo, str, str + regex::traits_type::length(str), e, flags);
Chris@16 115 }
Chris@16 116 #ifndef BOOST_NO_WREGEX
Chris@16 117 inline unsigned int regex_grep(bool (*foo)(const wcmatch&), const wchar_t* str,
Chris@16 118 const wregex& e,
Chris@16 119 match_flag_type flags = match_default)
Chris@16 120 {
Chris@16 121 return regex_grep(foo, str, str + wregex::traits_type::length(str), e, flags);
Chris@16 122 }
Chris@16 123 #endif
Chris@16 124 inline unsigned int regex_grep(bool (*foo)(const match_results<std::string::const_iterator>&), const std::string& s,
Chris@16 125 const regex& e,
Chris@16 126 match_flag_type flags = match_default)
Chris@16 127 {
Chris@16 128 return regex_grep(foo, s.begin(), s.end(), e, flags);
Chris@16 129 }
Chris@16 130 #if !defined(BOOST_NO_WREGEX)
Chris@16 131 inline unsigned int regex_grep(bool (*foo)(const match_results<std::basic_string<wchar_t>::const_iterator>&),
Chris@16 132 const std::basic_string<wchar_t>& s,
Chris@16 133 const wregex& e,
Chris@16 134 match_flag_type flags = match_default)
Chris@16 135 {
Chris@16 136 return regex_grep(foo, s.begin(), s.end(), e, flags);
Chris@16 137 }
Chris@16 138 #endif
Chris@16 139 #endif
Chris@16 140
Chris@16 141 #ifdef BOOST_MSVC
Chris@16 142 #pragma warning(push)
Chris@16 143 #pragma warning(disable: 4103)
Chris@16 144 #endif
Chris@16 145 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 146 # include BOOST_ABI_SUFFIX
Chris@16 147 #endif
Chris@16 148 #ifdef BOOST_MSVC
Chris@16 149 #pragma warning(pop)
Chris@16 150 #endif
Chris@16 151
Chris@16 152 } // namespace boost
Chris@16 153
Chris@16 154 #endif // BOOST_REGEX_V4_REGEX_GREP_HPP
Chris@16 155