Output non-printable chars as \xXY

This commit is contained in:
Peter Dimov
2021-01-20 02:38:57 +02:00
parent 0ae16756eb
commit afba04cf7f

View File

@ -27,9 +27,12 @@
#include <exception>
#include <iostream>
#include <iterator>
#include <string>
#include <cstdlib>
#include <cstring>
#include <cstddef>
#include <cctype>
#include <cstdio>
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
# include <crtdbg.h>
@ -188,6 +191,30 @@ inline unsigned long test_output_impl( char16_t const& v ) { return v; }
inline unsigned long test_output_impl( char32_t const& v ) { return v; }
#endif
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4996)
#endif
inline std::string test_output_impl( char const& v )
{
if( std::isprint( static_cast<unsigned char>( v ) ) )
{
return std::string( 1, v );
}
else
{
char buffer[ 8 ];
std::sprintf( buffer, "\\x%02X", static_cast<unsigned char>( v ) );
return buffer;
}
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
// predicates
struct lw_test_eq