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/detail/global_typedef.hpp>
20 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
21 #include <boost/test/utils/custom_manip.hpp>
22 #include <boost/test/utils/foreach.hpp>
23 #include <boost/test/utils/basic_cstring/io.hpp>
26 #include <boost/config.hpp>
32 #include <boost/test/detail/suppress_warnings.hpp>
34 //____________________________________________________________________________//
40 // ************************************************************************** //
41 // ************** xml print helpers ************** //
42 // ************************************************************************** //
45 print_escaped( std::ostream& where_to, const_string value )
47 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
48 static std::map<char,char const*> const char_type{{
56 static std::map<char,char const*> char_type;
58 if( char_type.empty() ) {
59 char_type['<'] = "lt";
60 char_type['>'] = "gt";
61 char_type['&'] = "amp";
62 char_type['\'']= "apos";
63 char_type['"'] = "quot";
67 BOOST_TEST_FOREACH( char, c, value ) {
68 std::map<char,char const*>::const_iterator found_ref = char_type.find( c );
70 if( found_ref != char_type.end() )
71 where_to << '&' << found_ref->second << ';';
77 //____________________________________________________________________________//
80 print_escaped( std::ostream& where_to, std::string const& value )
82 print_escaped( where_to, const_string( value ) );
85 //____________________________________________________________________________//
89 print_escaped( std::ostream& where_to, T const& value )
94 //____________________________________________________________________________//
97 print_escaped_cdata( std::ostream& where_to, const_string value )
99 static const_string cdata_end( "]]>" );
101 const_string::size_type pos = value.find( cdata_end );
102 if( pos == const_string::npos )
105 where_to << value.substr( 0, pos+2 ) << cdata_end
106 << BOOST_TEST_L( "<![CDATA[" ) << value.substr( pos+2 );
110 //____________________________________________________________________________//
112 typedef custom_manip<struct attr_value_t> attr_value;
116 operator<<( custom_printer<attr_value> const& p, T const& value )
119 print_escaped( *p, value );
125 //____________________________________________________________________________//
127 typedef custom_manip<struct cdata_t> cdata;
130 operator<<( custom_printer<cdata> const& p, const_string value )
132 *p << BOOST_TEST_L( "<![CDATA[" );
133 print_escaped_cdata( *p, value );
134 return *p << BOOST_TEST_L( "]]>" );
137 //____________________________________________________________________________//
140 } // namespace unit_test
143 #include <boost/test/detail/enable_warnings.hpp>
145 #endif // BOOST_TEST_UTILS_XML_PRINTER_HPP