1 | // Copyright (c) 2009-2020 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_CXX14) |
8 | int main(int, char const* []) { return 0; } |
9 | #else |
10 | |
11 | #include <boost/convert.hpp> |
12 | |
13 | static |
14 | bool |
15 | my_cypher(std::string const& value_in, boost::optional<std::string>& value_out) |
16 | { |
17 | size_t const cypher = 'A' - '1'; |
18 | |
19 | value_out = value_in; |
20 | |
21 | for (std::string::iterator it = value_out->begin(); it != value_out->end(); ++it) |
22 | (*it < 'A') ? (*it += cypher) : (*it -= cypher); |
23 | |
24 | return true; |
25 | } |
26 | |
27 | int |
28 | main(int, char const* []) |
29 | { |
30 | //////////////////////////////////////////////////////////////////////////// |
31 | // Testing custom converter. |
32 | //////////////////////////////////////////////////////////////////////////// |
33 | |
34 | std::string encrypted = boost::convert<std::string>("ABC" , my_cypher).value(); |
35 | std::string decrypted = boost::convert<std::string>(encrypted, my_cypher).value(); |
36 | |
37 | BOOST_TEST(encrypted == "123" ); |
38 | BOOST_TEST(decrypted == "ABC" ); |
39 | |
40 | return boost::report_errors(); |
41 | } |
42 | |
43 | #endif |
44 | |