Skip to content

Commit

Permalink
Remove dependency on boost.regex headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Oct 28, 2023
1 parent 9caa0f1 commit 9353ac2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 75 deletions.
15 changes: 3 additions & 12 deletions asio/include/asio/detail/regex_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@

#if defined(ASIO_HAS_BOOST_REGEX)

#include <boost/regex_fwd.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 107600
# if defined(BOOST_REGEX_CXX03)
# include <boost/regex/v4/match_flags.hpp>
# else // defined(BOOST_REGEX_CXX03)
# include <boost/regex/v5/match_flags.hpp>
# endif // defined(BOOST_REGEX_CXX03)
#else // BOOST_VERSION >= 107600
# include <boost/regex/v4/match_flags.hpp>
#endif // BOOST_VERSION >= 107600

namespace boost {

template <class BidiIterator>
Expand All @@ -37,6 +25,9 @@ struct sub_match;
template <class BidiIterator, class Allocator>
class match_results;

template <class CharT, class Traits>
class basic_regex;

} // namespace boost

#endif // defined(ASIO_HAS_BOOST_REGEX)
Expand Down
89 changes: 50 additions & 39 deletions asio/include/asio/impl/read_until.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,22 @@ std::size_t read_until(SyncReadStream& s,
#if !defined(ASIO_NO_EXTENSIONS)
#if defined(ASIO_HAS_BOOST_REGEX)

template <typename SyncReadStream, typename DynamicBuffer_v1>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
const boost::regex& expr,
namespace detail {

struct regex_match_flags
{
template <typename T>
operator T() const
{
return T::match_default | T::match_partial;
}
};

} // namespace detail

template <typename SyncReadStream, typename DynamicBuffer_v1, typename Traits>
inline std::size_t read_until(SyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
Expand All @@ -249,10 +261,9 @@ inline std::size_t read_until(SyncReadStream& s,
return bytes_transferred;
}

template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
const boost::regex& expr, asio::error_code& ec,
template <typename SyncReadStream, typename DynamicBuffer_v1, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr, asio::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
Expand All @@ -278,8 +289,8 @@ std::size_t read_until(SyncReadStream& s,
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
if (regex_search(start_pos, end, match_results, expr,
boost::match_default | boost::match_partial))
if (regex_search(start_pos, end, match_results,
expr, detail::regex_match_flags()))
{
if (match_results[0].matched)
{
Expand Down Expand Up @@ -441,16 +452,18 @@ inline std::size_t read_until(SyncReadStream& s,

#if defined(ASIO_HAS_BOOST_REGEX)

template <typename SyncReadStream, typename Allocator>
template <typename SyncReadStream, typename Allocator, typename Traits>
inline std::size_t read_until(SyncReadStream& s,
asio::basic_streambuf<Allocator>& b, const boost::regex& expr)
asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), expr);
}

template <typename SyncReadStream, typename Allocator>
template <typename SyncReadStream, typename Allocator, typename Traits>
inline std::size_t read_until(SyncReadStream& s,
asio::basic_streambuf<Allocator>& b, const boost::regex& expr,
asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr,
asio::error_code& ec)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), expr, ec);
Expand Down Expand Up @@ -629,9 +642,9 @@ std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
#if !defined(ASIO_NO_EXTENSIONS)
#if defined(ASIO_HAS_BOOST_REGEX)

template <typename SyncReadStream, typename DynamicBuffer_v2>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v2 buffers, const boost::regex& expr,
template <typename SyncReadStream, typename DynamicBuffer_v2, typename Traits>
inline std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::basic_regex<char, Traits>& expr,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
Expand All @@ -643,9 +656,9 @@ inline std::size_t read_until(SyncReadStream& s,
return bytes_transferred;
}

template <typename SyncReadStream, typename DynamicBuffer_v2>
template <typename SyncReadStream, typename DynamicBuffer_v2, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::regex& expr, asio::error_code& ec,
const boost::basic_regex<char, Traits>& expr, asio::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
Expand All @@ -668,8 +681,8 @@ std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
if (regex_search(start_pos, end, match_results, expr,
boost::match_default | boost::match_partial))
if (regex_search(start_pos, end, match_results,
expr, detail::regex_match_flags()))
{
if (match_results[0].matched)
{
Expand Down Expand Up @@ -1303,10 +1316,9 @@ namespace detail
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_expr_op_v1(AsyncReadStream& stream,
BufferSequence&& buffers,
const boost::regex& expr, ReadHandler& handler)
template <typename BufferSequence, typename Traits>
read_until_expr_op_v1(AsyncReadStream& stream, BufferSequence&& buffers,
const boost::basic_regex<char, Traits>& expr, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
Expand Down Expand Up @@ -1365,8 +1377,8 @@ namespace detail
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
bool match = regex_search(start_pos, end, match_results, expr_,
boost::match_default | boost::match_partial);
bool match = regex_search(start_pos, end,
match_results, expr_, regex_match_flags());
if (match && match_results[0].matched)
{
// Full match. We're done.
Expand Down Expand Up @@ -1525,11 +1537,11 @@ struct associator<Associator,

#endif // !defined(GENERATING_DOCUMENTATION)

template <typename AsyncReadStream, typename DynamicBuffer_v1,
template <typename AsyncReadStream, typename DynamicBuffer_v1, typename Traits,
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::regex& expr, ReadToken&& token,
const boost::basic_regex<char, Traits>& expr, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
Expand Down Expand Up @@ -1849,12 +1861,12 @@ inline auto async_read_until(AsyncReadStream& s,

#if defined(ASIO_HAS_BOOST_REGEX)

template <typename AsyncReadStream, typename Allocator,
template <typename AsyncReadStream, typename Allocator, typename Traits,
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
asio::basic_streambuf<Allocator>& b,
const boost::regex& expr, ReadToken&& token)
const boost::basic_regex<char, Traits>& expr, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (asio::error_code, std::size_t)>(
Expand Down Expand Up @@ -2407,10 +2419,9 @@ namespace detail
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_expr_op_v2(AsyncReadStream& stream,
BufferSequence&& buffers,
const boost::regex& expr, ReadHandler& handler)
template <typename BufferSequence, typename Traits>
read_until_expr_op_v2(AsyncReadStream& stream, BufferSequence&& buffers,
const boost::basic_regex<char, Traits>& expr, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
Expand Down Expand Up @@ -2474,8 +2485,8 @@ namespace detail
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
bool match = regex_search(start_pos, end, match_results, expr_,
boost::match_default | boost::match_partial);
bool match = regex_search(start_pos, end,
match_results, expr_, regex_match_flags());
if (match && match_results[0].matched)
{
// Full match. We're done.
Expand Down Expand Up @@ -2638,11 +2649,11 @@ struct associator<Associator,

#endif // !defined(GENERATING_DOCUMENTATION)

template <typename AsyncReadStream, typename DynamicBuffer_v2,
template <typename AsyncReadStream, typename DynamicBuffer_v2, typename Traits,
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::regex& expr, ReadToken&& token,
const boost::basic_regex<char, Traits>& expr, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
Expand Down
49 changes: 25 additions & 24 deletions asio/include/asio/read_until.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,9 @@ std::size_t read_until(SyncReadStream& s,
* This data may be the start of a new line, to be extracted by a subsequent
* @c read_until operation.
*/
template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
const boost::regex& expr,
template <typename SyncReadStream, typename DynamicBuffer_v1, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
> = 0,
Expand Down Expand Up @@ -412,10 +411,9 @@ std::size_t read_until(SyncReadStream& s,
* expression. An application will typically leave that data in the dynamic
* buffer sequence for a subsequent read_until operation to examine.
*/
template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
const boost::regex& expr, asio::error_code& ec,
template <typename SyncReadStream, typename DynamicBuffer_v1, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr, asio::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
> = 0,
Expand Down Expand Up @@ -841,9 +839,10 @@ std::size_t read_until(SyncReadStream& s,
* This data may be the start of a new line, to be extracted by a subsequent
* @c read_until operation.
*/
template <typename SyncReadStream, typename Allocator>
template <typename SyncReadStream, typename Allocator, typename Traits>
std::size_t read_until(SyncReadStream& s,
asio::basic_streambuf<Allocator>& b, const boost::regex& expr);
asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr);

/// Read data into a streambuf until some part of the data it contains matches
/// a regular expression.
Expand Down Expand Up @@ -878,9 +877,10 @@ std::size_t read_until(SyncReadStream& s,
* application will typically leave that data in the streambuf for a subsequent
* read_until operation to examine.
*/
template <typename SyncReadStream, typename Allocator>
template <typename SyncReadStream, typename Allocator, typename Traits>
std::size_t read_until(SyncReadStream& s,
asio::basic_streambuf<Allocator>& b, const boost::regex& expr,
asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr,
asio::error_code& ec);

#endif // defined(ASIO_HAS_BOOST_REGEX)
Expand Down Expand Up @@ -1309,9 +1309,9 @@ std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
* This data may be the start of a new line, to be extracted by a subsequent
* @c read_until operation.
*/
template <typename SyncReadStream, typename DynamicBuffer_v2>
template <typename SyncReadStream, typename DynamicBuffer_v2, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::regex& expr,
const boost::basic_regex<char, Traits>& expr,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
> = 0);
Expand Down Expand Up @@ -1352,9 +1352,9 @@ std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
* expression. An application will typically leave that data in the dynamic
* buffer sequence for a subsequent read_until operation to examine.
*/
template <typename SyncReadStream, typename DynamicBuffer_v2>
template <typename SyncReadStream, typename DynamicBuffer_v2, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::regex& expr, asio::error_code& ec,
const boost::basic_regex<char, Traits>& expr, asio::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
> = 0);
Expand Down Expand Up @@ -1897,12 +1897,12 @@ auto async_read_until(AsyncReadStream& s,
* if they are also supported by the @c AsyncReadStream type's
* @c async_read_some operation.
*/
template <typename AsyncReadStream, typename DynamicBuffer_v1,
template <typename AsyncReadStream, typename DynamicBuffer_v1, typename Traits,
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
std::size_t)) ReadToken = default_completion_token_t<
typename AsyncReadStream::executor_type>>
auto async_read_until(AsyncReadStream& s,
DynamicBuffer_v1&& buffers, const boost::regex& expr,
auto async_read_until(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr,
ReadToken&& token = default_completion_token_t<
typename AsyncReadStream::executor_type>(),
constraint_t<
Expand Down Expand Up @@ -2413,12 +2413,13 @@ auto async_read_until(AsyncReadStream& s,
* if they are also supported by the @c AsyncReadStream type's
* @c async_read_some operation.
*/
template <typename AsyncReadStream, typename Allocator,
template <typename AsyncReadStream, typename Allocator, typename Traits,
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
std::size_t)) ReadToken = default_completion_token_t<
typename AsyncReadStream::executor_type>>
auto async_read_until(AsyncReadStream& s,
asio::basic_streambuf<Allocator>& b, const boost::regex& expr,
asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr,
ReadToken&& token = default_completion_token_t<
typename AsyncReadStream::executor_type>())
-> decltype(
Expand Down Expand Up @@ -2925,12 +2926,12 @@ auto async_read_until(AsyncReadStream& s, DynamicBuffer_v2 buffers,
* if they are also supported by the @c AsyncReadStream type's
* @c async_read_some operation.
*/
template <typename AsyncReadStream, typename DynamicBuffer_v2,
template <typename AsyncReadStream, typename DynamicBuffer_v2, typename Traits,
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
std::size_t)) ReadToken = default_completion_token_t<
typename AsyncReadStream::executor_type>>
auto async_read_until(AsyncReadStream& s,
DynamicBuffer_v2 buffers, const boost::regex& expr,
auto async_read_until(AsyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::basic_regex<char, Traits>& expr,
ReadToken&& token = default_completion_token_t<
typename AsyncReadStream::executor_type>(),
constraint_t<
Expand Down

0 comments on commit 9353ac2

Please sign in to comment.