Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:43

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision$
0011 //
0012 //  Description : common code used by any agent serving as OF_XML printer
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_UTILS_XML_PRINTER_HPP
0016 #define BOOST_TEST_UTILS_XML_PRINTER_HPP
0017 
0018 // Boost.Test
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 // Boost
0026 #include <boost/config.hpp>
0027 
0028 // STL
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 // **************               xml print helpers              ************** //
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 } // namespace utils
0140 } // namespace unit_test
0141 } // namespace boost
0142 
0143 #include <boost/test/detail/enable_warnings.hpp>
0144 
0145 #endif // BOOST_TEST_UTILS_XML_PRINTER_HPP