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_HAS_ABI_HEADERS |
---|
26 | # include BOOST_ABI_PREFIX |
---|
27 | #endif |
---|
28 | |
---|
29 | template <class BidiIterator, class Allocator, class charT, class traits> |
---|
30 | bool regex_search(BidiIterator first, BidiIterator last, |
---|
31 | match_results<BidiIterator, Allocator>& m, |
---|
32 | const basic_regex<charT, traits>& e, |
---|
33 | match_flag_type flags = match_default) |
---|
34 | { |
---|
35 | return regex_search(first, last, m, e, flags, first); |
---|
36 | } |
---|
37 | |
---|
38 | template <class BidiIterator, class Allocator, class charT, class traits> |
---|
39 | bool regex_search(BidiIterator first, BidiIterator last, |
---|
40 | match_results<BidiIterator, Allocator>& m, |
---|
41 | const basic_regex<charT, traits>& e, |
---|
42 | match_flag_type flags, |
---|
43 | BidiIterator base) |
---|
44 | { |
---|
45 | if(e.flags() & regex_constants::failbit) |
---|
46 | return false; |
---|
47 | |
---|
48 | re_detail::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base); |
---|
49 | return matcher.find(); |
---|
50 | } |
---|
51 | |
---|
52 | // |
---|
53 | // regex_search convenience interfaces: |
---|
54 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
---|
55 | // |
---|
56 | // this isn't really a partial specialisation, but template function |
---|
57 | // overloading - if the compiler doesn't support partial specialisation |
---|
58 | // then it really won't support this either: |
---|
59 | template <class charT, class Allocator, class traits> |
---|
60 | inline bool regex_search(const charT* str, |
---|
61 | match_results<const charT*, Allocator>& m, |
---|
62 | const basic_regex<charT, traits>& e, |
---|
63 | match_flag_type flags = match_default) |
---|
64 | { |
---|
65 | return regex_search(str, str + traits::length(str), m, e, flags); |
---|
66 | } |
---|
67 | |
---|
68 | template <class ST, class SA, class Allocator, class charT, class traits> |
---|
69 | inline bool regex_search(const std::basic_string<charT, ST, SA>& s, |
---|
70 | match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
---|
71 | const basic_regex<charT, traits>& e, |
---|
72 | match_flag_type flags = match_default) |
---|
73 | { |
---|
74 | return regex_search(s.begin(), s.end(), m, e, flags); |
---|
75 | } |
---|
76 | #else // partial overloads: |
---|
77 | inline bool regex_search(const char* str, |
---|
78 | cmatch& m, |
---|
79 | const regex& e, |
---|
80 | match_flag_type flags = match_default) |
---|
81 | { |
---|
82 | return regex_search(str, str + regex::traits_type::length(str), m, e, flags); |
---|
83 | } |
---|
84 | inline bool regex_search(const char* first, const char* last, |
---|
85 | const regex& e, |
---|
86 | match_flag_type flags = match_default) |
---|
87 | { |
---|
88 | cmatch m; |
---|
89 | return regex_search(first, last, m, e, flags | regex_constants::match_any); |
---|
90 | } |
---|
91 | |
---|
92 | #ifndef BOOST_NO_WREGEX |
---|
93 | inline bool regex_search(const wchar_t* str, |
---|
94 | wcmatch& m, |
---|
95 | const wregex& e, |
---|
96 | match_flag_type flags = match_default) |
---|
97 | { |
---|
98 | return regex_search(str, str + wregex::traits_type::length(str), m, e, flags); |
---|
99 | } |
---|
100 | inline bool regex_search(const wchar_t* first, const wchar_t* last, |
---|
101 | const wregex& e, |
---|
102 | match_flag_type flags = match_default) |
---|
103 | { |
---|
104 | wcmatch m; |
---|
105 | return regex_search(first, last, m, e, flags | regex_constants::match_any); |
---|
106 | } |
---|
107 | #endif |
---|
108 | inline bool regex_search(const std::string& s, |
---|
109 | smatch& m, |
---|
110 | const regex& e, |
---|
111 | match_flag_type flags = match_default) |
---|
112 | { |
---|
113 | return regex_search(s.begin(), s.end(), m, e, flags); |
---|
114 | } |
---|
115 | #if !defined(BOOST_NO_WREGEX) |
---|
116 | inline bool regex_search(const std::basic_string<wchar_t>& s, |
---|
117 | wsmatch& m, |
---|
118 | const wregex& e, |
---|
119 | match_flag_type flags = match_default) |
---|
120 | { |
---|
121 | return regex_search(s.begin(), s.end(), m, e, flags); |
---|
122 | } |
---|
123 | #endif |
---|
124 | |
---|
125 | #endif |
---|
126 | |
---|
127 | template <class BidiIterator, class charT, class traits> |
---|
128 | bool regex_search(BidiIterator first, BidiIterator last, |
---|
129 | const basic_regex<charT, traits>& e, |
---|
130 | match_flag_type flags = match_default) |
---|
131 | { |
---|
132 | if(e.flags() & regex_constants::failbit) |
---|
133 | return false; |
---|
134 | |
---|
135 | match_results<BidiIterator> m; |
---|
136 | typedef typename match_results<BidiIterator>::allocator_type match_alloc_type; |
---|
137 | re_detail::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any, first); |
---|
138 | return matcher.find(); |
---|
139 | } |
---|
140 | |
---|
141 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
---|
142 | |
---|
143 | template <class charT, class traits> |
---|
144 | inline bool regex_search(const charT* str, |
---|
145 | const basic_regex<charT, traits>& e, |
---|
146 | match_flag_type flags = match_default) |
---|
147 | { |
---|
148 | return regex_search(str, str + traits::length(str), e, flags); |
---|
149 | } |
---|
150 | |
---|
151 | template <class ST, class SA, class charT, class traits> |
---|
152 | inline bool regex_search(const std::basic_string<charT, ST, SA>& s, |
---|
153 | const basic_regex<charT, traits>& e, |
---|
154 | match_flag_type flags = match_default) |
---|
155 | { |
---|
156 | return regex_search(s.begin(), s.end(), e, flags); |
---|
157 | } |
---|
158 | #else // non-template function overloads |
---|
159 | inline bool regex_search(const char* str, |
---|
160 | const regex& e, |
---|
161 | match_flag_type flags = match_default) |
---|
162 | { |
---|
163 | cmatch m; |
---|
164 | return regex_search(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any); |
---|
165 | } |
---|
166 | #ifndef BOOST_NO_WREGEX |
---|
167 | inline bool regex_search(const wchar_t* str, |
---|
168 | const wregex& e, |
---|
169 | match_flag_type flags = match_default) |
---|
170 | { |
---|
171 | wcmatch m; |
---|
172 | return regex_search(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any); |
---|
173 | } |
---|
174 | #endif |
---|
175 | inline bool regex_search(const std::string& s, |
---|
176 | const regex& e, |
---|
177 | match_flag_type flags = match_default) |
---|
178 | { |
---|
179 | smatch m; |
---|
180 | return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any); |
---|
181 | } |
---|
182 | #if !defined(BOOST_NO_WREGEX) |
---|
183 | inline bool regex_search(const std::basic_string<wchar_t>& s, |
---|
184 | const wregex& e, |
---|
185 | match_flag_type flags = match_default) |
---|
186 | { |
---|
187 | wsmatch m; |
---|
188 | return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any); |
---|
189 | } |
---|
190 | |
---|
191 | #endif // BOOST_NO_WREGEX |
---|
192 | |
---|
193 | #endif // partial overload |
---|
194 | |
---|
195 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
196 | # include BOOST_ABI_SUFFIX |
---|
197 | #endif |
---|
198 | |
---|
199 | } // namespace boost |
---|
200 | |
---|
201 | #endif // BOOST_REGEX_V4_REGEX_SEARCH_HPP |
---|
202 | |
---|
203 | |
---|