1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
7 <title>Boost "quoted" I/O manipulator</title>
8 <meta name="generator" content="Microsoft FrontPage 5.0" />
9 <link rel="stylesheet" type="text/css" href="../../../doc/src/minimal.css" />
14 <table border="0" cellpadding="5" cellspacing="0"
15 style="border-collapse: collapse">
18 <td width="277"><a href="../../../index.htm"><img
19 src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle"
20 width="300" height="86" border="0" /></a></td>
22 <h1 align="center">"Quoted"
30 <table border="1" cellpadding="5" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111">
33 <p align="center"><b>"Quoted"
35 for Strings are not yet accepted into Boost as public components. Thus the
36 header file is currently located in <boost/io/detail/quoted_manip.hpp></b></td>
41 <p>C++ Standard library stream I/O for strings that contain embedded spaces
42 can produce unexpected results. For example,</p>
44 <pre>std::stringstream ss;
45 std::string original = "fooled you";
46 std::string round_trip;
49 ss >> round_trip;
51 std::cout << original; // outputs: fooled you
52 std::cout << round_trip; // outputs: fooled
54 assert(original == round_trip); // assert will fire</pre>
56 <p>The Boost <code>quoted</code> stream I/O manipulator places delimiters, defaulted
57 to the double-quote (<code>"</code>), around strings on output, and strips off
58 the delimiters on input. This ensures strings with embedded spaces round-trip as
59 desired. For example,</p>
61 <pre>std::stringstream ss;
62 std::string original = "fooled you";
63 std::string round_trip;
65 ss << quoted(original);
66 ss >> quoted(round_trip);
68 std::cout << quoted(original); // outputs: "fooled you"
69 std::cout << round_trip; // outputs: fooled you
71 assert(original == round_trip); // assert will not fire</pre>
73 <p>If the string contains the delimiter character, on output that character will
74 be preceded by an escape character, as will the escape character itself:</p>
76 <pre>std::cout << quoted("'Jack & Jill'", '&', '\''); // outputs: '&'Jack && Jill&''</pre>
78 <h2>Header <a href="../../../boost/io/detail/quoted_manip.hpp"><boost/io/quoted_manip.hpp></a> synopsis</h2>
83 // manipulator for const std::basic_string&
85 template <class Char, class Traits, class Alloc>
86 <b><i>unspecified-type1</i></b> quoted(const std::basic_string<Char, Traits, Alloc>& string,
87 Char escape='\\', Char delim='\"');
89 // manipulator for const C-string*
91 template <class Char>
92 <b><i>unspecified-type2</i></b> quoted(const Char* string,
93 Char escape='\\', Char delim='\"');
95 // manipulator for non-const std::basic_string&
97 template <class Char, class Traits, class Alloc>
98 <b><i>unspecified-type3</i></b> quoted(std::basic_string<Char, Traits, Alloc>& string,
99 Char escape='\\', Char delim='\"');
102 <p><i><b><code>unspecified_type1</code></b></i>, <i><b><code>unspecified_type2</code></b></i>,
103 and <i><b><code>unspecified_type3</code></b></i> are implementation supplied
104 types with implementation supplied <code>operator<<</code>:</p>
106 <pre>template <class Char, class Traits>
107 std::basic_ostream<Char, Traits>&
108 operator<<(std::basic_ostream<Char, Traits>& os, const <i><b><code>unspecified_typeN</code></b></i>& proxy);</pre>
109 <p><i>Effects:</i> Inserts characters into <code>os</code>:</p>
111 <li><code>delim</code>.</li>
112 <li>Each character in <code>string</code>. If the character to be output is
113 equal to <code>escape</code> or <code>delim</code>, as determined by <code>
114 operator==</code>, first output <code>escape</code>. </li>
115 <li><code>delim</code>.</li>
117 <p><i>Remarks:</i> <code>string</code>, <code>escape</code>, and <code>delim</code>
118 have the type and value of the corresponding arguments of the call to the <code>
119 quoted</code> function that constructed <code>proxy</code>.</p>
120 <p><i>Returns:</i> <code>os</code>. </p>
122 <p><i><b><code>unspecified_type3</code></b></i> is an implementation supplied
123 type with an implementation supplied <code>operator>></code>:</p>
125 <pre>template <class Char, class Traits>
126 std::basic_istream<Char, Traits>&
127 operator>>(std::basic_istream<Char, Traits>& is, const <i><b><code>unspecified_type3</code></b></i>& proxy);</pre>
128 <p><i>Effects:</i> Extracts characters from <code>os</code>:</p>
130 <li>If the first character extracted is equal to delim, as determined by
131 <code>operator==</code>, then:<ul>
132 <li>Turn off the <code>skipws</code> flag.</li>
133 <li><code>string.clear()</code></li>
134 <li>Until an unescaped <code>delim</code> character is reached or <code>
135 is.not_good()</code>, extract
136 characters from <code>os</code> and append them to <code>string</code>,
137 except that if an <code>escape</code> is reached, ignore it and append the
138 next character to <code>string</code>.</li>
139 <li>Discard the final <code>delim</code> character.</li>
140 <li>Restore the <code>skipws</code> flag to its original value.</li>
143 <li>Otherwise, <code>os >> string</code>.</li>
145 <p><i>Remarks:</i> <code>string</code>, <code>escape</code>, and <code>delim</code>
146 have the type and value of the corresponding arguments of the call to the <code>
147 quoted</code> function that constructed <code>proxy</code>.</p>
148 <p><i>Returns:</i> <code>is</code>. </p>
150 <h2>Acknowledgements</h2>
151 <p>The <code>quoted()</code> stream manipulator emerged from discussions on the
152 Boost developers mailing list. Participants included Beman Dawes, Rob Stewart,
153 Alexander Lamaison, Eric Niebler, Vicente Botet, Andrey Semashev, Phil Richards,
154 and Rob Murray. Eric Niebler's suggestions provided the basis for the name and
155 form of the templates. </p>
157 <p>© Copyright Beman Dawes, 2002, 2006, 2007, 2009, 2010</p>
158 <p>Distributed under the Boost Software License, Version 1.0. See
159 <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
161 <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->08 March 2013<!--webbot bot="Timestamp" endspan i-checksum="27284" --></p>