Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64856 - in trunk: boost/io/detail libs/io/test
From: bdawes_at_[hidden]
Date: 2010-08-16 17:53:35


Author: bemandawes
Date: 2010-08-16 17:53:33 EDT (Mon, 16 Aug 2010)
New Revision: 64856
URL: http://svn.boost.org/trac/boost/changeset/64856

Log:
Fix bug quoted_manip.hpp and in its tests. Thanks to Daniel James for a patch.
Text files modified:
   trunk/boost/io/detail/quoted_manip.hpp | 4
   trunk/libs/io/test/quoted_manip_test.cpp | 145 +++++++++++++++++++++++++--------------
   2 files changed, 95 insertions(+), 54 deletions(-)

Modified: trunk/boost/io/detail/quoted_manip.hpp
==============================================================================
--- trunk/boost/io/detail/quoted_manip.hpp (original)
+++ trunk/boost/io/detail/quoted_manip.hpp 2010-08-16 17:53:33 EDT (Mon, 16 Aug 2010)
@@ -125,15 +125,15 @@
       std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
         const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
       {
+ proxy.string.clear();
         Char c;
         is >> c;
         if (c != proxy.delim)
         {
- proxy.string = c;
+ is.unget();
           is >> proxy.string;
           return is;
         }
- proxy.string.clear();
         {
           boost::io::ios_flags_saver ifs(is);
           is >> std::noskipws;

Modified: trunk/libs/io/test/quoted_manip_test.cpp
==============================================================================
--- trunk/libs/io/test/quoted_manip_test.cpp (original)
+++ trunk/libs/io/test/quoted_manip_test.cpp 2010-08-16 17:53:33 EDT (Mon, 16 Aug 2010)
@@ -21,72 +21,113 @@
 int main()
 {
 
- std::stringstream ss;
   std::wstringstream wss;
 
- const string s1("foo\\bar, \" *");
   string r; // test results
 
- ss << quoted(s1);
- ss >> r;
- BOOST_TEST_EQ(r, "\"foo\\\\bar, \\\" *\"");
-
- ss << quoted(s1.c_str());
- ss >> r;
- BOOST_TEST_EQ(r, "\"foo\\\\bar, \\\" *\"");
-
- ss << quoted(s1);
- ss >> quoted(r);
- BOOST_TEST_EQ(r, s1);
-
- ss << quoted(s1.c_str());
- ss >> quoted(r);
- BOOST_TEST_EQ(r, s1);
+ const string s0("foo");
+ {
+ std::stringstream ss;
+ ss << quoted(s0);
+ ss >> r;
+ BOOST_TEST(r == "\"foo\"");
+ }
+ {
+ std::stringstream ss;
+ ss << quoted(s0);
+ ss >> quoted(r);
+ BOOST_TEST(r == "foo");
+ }
+
+ const string s0s("foo bar");
+ {
+ std::stringstream ss;
+ ss << quoted(s0s);
+ ss >> r;
+ BOOST_TEST(r == "\"foo");
+ }
+ {
+ std::stringstream ss;
+ ss << quoted(s0s);
+ ss >> quoted(r);
+ BOOST_TEST(r == "foo bar");
+ }
 
- string s2("'Jack & Jill'");
+ const string s1("foo\\bar, \" *");
+ {
+ std::stringstream ss;
+ ss << quoted(s1);
+ ss >> r;
+ BOOST_TEST(r == "\"foo\\\\bar,");
+ }
+ {
+ std::stringstream ss;
+ ss << quoted("foo\\bar, \" *");
+ ss >> r;
+ BOOST_TEST(r == "\"foo\\\\bar,");
+ }
+ {
+ std::stringstream ss;
+ ss << quoted(s1);
+ ss >> quoted(r);
+ BOOST_TEST(r == s1);
+ }
+ {
+ std::stringstream ss;
+ ss << quoted(s1.c_str());
+ ss >> quoted(r);
+ BOOST_TEST(r == s1);
+ }
 
- ss << quoted(s2, '&', '\'');
- ss >> r;
- BOOST_TEST_EQ(r, "'&'Jack && Jill&''");
-
- ss << quoted(s2, '&', '\'');
- ss >> quoted(r, '&', '\'');
- BOOST_TEST_EQ(r, s2);
+ string s2("'Jack & Jill'");
+ {
+ std::stringstream ss;
+ ss << quoted(s2, '&', '\'');
+ ss >> quoted(r, '&', '\'');
+ BOOST_TEST(r == s2);
+ }
 
   wstring ws1(L"foo$bar, \" *");
   wstring wr; // test results
-
- wss << quoted(ws1, L'$');
- wss >> wr;
- BOOST_TEST(wr == wstring(L"\"foo$$bar, $\" *\""));
-
- wss << quoted(ws1, L'$');
- wss >> quoted(wr, L'$');
- BOOST_TEST(wr == ws1);
+ {
+ std::wstringstream wss;
+ wss << quoted(ws1, L'$');
+ wss >> quoted(wr, L'$');
+ BOOST_TEST(wr == ws1);
+ }
 
   const string s3("const string");
- ss << quoted(s3);
- ss >> quoted(r);
- BOOST_TEST_EQ(r, s3);
-
- // missing end delimiter test
- ss << "\"abc"; // load ss with faulty quoting
- ss >> quoted(r); // this loops if istream error/eof not detected
- BOOST_TEST_EQ(r, "abc");
-
- // no initial delmiter test
- ss << "abc";
- ss >> quoted(r);
- BOOST_TEST_EQ(r, "abc");
-
- // no initial delmiter, space in ss
- ss << "abc def";
- ss >> quoted(r);
- BOOST_TEST_EQ(r, "abc");
+ {
+ std::stringstream ss;
+ ss << quoted(s3);
+ ss >> quoted(r);
+ BOOST_TEST(r == s3);
+ }
+ {
+ // missing end delimiter test
+ std::stringstream ss;
+ ss << "\"abc"; // load ss with faulty quoting
+ ss >> quoted(r); // this loops if istream error/eof not detected
+ BOOST_TEST(r == "abc");
+ }
+ {
+ // no initial delmiter test
+ std::stringstream ss;
+ ss << "abc";
+ ss >> quoted(r);
+ BOOST_TEST(r == "abc");
+ }
+ {
+ // no initial delmiter, space in ss
+ std::stringstream ss;
+ ss << "abc def";
+ ss >> quoted(r);
+ BOOST_TEST(r == "abc");
+ }
 
   // these should fail to compile because the arguments are const:
   // ss >> quoted(s1);
   // ss >> quoted("foo");
 
- return 0;
+ return boost::report_errors();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk