• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>read_until (5 of 24 overloads)</title>
5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../boost_asio.html" title="Boost.Asio">
8<link rel="up" href="../read_until.html" title="read_until">
9<link rel="prev" href="overload4.html" title="read_until (4 of 24 overloads)">
10<link rel="next" href="overload6.html" title="read_until (6 of 24 overloads)">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="overload4.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../read_until.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload6.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="boost_asio.reference.read_until.overload5"></a><a class="link" href="overload5.html" title="read_until (5 of 24 overloads)">read_until
28        (5 of 24 overloads)</a>
29</h4></div></div></div>
30<p>
31          Read data into a dynamic buffer sequence until some part of the data it
32          contains matches a regular expression.
33        </p>
34<pre class="programlisting">template&lt;
35    typename <a class="link" href="../SyncReadStream.html" title="Buffer-oriented synchronous read stream requirements">SyncReadStream</a>,
36    typename <a class="link" href="../DynamicBuffer_v1.html" title="Dynamic buffer requirements (version 1)">DynamicBuffer_v1</a>&gt;
37std::size_t read_until(
38    SyncReadStream &amp; s,
39    DynamicBuffer_v1 &amp;&amp; buffers,
40    const boost::regex &amp; expr,
41    typename enable_if&lt; is_dynamic_buffer_v1&lt; typename decay&lt; DynamicBuffer_v1 &gt;::type &gt;::value &amp;&amp;!is_dynamic_buffer_v2&lt; typename decay&lt; DynamicBuffer_v1 &gt;::type &gt;::value &gt;::type *  = 0);
42</pre>
43<p>
44          This function is used to read data into the specified dynamic buffer sequence
45          until the dynamic buffer sequence's get area contains some data that matches
46          a regular expression. The call will block until one of the following conditions
47          is true:
48        </p>
49<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
50<li class="listitem">
51              A substring of the dynamic buffer sequence's get area matches the regular
52              expression.
53            </li>
54<li class="listitem">
55              An error occurred.
56            </li>
57</ul></div>
58<p>
59          This operation is implemented in terms of zero or more calls to the stream's
60          read_some function. If the dynamic buffer sequence's get area already contains
61          data that matches the regular expression, the function returns immediately.
62        </p>
63<h6>
64<a name="boost_asio.reference.read_until.overload5.h0"></a>
65          <span class="phrase"><a name="boost_asio.reference.read_until.overload5.parameters"></a></span><a class="link" href="overload5.html#boost_asio.reference.read_until.overload5.parameters">Parameters</a>
66        </h6>
67<div class="variablelist">
68<p class="title"><b></b></p>
69<dl class="variablelist">
70<dt><span class="term">s</span></dt>
71<dd><p>
72                The stream from which the data is to be read. The type must support
73                the SyncReadStream concept.
74              </p></dd>
75<dt><span class="term">buffers</span></dt>
76<dd><p>
77                A dynamic buffer sequence into which the data will be read.
78              </p></dd>
79<dt><span class="term">expr</span></dt>
80<dd><p>
81                The regular expression.
82              </p></dd>
83</dl>
84</div>
85<h6>
86<a name="boost_asio.reference.read_until.overload5.h1"></a>
87          <span class="phrase"><a name="boost_asio.reference.read_until.overload5.return_value"></a></span><a class="link" href="overload5.html#boost_asio.reference.read_until.overload5.return_value">Return
88          Value</a>
89        </h6>
90<p>
91          The number of bytes in the dynamic buffer sequence's get area up to and
92          including the substring that matches the regular expression.
93        </p>
94<h6>
95<a name="boost_asio.reference.read_until.overload5.h2"></a>
96          <span class="phrase"><a name="boost_asio.reference.read_until.overload5.exceptions"></a></span><a class="link" href="overload5.html#boost_asio.reference.read_until.overload5.exceptions">Exceptions</a>
97        </h6>
98<div class="variablelist">
99<p class="title"><b></b></p>
100<dl class="variablelist">
101<dt><span class="term">boost::system::system_error</span></dt>
102<dd><p>
103                Thrown on failure.
104              </p></dd>
105</dl>
106</div>
107<h6>
108<a name="boost_asio.reference.read_until.overload5.h3"></a>
109          <span class="phrase"><a name="boost_asio.reference.read_until.overload5.remarks"></a></span><a class="link" href="overload5.html#boost_asio.reference.read_until.overload5.remarks">Remarks</a>
110        </h6>
111<p>
112          After a successful read_until operation, the dynamic buffer sequence may
113          contain additional data beyond that which matched the regular expression.
114          An application will typically leave that data in the dynamic buffer sequence
115          for a subsequent read_until operation to examine.
116        </p>
117<h6>
118<a name="boost_asio.reference.read_until.overload5.h4"></a>
119          <span class="phrase"><a name="boost_asio.reference.read_until.overload5.example"></a></span><a class="link" href="overload5.html#boost_asio.reference.read_until.overload5.example">Example</a>
120        </h6>
121<p>
122          To read data into a <code class="computeroutput">std::string</code> until a CR-LF sequence is
123          encountered:
124        </p>
125<pre class="programlisting">std::string data;
126std::size_t n = boost::asio::read_until(s,
127    boost::asio::dynamic_buffer(data), boost::regex("\r\n"));
128std::string line = data.substr(0, n);
129data.erase(0, n);
130</pre>
131<p>
132          After the <code class="computeroutput">read_until</code> operation completes successfully, the
133          string <code class="computeroutput">data</code> contains the delimiter:
134        </p>
135<pre class="programlisting">{ 'a', 'b', ..., 'c', '\r', '\n', 'd', 'e', ... }
136</pre>
137<p>
138          The call to <code class="computeroutput">substr</code> then extracts the data up to and including
139          the delimiter, so that the string <code class="computeroutput">line</code> contains:
140        </p>
141<pre class="programlisting">{ 'a', 'b', ..., 'c', '\r', '\n' }
142</pre>
143<p>
144          After the call to <code class="computeroutput">erase</code>, the remaining data is left in the
145          buffer <code class="computeroutput">b</code> as follows:
146        </p>
147<pre class="programlisting">{ 'd', 'e', ... }
148</pre>
149<p>
150          This data may be the start of a new line, to be extracted by a subsequent
151          <code class="computeroutput">read_until</code> operation.
152        </p>
153</div>
154<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
155<td align="left"></td>
156<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
157      Kohlhoff<p>
158        Distributed under the Boost Software License, Version 1.0. (See accompanying
159        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
160      </p>
161</div></td>
162</tr></table>
163<hr>
164<div class="spirit-nav">
165<a accesskey="p" href="overload4.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../read_until.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload6.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
166</div>
167</body>
168</html>
169