mirror of
https://github.com/boostorg/io.git
synced 2025-07-30 12:27:13 +02:00
Cope with I/O errors or premature eof
[SVN r63099]
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
|
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
|
||||||
<title>Boost quoted string manipulator</title>
|
<title>Boost "quoted" I/O manipulator</title>
|
||||||
<meta name="generator" content="Microsoft FrontPage 5.0" />
|
<meta name="generator" content="Microsoft FrontPage 5.0" />
|
||||||
<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css" />
|
<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css" />
|
||||||
</head>
|
</head>
|
||||||
@ -19,9 +19,9 @@ style="border-collapse: collapse">
|
|||||||
src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle"
|
src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle"
|
||||||
width="300" height="86" border="0" /></a></td>
|
width="300" height="86" border="0" /></a></td>
|
||||||
<td>
|
<td>
|
||||||
<h1 align="center">Quoted String<br>
|
<h1 align="center">"Quoted"
|
||||||
Stream
|
I/O Manipulator<br>
|
||||||
I/O Manipulator</h1>
|
for Strings</h1>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -43,7 +43,7 @@ std::cout << round_trip; // outputs: fooled
|
|||||||
|
|
||||||
assert(original == round_trip); // assert will fire</pre>
|
assert(original == round_trip); // assert will fire</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<p>The Boost quoted string stream I/O manipulator places delimiters, defaulted
|
<p>The Boost <code>quoted</code> stream I/O manipulator places delimiters, defaulted
|
||||||
to the double-quote (<code>"</code>), around strings on output, and strips off
|
to the double-quote (<code>"</code>), around strings on output, and strips off
|
||||||
the delimiters on input. This ensures strings with embedded spaces round-trip as
|
the delimiters on input. This ensures strings with embedded spaces round-trip as
|
||||||
desired. For example,</p>
|
desired. For example,</p>
|
||||||
@ -60,6 +60,11 @@ std::cout << round_trip; // outputs: fooled you
|
|||||||
|
|
||||||
assert(original == round_trip); // assert will not fire</pre>
|
assert(original == round_trip); // assert will not fire</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
<p>If the string contains the delimiter character, on output that character will
|
||||||
|
be preceded by an escape character, as will the escape character itself:</p>
|
||||||
|
<blockquote>
|
||||||
|
<pre>std::cout << quoted("'Jack & Jill'", '&', '\''); // outputs: '&'Jack && Jill&''</pre>
|
||||||
|
</blockquote>
|
||||||
<h2>Header <boost/io/quoted_manip.hpp> synopsis</h2>
|
<h2>Header <boost/io/quoted_manip.hpp> synopsis</h2>
|
||||||
<pre>namespace boost
|
<pre>namespace boost
|
||||||
{
|
{
|
||||||
@ -113,7 +118,8 @@ type with an implementation supplied <code>operator>></code>:</p>
|
|||||||
<code>operator==</code>, then:<ul>
|
<code>operator==</code>, then:<ul>
|
||||||
<li>Turn off the <code>skipws</code> flag.</li>
|
<li>Turn off the <code>skipws</code> flag.</li>
|
||||||
<li><code>string.clear()</code></li>
|
<li><code>string.clear()</code></li>
|
||||||
<li>Until an unescaped <code>delim</code> character is reached, extract
|
<li>Until an unescaped <code>delim</code> character is reached or <code>
|
||||||
|
is.not_good()</code>, extract
|
||||||
characters from <code>os</code> and append them to <code>string</code>,
|
characters from <code>os</code> and append them to <code>string</code>,
|
||||||
except that if an <code>escape</code> is reached, ignore it and append the
|
except that if an <code>escape</code> is reached, ignore it and append the
|
||||||
next character to <code>string</code>.</li>
|
next character to <code>string</code>.</li>
|
||||||
@ -139,7 +145,7 @@ form of the templates. </p>
|
|||||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||||
<p>Revised
|
<p>Revised
|
||||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->18 June 2010<!--webbot bot="Timestamp" endspan i-checksum="17559" --></p>
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->19 June 2010<!--webbot bot="Timestamp" endspan i-checksum="17561" --></p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -13,7 +13,9 @@
|
|||||||
#define BOOST_IO_QUOTED_MANIP
|
#define BOOST_IO_QUOTED_MANIP
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <ios>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iterator>
|
||||||
#include <boost/io/ios_state.hpp>
|
#include <boost/io/ios_state.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@ -130,11 +132,17 @@ namespace boost
|
|||||||
{
|
{
|
||||||
boost::io::ios_flags_saver ifs(is);
|
boost::io::ios_flags_saver ifs(is);
|
||||||
is >> std::noskipws;
|
is >> std::noskipws;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
is >> c;
|
is >> c;
|
||||||
|
if (!is.good()) // cope with I/O errors or end-of-file
|
||||||
|
break;
|
||||||
if (c == proxy.escape)
|
if (c == proxy.escape)
|
||||||
|
{
|
||||||
is >> c;
|
is >> c;
|
||||||
|
if (!is.good()) // cope with I/O errors or end-of-file
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (c == proxy.delim)
|
else if (c == proxy.delim)
|
||||||
break;
|
break;
|
||||||
proxy.string += c;
|
proxy.string += c;
|
||||||
|
Reference in New Issue
Block a user