LCOV - code coverage report
Current view: top level - opt/homebrew/include/boost/test/utils - xml_printer.hpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 32 0.0 %
Date: 2026-06-25 07:23:43 Functions: 0 22 0.0 %

          Line data    Source code
       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)
       5             : 
       6             : //  See http://www.boost.org/libs/test for the library home page.
       7             : //
       8             : //  File        : $RCSfile$
       9             : //
      10             : //  Version     : $Revision$
      11             : //
      12             : //  Description : common code used by any agent serving as OF_XML printer
      13             : // ***************************************************************************
      14             : 
      15             : #ifndef BOOST_TEST_UTILS_XML_PRINTER_HPP
      16             : #define BOOST_TEST_UTILS_XML_PRINTER_HPP
      17             : 
      18             : // Boost.Test
      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>
      24             : 
      25             : // Boost
      26             : #include <boost/config.hpp>
      27             : 
      28             : // STL
      29             : #include <iostream>
      30             : #include <map>
      31             : 
      32             : #include <boost/test/detail/suppress_warnings.hpp>
      33             : 
      34             : //____________________________________________________________________________//
      35             : 
      36             : namespace boost {
      37             : namespace unit_test {
      38             : namespace utils {
      39             : 
      40             : // ************************************************************************** //
      41             : // **************               xml print helpers              ************** //
      42             : // ************************************************************************** //
      43             : 
      44             : inline void
      45           0 : print_escaped( std::ostream& where_to, const_string value )
      46             : {
      47             : #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
      48           0 :     static std::map<char,char const*> const char_type{{
      49             :         {'<' , "lt"},
      50             :         {'>' , "gt"},
      51             :         {'&' , "amp"},
      52             :         {'\'', "apos"},
      53             :         {'"' , "quot"}
      54             :     }};
      55             : #else
      56             :     static std::map<char,char const*> char_type;
      57             : 
      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";
      64             :     }
      65             : #endif
      66             : 
      67           0 :     BOOST_TEST_FOREACH( char, c, value ) {
      68           0 :         std::map<char,char const*>::const_iterator found_ref = char_type.find( c );
      69             : 
      70           0 :         if( found_ref != char_type.end() )
      71           0 :             where_to << '&' << found_ref->second << ';';
      72             :         else
      73           0 :             where_to << c;
      74           0 :     }
      75           0 : }
      76             : 
      77             : //____________________________________________________________________________//
      78             : 
      79             : inline void
      80           0 : print_escaped( std::ostream& where_to, std::string const& value )
      81             : {
      82           0 :     print_escaped( where_to, const_string( value ) );
      83           0 : }
      84             : 
      85             : //____________________________________________________________________________//
      86             : 
      87             : template<typename T>
      88             : inline void
      89           0 : print_escaped( std::ostream& where_to, T const& value )
      90             : {
      91           0 :     where_to << value;
      92           0 : }
      93             : 
      94             : //____________________________________________________________________________//
      95             : 
      96             : inline void
      97           0 : print_escaped_cdata( std::ostream& where_to, const_string value )
      98             : {
      99           0 :     static const_string cdata_end( "]]>" );
     100             : 
     101           0 :     const_string::size_type pos = value.find( cdata_end );
     102           0 :     if( pos == const_string::npos )
     103           0 :         where_to << value;
     104             :     else {
     105           0 :         where_to << value.substr( 0, pos+2 ) << cdata_end
     106           0 :                  << BOOST_TEST_L( "<![CDATA[" ) << value.substr( pos+2 );
     107             :     }
     108           0 : }
     109             : 
     110             : //____________________________________________________________________________//
     111             : 
     112             : typedef custom_manip<struct attr_value_t> attr_value;
     113             : 
     114             : template<typename T>
     115             : inline std::ostream&
     116           0 : operator<<( custom_printer<attr_value> const& p, T const& value )
     117             : {
     118           0 :     *p << "=\"";
     119           0 :     print_escaped( *p, value );
     120           0 :     *p << '"';
     121             : 
     122           0 :     return *p;
     123             : }
     124             : 
     125             : //____________________________________________________________________________//
     126             : 
     127             : typedef custom_manip<struct cdata_t> cdata;
     128             : 
     129             : inline std::ostream&
     130           0 : operator<<( custom_printer<cdata> const& p, const_string value )
     131             : {
     132           0 :     *p << BOOST_TEST_L( "<![CDATA[" );
     133           0 :     print_escaped_cdata( *p, value );
     134           0 :     return  *p << BOOST_TEST_L( "]]>" );
     135             : }
     136             : 
     137             : //____________________________________________________________________________//
     138             : 
     139             : } // namespace utils
     140             : } // namespace unit_test
     141             : } // namespace boost
     142             : 
     143             : #include <boost/test/detail/enable_warnings.hpp>
     144             : 
     145             : #endif // BOOST_TEST_UTILS_XML_PRINTER_HPP

Generated by: LCOV version 1.16