• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2010 Beman Dawes
3 
4 Copyright 2019 Glen Joseph Fernandes
5 (glenjofe@gmail.com)
6 
7 Distributed under the Boost Software License, Version 1.0.
8 (http://www.boost.org/LICENSE_1_0.txt)
9 */
10 #include <boost/io/quoted.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <iostream>
13 #include <sstream>
14 
main()15 int main()
16 {
17     const std::string s0("foo");
18     std::string r;
19     {
20         std::stringstream ss;
21         ss << boost::io::quoted(s0);
22         ss >> r;
23         BOOST_TEST(r == "\"foo\"");
24     }
25     {
26         std::stringstream ss;
27         ss << boost::io::quoted(s0);
28         ss >> boost::io::quoted(r);
29         BOOST_TEST(r == "foo");
30     }
31     const std::string s0s("foo bar");
32     {
33         std::stringstream ss;
34         ss << boost::io::quoted(s0s);
35         ss >> r;
36         BOOST_TEST(r == "\"foo");
37     }
38     {
39         std::stringstream ss;
40         ss << boost::io::quoted(s0s);
41         ss >> boost::io::quoted(r);
42         BOOST_TEST(r == "foo bar");
43     }
44     const std::string s1("foo\\bar, \" *");
45     {
46         std::stringstream ss;
47         ss << boost::io::quoted(s1);
48         ss >> r;
49         BOOST_TEST(r == "\"foo\\\\bar,");
50     }
51     {
52         std::stringstream ss;
53         ss << boost::io::quoted("foo\\bar, \" *");
54         ss >> r;
55         BOOST_TEST(r == "\"foo\\\\bar,");
56     }
57     {
58         std::stringstream ss;
59         ss << boost::io::quoted(s1);
60         ss >> boost::io::quoted(r);
61         BOOST_TEST(r == s1);
62     }
63     {
64         std::stringstream ss;
65         ss << boost::io::quoted(s1.c_str());
66         ss >> boost::io::quoted(r);
67         BOOST_TEST(r == s1);
68     }
69     std::string s2("'Jack & Jill'");
70     {
71         std::stringstream ss;
72         ss << boost::io::quoted(s2, '&', '\'');
73         ss >> boost::io::quoted(r, '&', '\'');
74         BOOST_TEST(r == s2);
75     }
76     const std::wstring ws1(L"foo$bar, \" *");
77     std::wstring wr;
78     {
79         std::wstringstream wss;
80         wss << boost::io::quoted(ws1, L'$');
81         wss >> boost::io::quoted(wr,  L'$');
82         BOOST_TEST(wr == ws1);
83     }
84     const std::string s3("const string");
85     {
86         std::stringstream ss;
87         ss << boost::io::quoted(s3);
88         ss >> boost::io::quoted(r);
89         BOOST_TEST(r == s3);
90     }
91     {
92         std::stringstream ss;
93         ss << "\"abc";
94         ss >> boost::io::quoted(r);
95         BOOST_TEST(r == "abc");
96     }
97     {
98         std::stringstream ss;
99         ss << "abc";
100         ss >> boost::io::quoted(r);
101         BOOST_TEST(r == "abc");
102     }
103     {
104         std::stringstream ss;
105         ss << "abc def";
106         ss >> boost::io::quoted(r);
107         BOOST_TEST(r == "abc");
108     }
109     return boost::report_errors();
110 }
111