blob: 2a480fd4cfbb699ee6826b50eb3e8a382d25269f [file] [log] [blame]
Jeff Thompson86b6d642013-10-17 15:01:56 -07001/*
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 <ndnboost/version.hpp>
16 * DESCRIPTION: Provides regex_search implementation.
17 */
18
19#ifndef NDNBOOST_REGEX_V4_REGEX_SEARCH_HPP
20#define NDNBOOST_REGEX_V4_REGEX_SEARCH_HPP
21
22
23namespace ndnboost{
24
25#ifdef NDNBOOST_MSVC
26#pragma warning(push)
27#pragma warning(disable: 4103)
28#endif
29#ifdef NDNBOOST_HAS_ABI_HEADERS
30# include NDNBOOST_ABI_PREFIX
31#endif
32#ifdef NDNBOOST_MSVC
33#pragma warning(pop)
34#endif
35
36template <class BidiIterator, class Allocator, class charT, class traits>
37bool 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 return regex_search(first, last, m, e, flags, first);
43}
44
45template <class BidiIterator, class Allocator, class charT, class traits>
46bool 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 if(e.flags() & regex_constants::failbit)
53 return false;
54
55 re_detail::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base);
56 return matcher.find();
57}
58
59//
60// regex_search convenience interfaces:
61#ifndef NDNBOOST_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:
66template <class charT, class Allocator, class traits>
67inline 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 return regex_search(str, str + traits::length(str), m, e, flags);
73}
74
75template <class ST, class SA, class Allocator, class charT, class traits>
76inline 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 return regex_search(s.begin(), s.end(), m, e, flags);
82}
83#else // partial overloads:
84inline 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}
91inline 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 NDNBOOST_NO_WREGEX
100inline 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}
107inline 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
115inline 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(NDNBOOST_NO_WREGEX)
123inline 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
134template <class BidiIterator, class charT, class traits>
135bool 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 re_detail::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 NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING
149
150template <class charT, class traits>
151inline 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
158template <class ST, class SA, class charT, class traits>
159inline 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
166inline 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 NDNBOOST_NO_WREGEX
174inline 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
182inline 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(NDNBOOST_NO_WREGEX)
190inline 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 // NDNBOOST_NO_WREGEX
199
200#endif // partial overload
201
202#ifdef NDNBOOST_MSVC
203#pragma warning(push)
204#pragma warning(disable: 4103)
205#endif
206#ifdef NDNBOOST_HAS_ABI_HEADERS
207# include NDNBOOST_ABI_SUFFIX
208#endif
209#ifdef NDNBOOST_MSVC
210#pragma warning(pop)
211#endif
212
213} // namespace ndnboost
214
215#endif // NDNBOOST_REGEX_V4_REGEX_SEARCH_HPP
216
217