1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : common code used by any agent serving as OF_XML printer
13 // ***************************************************************************
15 #ifndef BOOST_TEST_UTILS_XML_PRINTER_HPP
16 #define BOOST_TEST_UTILS_XML_PRINTER_HPP
19 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
20 #include <boost/test/utils/custom_manip.hpp>
21 #include <boost/test/utils/foreach.hpp>
22 #include <boost/test/utils/basic_cstring/io.hpp>
25 #include <boost/config.hpp>
30 #include <boost/test/detail/suppress_warnings.hpp>
32 //____________________________________________________________________________//
38 // ************************************************************************** //
39 // ************** xml print helpers ************** //
40 // ************************************************************************** //
43 print_escaped( std::ostream& where_to, const_string value )
45 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
46 static std::map<char,char const*> const char_type{{
54 static std::map<char,char const*> char_type;
56 if( char_type.empty() ) {
57 char_type['<'] = "lt";
58 char_type['>'] = "gt";
59 char_type['&'] = "amp";
60 char_type['\'']= "apos";
61 char_type['"'] = "quot";
65 BOOST_TEST_FOREACH( char, c, value ) {
66 std::map<char,char const*>::const_iterator found_ref = char_type.find( c );
68 if( found_ref != char_type.end() )
69 where_to << '&' << found_ref->second << ';';
75 //____________________________________________________________________________//
78 print_escaped( std::ostream& where_to, std::string const& value )
80 print_escaped( where_to, const_string( value ) );
83 //____________________________________________________________________________//
87 print_escaped( std::ostream& where_to, T const& value )
92 //____________________________________________________________________________//
95 print_escaped_cdata( std::ostream& where_to, const_string value )
97 static const_string cdata_end( "]]>" );
99 const_string::size_type pos = value.find( cdata_end );
100 if( pos == const_string::npos )
103 where_to << value.substr( 0, pos+2 ) << cdata_end
104 << BOOST_TEST_L( "<![CDATA[" ) << value.substr( pos+2 );
108 //____________________________________________________________________________//
110 typedef custom_manip<struct attr_value_t> attr_value;
114 operator<<( custom_printer<attr_value> const& p, T const& value )
117 print_escaped( *p, value );
123 //____________________________________________________________________________//
125 typedef custom_manip<struct cdata_t> cdata;
128 operator<<( custom_printer<cdata> const& p, const_string value )
130 *p << BOOST_TEST_L( "<![CDATA[" );
131 print_escaped_cdata( *p, value );
132 return *p << BOOST_TEST_L( "]]>" );
135 //____________________________________________________________________________//
138 } // namespace unit_test
141 #include <boost/test/detail/enable_warnings.hpp>
143 #endif // BOOST_TEST_UTILS_XML_PRINTER_HPP