File indexing completed on 2025-01-18 09:52:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_UTILS_XML_PRINTER_HPP
0016 #define BOOST_TEST_UTILS_XML_PRINTER_HPP
0017
0018
0019 #include <boost/test/detail/global_typedef.hpp>
0020 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
0021 #include <boost/test/utils/custom_manip.hpp>
0022 #include <boost/test/utils/foreach.hpp>
0023 #include <boost/test/utils/basic_cstring/io.hpp>
0024
0025
0026 #include <boost/config.hpp>
0027
0028
0029 #include <iostream>
0030 #include <map>
0031
0032 #include <boost/test/detail/suppress_warnings.hpp>
0033
0034
0035
0036 namespace boost {
0037 namespace unit_test {
0038 namespace utils {
0039
0040
0041
0042
0043
0044 inline void
0045 print_escaped( std::ostream& where_to, const_string value )
0046 {
0047 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
0048 static std::map<char,char const*> const char_type{{
0049 {'<' , "lt"},
0050 {'>' , "gt"},
0051 {'&' , "amp"},
0052 {'\'', "apos"},
0053 {'"' , "quot"}
0054 }};
0055 #else
0056 static std::map<char,char const*> char_type;
0057
0058 if( char_type.empty() ) {
0059 char_type['<'] = "lt";
0060 char_type['>'] = "gt";
0061 char_type['&'] = "amp";
0062 char_type['\'']= "apos";
0063 char_type['"'] = "quot";
0064 }
0065 #endif
0066
0067 BOOST_TEST_FOREACH( char, c, value ) {
0068 std::map<char,char const*>::const_iterator found_ref = char_type.find( c );
0069
0070 if( found_ref != char_type.end() )
0071 where_to << '&' << found_ref->second << ';';
0072 else
0073 where_to << c;
0074 }
0075 }
0076
0077
0078
0079 inline void
0080 print_escaped( std::ostream& where_to, std::string const& value )
0081 {
0082 print_escaped( where_to, const_string( value ) );
0083 }
0084
0085
0086
0087 template<typename T>
0088 inline void
0089 print_escaped( std::ostream& where_to, T const& value )
0090 {
0091 where_to << value;
0092 }
0093
0094
0095
0096 inline void
0097 print_escaped_cdata( std::ostream& where_to, const_string value )
0098 {
0099 static const_string cdata_end( "]]>" );
0100
0101 const_string::size_type pos = value.find( cdata_end );
0102 if( pos == const_string::npos )
0103 where_to << value;
0104 else {
0105 where_to << value.substr( 0, pos+2 ) << cdata_end
0106 << BOOST_TEST_L( "<![CDATA[" ) << value.substr( pos+2 );
0107 }
0108 }
0109
0110
0111
0112 typedef custom_manip<struct attr_value_t> attr_value;
0113
0114 template<typename T>
0115 inline std::ostream&
0116 operator<<( custom_printer<attr_value> const& p, T const& value )
0117 {
0118 *p << "=\"";
0119 print_escaped( *p, value );
0120 *p << '"';
0121
0122 return *p;
0123 }
0124
0125
0126
0127 typedef custom_manip<struct cdata_t> cdata;
0128
0129 inline std::ostream&
0130 operator<<( custom_printer<cdata> const& p, const_string value )
0131 {
0132 *p << BOOST_TEST_L( "<![CDATA[" );
0133 print_escaped_cdata( *p, value );
0134 return *p << BOOST_TEST_L( "]]>" );
0135 }
0136
0137
0138
0139 }
0140 }
0141 }
0142
0143 #include <boost/test/detail/enable_warnings.hpp>
0144
0145 #endif