• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009-2016 Vladimir Batov.
2 // Use, modification and distribution are subject to the Boost Software License,
3 // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
4 
5 #include "./test.hpp"
6 
7 #if defined(BOOST_CONVERT_IS_NOT_SUPPORTED)
main(int,char const * [])8 int main(int, char const* []) { return 0; }
9 #else
10 
11 #include <boost/convert.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13 
14 static
15 bool
my_cypher(std::string const & value_in,boost::optional<std::string> & value_out)16 my_cypher(std::string const& value_in, boost::optional<std::string>& value_out)
17 {
18     size_t const cypher = 'A' - '1';
19 
20     value_out = value_in;
21 
22     for (std::string::iterator it = value_out->begin(); it != value_out->end(); ++it)
23         (*it < 'A') ? (*it += cypher) : (*it -= cypher);
24 
25     return true;
26 }
27 
28 int
main(int,char const * [])29 main(int, char const* [])
30 {
31     ////////////////////////////////////////////////////////////////////////////
32     // Testing custom converter.
33     ////////////////////////////////////////////////////////////////////////////
34 
35     std::string encrypted = boost::convert<std::string>("ABC", my_cypher).value();
36     std::string decrypted = boost::convert<std::string>(encrypted, my_cypher).value();
37 
38     BOOST_TEST(encrypted == "123");
39     BOOST_TEST(decrypted == "ABC");
40 
41     return boost::report_errors();
42 }
43 
44 #endif
45