From 961be4e9270b43709fa36c64daa75f6cf8ec47ec Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Mon, 16 Aug 2010 21:53:33 +0000 Subject: [PATCH 1/3] Fix bug quoted_manip.hpp and in its tests. Thanks to Daniel James for a patch. [SVN r64856] --- include/boost/io/detail/quoted_manip.hpp | 4 +- test/quoted_manip_test.cpp | 141 +++++++++++++++-------- 2 files changed, 93 insertions(+), 52 deletions(-) diff --git a/include/boost/io/detail/quoted_manip.hpp b/include/boost/io/detail/quoted_manip.hpp index 13cfc35..502f422 100644 --- a/include/boost/io/detail/quoted_manip.hpp +++ b/include/boost/io/detail/quoted_manip.hpp @@ -125,15 +125,15 @@ namespace boost std::basic_istream& operator>>(std::basic_istream& is, const quoted_proxy&, 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; diff --git a/test/quoted_manip_test.cpp b/test/quoted_manip_test.cpp index eb481b7..31c6f05 100644 --- a/test/quoted_manip_test.cpp +++ b/test/quoted_manip_test.cpp @@ -21,72 +21,113 @@ using std::wstring; 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, \\\" *\""); + 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"); + } - ss << quoted(s1.c_str()); - ss >> r; - BOOST_TEST_EQ(r, "\"foo\\\\bar, \\\" *\""); + 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"); + } - 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 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); + } string s2("'Jack & Jill'"); - - ss << quoted(s2, '&', '\''); - ss >> r; - BOOST_TEST_EQ(r, "'&'Jack && Jill&''"); - - ss << quoted(s2, '&', '\''); - ss >> quoted(r, '&', '\''); - BOOST_TEST_EQ(r, s2); + { + 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(); } From 4b6617d62bcca75651c26e846cf4048ab237fd0a Mon Sep 17 00:00:00 2001 From: Bryce Adelstein-Lelbach Date: Fri, 14 Jan 2011 02:35:58 +0000 Subject: [PATCH 2/3] Replacing the use of with across Boost. On Linux, GNU's libstdc++, which is the default stdlib for icc and clang, cannot parse the header in version 4.5+ (which thankfully neither compiler advises the use of yet), as it's original C++98-friendly implementation has been replaced with a gnu++0x implementation. is a portable implementation of , providing boost::detail::setfill, boost::detail::setbase, boost::detail::setw, boost::detail::setprecision, boost::detail::setiosflags and boost::detail::resetiosflags. [SVN r68140] --- test/ios_state_test.cpp | 8 ++++---- test/ios_state_unit_test.cpp | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/ios_state_test.cpp b/test/ios_state_test.cpp index 1f7fa84..0900de9 100644 --- a/test/ios_state_test.cpp +++ b/test/ios_state_test.cpp @@ -16,7 +16,7 @@ #include // for boost::io::ios_flags_saver, etc. #include // for std::size_t -#include // for std::setw +#include // for boost::detail::setw #include // for std::ios_base, std::streamsize, etc. #include // for std::cout, etc. #include // for std::istream @@ -143,7 +143,7 @@ saver_tests_1 { using std::locale; using std::ios_base; - using std::setw; + using boost::detail::setw; boost::io::ios_flags_saver const ifls( output ); boost::io::ios_precision_saver const iprs( output ); @@ -168,8 +168,8 @@ saver_tests_1 output.fill( '@' ); output.precision( 9 ); output << '\t' << test_string << '\n'; - output << '\t' << setw( 10 ) << test_num1 << '\n'; - output << '\t' << setw( 15 ) << test_num2 << '\n'; + output << '\t' << boost::detail::setw( 10 ) << test_num1 << '\n'; + output << '\t' << boost::detail::setw( 15 ) << test_num2 << '\n'; output.imbue( loc ); output << '\t' << test_bool << '\n'; diff --git a/test/ios_state_unit_test.cpp b/test/ios_state_unit_test.cpp index 72ce7b5..0d5969c 100644 --- a/test/ios_state_unit_test.cpp +++ b/test/ios_state_unit_test.cpp @@ -13,7 +13,7 @@ #include // for main, BOOST_CHECK, etc. #include // for NULL -#include // for std::setiosflags, etc. +#include // for boost::detail::setiosflags, etc. #include // for std::ios_base #include // for std::cout, std::cerr, etc. #include // for std::iostream @@ -77,7 +77,7 @@ ios_flags_saver_unit_test BOOST_CHECK_EQUAL( (ios_base::showbase | ios_base::internal), ss.flags() ); - ss << setiosflags( ios_base::unitbuf ); + ss << boost::detail::setiosflags( ios_base::unitbuf ); BOOST_CHECK_EQUAL( (ios_base::showbase | ios_base::internal | ios_base::unitbuf), ss.flags() ); } @@ -102,7 +102,7 @@ ios_precision_saver_unit_test BOOST_CHECK_EQUAL( 6, ss.precision() ); - ss << setprecision( 4 ); + ss << boost::detail::setprecision( 4 ); BOOST_CHECK_EQUAL( 4, ss.precision() ); } @@ -113,7 +113,7 @@ ios_precision_saver_unit_test BOOST_CHECK_EQUAL( 8, ss.precision() ); - ss << setprecision( 10 ); + ss << boost::detail::setprecision( 10 ); BOOST_CHECK_EQUAL( 10, ss.precision() ); } @@ -137,7 +137,7 @@ ios_width_saver_unit_test BOOST_CHECK_EQUAL( 0, ss.width() ); - ss << setw( 4 ); + ss << boost::detail::setw( 4 ); BOOST_CHECK_EQUAL( 4, ss.width() ); } @@ -148,7 +148,7 @@ ios_width_saver_unit_test BOOST_CHECK_EQUAL( 8, ss.width() ); - ss << setw( 10 ); + ss << boost::detail::setw( 10 ); BOOST_CHECK_EQUAL( 10, ss.width() ); } @@ -507,7 +507,7 @@ ios_base_all_saver_unit_test BOOST_CHECK_EQUAL( 6, ss.precision() ); BOOST_CHECK_EQUAL( 0, ss.width() ); - ss << hex << unitbuf << setprecision( 5 ) << setw( 7 ); + ss << hex << unitbuf << boost::detail::setprecision( 5 ) << boost::detail::setw( 7 ); BOOST_CHECK_EQUAL( (ios_base::unitbuf | ios_base::hex | ios_base::skipws), ss.flags() ); BOOST_CHECK_EQUAL( 5, ss.precision() ); @@ -560,10 +560,10 @@ ios_all_saver_unit_test ss << oct << showpos << noskipws; BOOST_CHECK_EQUAL( (ios_base::showpos | ios_base::oct), ss.flags() ); - ss << setprecision( 3 ); + ss << boost::detail::setprecision( 3 ); BOOST_CHECK_EQUAL( 3, ss.precision() ); - ss << setw( 9 ); + ss << boost::detail::setw( 9 ); BOOST_CHECK_EQUAL( 9, ss.width() ); ss.setstate( ios_base::eofbit ); @@ -586,7 +586,7 @@ ios_all_saver_unit_test ss.rdbuf( cerr.rdbuf() ); BOOST_CHECK_EQUAL( cerr.rdbuf(), ss.rdbuf() ); - ss << setfill( 'x' ); + ss << boost::detail::setfill( 'x' ); BOOST_CHECK_EQUAL( 'x', ss.fill() ); ss.imbue( locale(locale::classic(), new backward_bool_names) ); From e2fe59318b9782d195767cf65d5a4ebabf2855da Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Sat, 15 Jan 2011 08:11:51 +0000 Subject: [PATCH 3/3] Revert [67111] (addition of boost/detail/iomanip.hpp) and all the commits that depend on it. ([68137], [68140], [68141], [68154], and [68165]). [SVN r68168] --- test/ios_state_test.cpp | 8 ++++---- test/ios_state_unit_test.cpp | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/ios_state_test.cpp b/test/ios_state_test.cpp index 0900de9..1f7fa84 100644 --- a/test/ios_state_test.cpp +++ b/test/ios_state_test.cpp @@ -16,7 +16,7 @@ #include // for boost::io::ios_flags_saver, etc. #include // for std::size_t -#include // for boost::detail::setw +#include // for std::setw #include // for std::ios_base, std::streamsize, etc. #include // for std::cout, etc. #include // for std::istream @@ -143,7 +143,7 @@ saver_tests_1 { using std::locale; using std::ios_base; - using boost::detail::setw; + using std::setw; boost::io::ios_flags_saver const ifls( output ); boost::io::ios_precision_saver const iprs( output ); @@ -168,8 +168,8 @@ saver_tests_1 output.fill( '@' ); output.precision( 9 ); output << '\t' << test_string << '\n'; - output << '\t' << boost::detail::setw( 10 ) << test_num1 << '\n'; - output << '\t' << boost::detail::setw( 15 ) << test_num2 << '\n'; + output << '\t' << setw( 10 ) << test_num1 << '\n'; + output << '\t' << setw( 15 ) << test_num2 << '\n'; output.imbue( loc ); output << '\t' << test_bool << '\n'; diff --git a/test/ios_state_unit_test.cpp b/test/ios_state_unit_test.cpp index 0d5969c..72ce7b5 100644 --- a/test/ios_state_unit_test.cpp +++ b/test/ios_state_unit_test.cpp @@ -13,7 +13,7 @@ #include // for main, BOOST_CHECK, etc. #include // for NULL -#include // for boost::detail::setiosflags, etc. +#include // for std::setiosflags, etc. #include // for std::ios_base #include // for std::cout, std::cerr, etc. #include // for std::iostream @@ -77,7 +77,7 @@ ios_flags_saver_unit_test BOOST_CHECK_EQUAL( (ios_base::showbase | ios_base::internal), ss.flags() ); - ss << boost::detail::setiosflags( ios_base::unitbuf ); + ss << setiosflags( ios_base::unitbuf ); BOOST_CHECK_EQUAL( (ios_base::showbase | ios_base::internal | ios_base::unitbuf), ss.flags() ); } @@ -102,7 +102,7 @@ ios_precision_saver_unit_test BOOST_CHECK_EQUAL( 6, ss.precision() ); - ss << boost::detail::setprecision( 4 ); + ss << setprecision( 4 ); BOOST_CHECK_EQUAL( 4, ss.precision() ); } @@ -113,7 +113,7 @@ ios_precision_saver_unit_test BOOST_CHECK_EQUAL( 8, ss.precision() ); - ss << boost::detail::setprecision( 10 ); + ss << setprecision( 10 ); BOOST_CHECK_EQUAL( 10, ss.precision() ); } @@ -137,7 +137,7 @@ ios_width_saver_unit_test BOOST_CHECK_EQUAL( 0, ss.width() ); - ss << boost::detail::setw( 4 ); + ss << setw( 4 ); BOOST_CHECK_EQUAL( 4, ss.width() ); } @@ -148,7 +148,7 @@ ios_width_saver_unit_test BOOST_CHECK_EQUAL( 8, ss.width() ); - ss << boost::detail::setw( 10 ); + ss << setw( 10 ); BOOST_CHECK_EQUAL( 10, ss.width() ); } @@ -507,7 +507,7 @@ ios_base_all_saver_unit_test BOOST_CHECK_EQUAL( 6, ss.precision() ); BOOST_CHECK_EQUAL( 0, ss.width() ); - ss << hex << unitbuf << boost::detail::setprecision( 5 ) << boost::detail::setw( 7 ); + ss << hex << unitbuf << setprecision( 5 ) << setw( 7 ); BOOST_CHECK_EQUAL( (ios_base::unitbuf | ios_base::hex | ios_base::skipws), ss.flags() ); BOOST_CHECK_EQUAL( 5, ss.precision() ); @@ -560,10 +560,10 @@ ios_all_saver_unit_test ss << oct << showpos << noskipws; BOOST_CHECK_EQUAL( (ios_base::showpos | ios_base::oct), ss.flags() ); - ss << boost::detail::setprecision( 3 ); + ss << setprecision( 3 ); BOOST_CHECK_EQUAL( 3, ss.precision() ); - ss << boost::detail::setw( 9 ); + ss << setw( 9 ); BOOST_CHECK_EQUAL( 9, ss.width() ); ss.setstate( ios_base::eofbit ); @@ -586,7 +586,7 @@ ios_all_saver_unit_test ss.rdbuf( cerr.rdbuf() ); BOOST_CHECK_EQUAL( cerr.rdbuf(), ss.rdbuf() ); - ss << boost::detail::setfill( 'x' ); + ss << setfill( 'x' ); BOOST_CHECK_EQUAL( 'x', ss.fill() ); ss.imbue( locale(locale::classic(), new backward_bool_names) );