MCPcopy Create free account
hub / github.com/dirkvdb/ffmpegthumbnailer / encodeTo

Method encodeTo

test/testframework/catch.hpp:8863–8897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8861 {}
8862
8863 void encodeTo( std::ostream& os ) const {
8864
8865 // Apostrophe escaping not necessary if we always use " to write attributes
8866 // (see: http://www.w3.org/TR/xml/#syntax)
8867
8868 for( std::size_t i = 0; i < m_str.size(); ++ i ) {
8869 char c = m_str[i];
8870 switch( c ) {
8871 case '<': os << "&lt;"; break;
8872 case '&': os << "&amp;"; break;
8873
8874 case '>':
8875 // See: http://www.w3.org/TR/xml/#syntax
8876 if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
8877 os << "&gt;";
8878 else
8879 os << c;
8880 break;
8881
8882 case '\"':
8883 if( m_forWhat == ForAttributes )
8884 os << "&quot;";
8885 else
8886 os << c;
8887 break;
8888
8889 default:
8890 // Escape control chars - based on contribution by @espenalb in PR #465
8891 if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
8892 os << "&#x" << std::uppercase << std::hex << static_cast<int>( c );
8893 else
8894 os << c;
8895 }
8896 }
8897 }
8898
8899 friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
8900 xmlEncode.encodeTo( os );

Callers 1

XmlEncodeClass · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected