Line data 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_search.hpp
15 : * VERSION see <boost/version.hpp>
16 : * DESCRIPTION: Provides regex_search implementation.
17 : */
18 :
19 : #ifndef BOOST_REGEX_V4_REGEX_SEARCH_HPP
20 : #define BOOST_REGEX_V4_REGEX_SEARCH_HPP
21 :
22 :
23 : namespace boost{
24 :
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
35 :
36 : template <class BidiIterator, class Allocator, class charT, class traits>
37 0 : 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)
41 : {
42 0 : return regex_search(first, last, m, e, flags, first);
43 : }
44 :
45 : template <class BidiIterator, class Allocator, class charT, class traits>
46 0 : 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)
51 : {
52 0 : if(e.flags() & regex_constants::failbit)
53 : return false;
54 :
55 0 : BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base);
56 0 : return matcher.find();
57 : }
58 :
59 : //
60 : // regex_search convenience interfaces:
61 : #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
62 : //
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 0 : 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)
71 : {
72 0 : return regex_search(str, str + traits::length(str), m, e, flags);
73 : }
74 :
75 : template <class ST, class SA, class Allocator, class charT, class traits>
76 0 : 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)
80 : {
81 0 : return regex_search(s.begin(), s.end(), m, e, flags);
82 : }
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)
88 : {
89 : return regex_search(str, str + regex::traits_type::length(str), m, e, flags);
90 : }
91 : inline bool regex_search(const char* first, const char* last,
92 : const regex& e,
93 : match_flag_type flags = match_default)
94 : {
95 : cmatch m;
96 : return regex_search(first, last, m, e, flags | regex_constants::match_any);
97 : }
98 :
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)
104 : {
105 : return regex_search(str, str + wregex::traits_type::length(str), m, e, flags);
106 : }
107 : inline bool regex_search(const wchar_t* first, const wchar_t* last,
108 : const wregex& e,
109 : match_flag_type flags = match_default)
110 : {
111 : wcmatch m;
112 : return regex_search(first, last, m, e, flags | regex_constants::match_any);
113 : }
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)
119 : {
120 : return regex_search(s.begin(), s.end(), m, e, flags);
121 : }
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)
127 : {
128 : return regex_search(s.begin(), s.end(), m, e, flags);
129 : }
130 : #endif
131 :
132 : #endif
133 :
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)
138 : {
139 : if(e.flags() & regex_constants::failbit)
140 : return false;
141 :
142 : match_results<BidiIterator> m;
143 : typedef typename match_results<BidiIterator>::allocator_type match_alloc_type;
144 : BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any, first);
145 : return matcher.find();
146 : }
147 :
148 : #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
149 :
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)
154 : {
155 : return regex_search(str, str + traits::length(str), e, flags);
156 : }
157 :
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)
162 : {
163 : return regex_search(s.begin(), s.end(), e, flags);
164 : }
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)
169 : {
170 : cmatch m;
171 : return regex_search(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
172 : }
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)
177 : {
178 : wcmatch m;
179 : return regex_search(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
180 : }
181 : #endif
182 : inline bool regex_search(const std::string& s,
183 : const regex& e,
184 : match_flag_type flags = match_default)
185 : {
186 : smatch m;
187 : return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
188 : }
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)
193 : {
194 : wsmatch m;
195 : return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
196 : }
197 :
198 : #endif // BOOST_NO_WREGEX
199 :
200 : #endif // partial overload
201 :
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
212 :
213 : } // namespace boost
214 :
215 : #endif // BOOST_REGEX_V4_REGEX_SEARCH_HPP
216 :
217 :
|