// Copyright Johannes Kapfhammer 2019-2022. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // pretty pretty_printing with c++ // #ifndef SOI_PRETTY #define SOI_PRETTY #include "prettyprint.hpp" namespace soi { namespace prettyprint { template std::basic_ostream & pretty_print(std::basic_ostream &stream, const bool &x) { return stream << (x ? "true" : "false"); } namespace detail { template void escape_char(std::basic_ostream &stream, char c) { switch (c) { case '\a': stream << "\\a"; break; case '\b': stream << "\\b"; break; case '\t': stream << "\\t"; break; case '\n': stream << "\\n"; break; case '\v': stream << "\\v"; break; case '\f': stream << "\\f"; break; case '\r': stream << "\\r"; break; case '\e': stream << "\\e"; break; case '\"': stream << "\\\""; break; case '\'': stream << "\\'"; break; case '\?': stream << "\\?"; break; case '\\': stream << "\\\\"; break; default: stream << c; } } } // namespace detail template std::basic_ostream & pretty_print(std::basic_ostream &stream, const std::string &x) { stream << "\""; for (char c : x) detail::escape_char(stream, c); return stream << "\""; } template std::basic_ostream & pretty_print(std::basic_ostream &stream, char c) { stream << "'"; detail::escape_char(stream, c); return stream << "'"; } template inline typename std::enable_if::value, std::basic_ostream &>::type pretty_print(std::basic_ostream &stream, const T &x) { return stream << x; } template std::basic_ostream & print(std::basic_ostream &stream, const T &x) { return ::soi::prettyprint::pretty_print(stream, x); } } // namespace prettyprint } // namespace soi #endif // SOI_PRETTY