mirror of
https://github.com/boostorg/io.git
synced 2025-07-30 12:27:13 +02:00
Fix bug quoted_manip.hpp and in its tests. Thanks to Daniel James for a patch.
[SVN r64856]
This commit is contained in:
@ -125,15 +125,15 @@ namespace boost
|
|||||||
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
|
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
|
||||||
const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
|
const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
|
||||||
{
|
{
|
||||||
|
proxy.string.clear();
|
||||||
Char c;
|
Char c;
|
||||||
is >> c;
|
is >> c;
|
||||||
if (c != proxy.delim)
|
if (c != proxy.delim)
|
||||||
{
|
{
|
||||||
proxy.string = c;
|
is.unget();
|
||||||
is >> proxy.string;
|
is >> proxy.string;
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
proxy.string.clear();
|
|
||||||
{
|
{
|
||||||
boost::io::ios_flags_saver ifs(is);
|
boost::io::ios_flags_saver ifs(is);
|
||||||
is >> std::noskipws;
|
is >> std::noskipws;
|
||||||
|
@ -21,72 +21,113 @@ using std::wstring;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
std::stringstream ss;
|
|
||||||
std::wstringstream wss;
|
std::wstringstream wss;
|
||||||
|
|
||||||
const string s1("foo\\bar, \" *");
|
|
||||||
string r; // test results
|
string r; // test results
|
||||||
|
|
||||||
ss << quoted(s1);
|
const string s0("foo");
|
||||||
ss >> r;
|
{
|
||||||
BOOST_TEST_EQ(r, "\"foo\\\\bar, \\\" *\"");
|
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());
|
const string s0s("foo bar");
|
||||||
ss >> r;
|
{
|
||||||
BOOST_TEST_EQ(r, "\"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);
|
const string s1("foo\\bar, \" *");
|
||||||
ss >> quoted(r);
|
{
|
||||||
BOOST_TEST_EQ(r, s1);
|
std::stringstream ss;
|
||||||
|
ss << quoted(s1);
|
||||||
ss << quoted(s1.c_str());
|
ss >> r;
|
||||||
ss >> quoted(r);
|
BOOST_TEST(r == "\"foo\\\\bar,");
|
||||||
BOOST_TEST_EQ(r, s1);
|
}
|
||||||
|
{
|
||||||
|
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'");
|
string s2("'Jack & Jill'");
|
||||||
|
{
|
||||||
ss << quoted(s2, '&', '\'');
|
std::stringstream ss;
|
||||||
ss >> r;
|
ss << quoted(s2, '&', '\'');
|
||||||
BOOST_TEST_EQ(r, "'&'Jack && Jill&''");
|
ss >> quoted(r, '&', '\'');
|
||||||
|
BOOST_TEST(r == s2);
|
||||||
ss << quoted(s2, '&', '\'');
|
}
|
||||||
ss >> quoted(r, '&', '\'');
|
|
||||||
BOOST_TEST_EQ(r, s2);
|
|
||||||
|
|
||||||
wstring ws1(L"foo$bar, \" *");
|
wstring ws1(L"foo$bar, \" *");
|
||||||
wstring wr; // test results
|
wstring wr; // test results
|
||||||
|
{
|
||||||
wss << quoted(ws1, L'$');
|
std::wstringstream wss;
|
||||||
wss >> wr;
|
wss << quoted(ws1, L'$');
|
||||||
BOOST_TEST(wr == wstring(L"\"foo$$bar, $\" *\""));
|
wss >> quoted(wr, L'$');
|
||||||
|
BOOST_TEST(wr == ws1);
|
||||||
wss << quoted(ws1, L'$');
|
}
|
||||||
wss >> quoted(wr, L'$');
|
|
||||||
BOOST_TEST(wr == ws1);
|
|
||||||
|
|
||||||
const string s3("const string");
|
const string s3("const string");
|
||||||
ss << quoted(s3);
|
{
|
||||||
ss >> quoted(r);
|
std::stringstream ss;
|
||||||
BOOST_TEST_EQ(r, s3);
|
ss << quoted(s3);
|
||||||
|
ss >> quoted(r);
|
||||||
// missing end delimiter test
|
BOOST_TEST(r == s3);
|
||||||
ss << "\"abc"; // load ss with faulty quoting
|
}
|
||||||
ss >> quoted(r); // this loops if istream error/eof not detected
|
{
|
||||||
BOOST_TEST_EQ(r, "abc");
|
// missing end delimiter test
|
||||||
|
std::stringstream ss;
|
||||||
// no initial delmiter test
|
ss << "\"abc"; // load ss with faulty quoting
|
||||||
ss << "abc";
|
ss >> quoted(r); // this loops if istream error/eof not detected
|
||||||
ss >> quoted(r);
|
BOOST_TEST(r == "abc");
|
||||||
BOOST_TEST_EQ(r, "abc");
|
}
|
||||||
|
{
|
||||||
// no initial delmiter, space in ss
|
// no initial delmiter test
|
||||||
ss << "abc def";
|
std::stringstream ss;
|
||||||
ss >> quoted(r);
|
ss << "abc";
|
||||||
BOOST_TEST_EQ(r, "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:
|
// these should fail to compile because the arguments are const:
|
||||||
// ss >> quoted(s1);
|
// ss >> quoted(s1);
|
||||||
// ss >> quoted("foo");
|
// ss >> quoted("foo");
|
||||||
|
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user