fix doc example typo
[boost.git] / boost / regex / v4 / regex_search.hpp
blobcf5579d2c722f12937dc07d359f5ea3aa17b2366
1 /*
3 * Copyright (c) 1998-2002
4 * John Maddock
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)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE regex_search.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Provides regex_search implementation.
19 #ifndef BOOST_REGEX_V4_REGEX_SEARCH_HPP
20 #define BOOST_REGEX_V4_REGEX_SEARCH_HPP
23 namespace boost{
25 #ifdef BOOST_MSVC
26 #pragma warning(push)
27 #pragma warning(disable: 4103)
28 #endif
29 #ifdef BOOST_HAS_ABI_HEADERS
30 # include BOOST_ABI_PREFIX
31 #endif
32 #ifdef BOOST_MSVC
33 #pragma warning(pop)
34 #endif
36 template <class BidiIterator, class Allocator, class charT, class traits>
37 bool regex_search(BidiIterator first, BidiIterator last,
38 match_results<BidiIterator, Allocator>& m,
39 const basic_regex<charT, traits>& e,
40 match_flag_type flags = match_default)
42 return regex_search(first, last, m, e, flags, first);
45 template <class BidiIterator, class Allocator, class charT, class traits>
46 bool regex_search(BidiIterator first, BidiIterator last,
47 match_results<BidiIterator, Allocator>& m,
48 const basic_regex<charT, traits>& e,
49 match_flag_type flags,
50 BidiIterator base)
52 if(e.flags() & regex_constants::failbit)
53 return false;
55 re_detail::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base);
56 return matcher.find();
60 // regex_search convenience interfaces:
61 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
63 // this isn't really a partial specialisation, but template function
64 // overloading - if the compiler doesn't support partial specialisation
65 // then it really won't support this either:
66 template <class charT, class Allocator, class traits>
67 inline bool regex_search(const charT* str,
68 match_results<const charT*, Allocator>& m,
69 const basic_regex<charT, traits>& e,
70 match_flag_type flags = match_default)
72 return regex_search(str, str + traits::length(str), m, e, flags);
75 template <class ST, class SA, class Allocator, class charT, class traits>
76 inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
77 match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
78 const basic_regex<charT, traits>& e,
79 match_flag_type flags = match_default)
81 return regex_search(s.begin(), s.end(), m, e, flags);
83 #else // partial overloads:
84 inline bool regex_search(const char* str,
85 cmatch& m,
86 const regex& e,
87 match_flag_type flags = match_default)
89 return regex_search(str, str + regex::traits_type::length(str), m, e, flags);
91 inline bool regex_search(const char* first, const char* last,
92 const regex& e,
93 match_flag_type flags = match_default)
95 cmatch m;
96 return regex_search(first, last, m, e, flags | regex_constants::match_any);
99 #ifndef BOOST_NO_WREGEX
100 inline bool regex_search(const wchar_t* str,
101 wcmatch& m,
102 const wregex& e,
103 match_flag_type flags = match_default)
105 return regex_search(str, str + wregex::traits_type::length(str), m, e, flags);
107 inline bool regex_search(const wchar_t* first, const wchar_t* last,
108 const wregex& e,
109 match_flag_type flags = match_default)
111 wcmatch m;
112 return regex_search(first, last, m, e, flags | regex_constants::match_any);
114 #endif
115 inline bool regex_search(const std::string& s,
116 smatch& m,
117 const regex& e,
118 match_flag_type flags = match_default)
120 return regex_search(s.begin(), s.end(), m, e, flags);
122 #if !defined(BOOST_NO_WREGEX)
123 inline bool regex_search(const std::basic_string<wchar_t>& s,
124 wsmatch& m,
125 const wregex& e,
126 match_flag_type flags = match_default)
128 return regex_search(s.begin(), s.end(), m, e, flags);
130 #endif
132 #endif
134 template <class BidiIterator, class charT, class traits>
135 bool regex_search(BidiIterator first, BidiIterator last,
136 const basic_regex<charT, traits>& e,
137 match_flag_type flags = match_default)
139 if(e.flags() & regex_constants::failbit)
140 return false;
142 match_results<BidiIterator> m;
143 typedef typename match_results<BidiIterator>::allocator_type match_alloc_type;
144 re_detail::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any, first);
145 return matcher.find();
148 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
150 template <class charT, class traits>
151 inline bool regex_search(const charT* str,
152 const basic_regex<charT, traits>& e,
153 match_flag_type flags = match_default)
155 return regex_search(str, str + traits::length(str), e, flags);
158 template <class ST, class SA, class charT, class traits>
159 inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
160 const basic_regex<charT, traits>& e,
161 match_flag_type flags = match_default)
163 return regex_search(s.begin(), s.end(), e, flags);
165 #else // non-template function overloads
166 inline bool regex_search(const char* str,
167 const regex& e,
168 match_flag_type flags = match_default)
170 cmatch m;
171 return regex_search(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
173 #ifndef BOOST_NO_WREGEX
174 inline bool regex_search(const wchar_t* str,
175 const wregex& e,
176 match_flag_type flags = match_default)
178 wcmatch m;
179 return regex_search(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
181 #endif
182 inline bool regex_search(const std::string& s,
183 const regex& e,
184 match_flag_type flags = match_default)
186 smatch m;
187 return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
189 #if !defined(BOOST_NO_WREGEX)
190 inline bool regex_search(const std::basic_string<wchar_t>& s,
191 const wregex& e,
192 match_flag_type flags = match_default)
194 wsmatch m;
195 return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
198 #endif // BOOST_NO_WREGEX
200 #endif // partial overload
202 #ifdef BOOST_MSVC
203 #pragma warning(push)
204 #pragma warning(disable: 4103)
205 #endif
206 #ifdef BOOST_HAS_ABI_HEADERS
207 # include BOOST_ABI_SUFFIX
208 #endif
209 #ifdef BOOST_MSVC
210 #pragma warning(pop)
211 #endif
213 } // namespace boost
215 #endif // BOOST_REGEX_V4_REGEX_SEARCH_HPP