11#include "prettyprint.hpp"
20namespace pretty_print {
22struct is_container<std::optional<T>> : std::false_type {};
28template <
typename A,
typename E>
41 [[nodiscard]] std::string name(
const std::string& name)
const;
42 [[nodiscard]] std::string name_to_sentence(
const std::string& name)
const;
43 static std::string split_words(
const std::string& sym);
44 static std::string underscore(
const std::string& camel_cased_word);
45 static std::string last(
const std::string& s,
char delim);
46 static std::string improve_hash_formatting(
const std::string& inspect_string);
48 template <Util::is_streamable T>
49 static std::string
to_word(
const T& item);
52 static std::string
to_word(
const T& item);
55 static std::string to_word_type(
const T& item);
57 template <
typename A,
typename E>
64 static std::string
to_sentence(
const std::vector<T>& words);
67 static std::string inspect_object(
const T&
object);
80 std::vector<std::string> words;
81 for (
const auto&
object : objects) {
82 words.push_back(
to_word(
object));
86 switch (words.size()) {
90 ss <<
" " << words[0];
93 ss <<
" " << words[0] <<
" and " << words[1];
97 for (
size_t i = 0; i < words.size() - 1; ++i) {
103 ss <<
", and " << words.back();
133template <Util::is_streamable T>
135 std::ostringstream oss;
142 return item ?
"true" :
"false";
146inline std::string Pretty::to_word<std::true_type>(
const std::true_type& ) {
164 std::stringstream ss;
166 ss <<
"#<" << Util::demangle(
typeid(item).name()) <<
":" << &item <<
">";
181template <
typename A,
typename E>
184 if (description.empty()) {
185 return "[No description]";
191inline std::string Pretty::to_word_type(
const T& item) {
192 std::string word =
to_word(item);
199inline std::string Pretty::name_to_sentence(
const std::string& n)
const {
200 return split_words(name(n));
203inline std::string Pretty::name(
const std::string& name)
const {
205 return last(name,
':');
210inline std::string Pretty::split_words(
const std::string& sym) {
211 return std::regex_replace(sym, std::regex(
"_"),
" ");
214inline std::string Pretty::underscore(
const std::string& word) {
215 std::string str = std::regex_replace(word, std::regex(
"([A-Z]+)([A-Z][a-z])"),
"$1_$2");
216 str = std::regex_replace(str, std::regex(
"([a-z\\d])([A-Z])"),
"$1_$2");
217 str = std::regex_replace(str, std::regex(
"-"),
"_");
218 std::ranges::transform(str, str.begin(), ::tolower);
222inline std::string Pretty::last(
const std::string& s,
const char delim) {
223 std::vector<std::string> elems;
224 std::stringstream ss(s);
226 while (getline(ss, item, delim)) {
228 elems.push_back(item);
234inline std::string Pretty::improve_hash_formatting(
const std::string& inspect_string) {
235 return std::regex_replace(inspect_string, std::regex(
"(\\S)=>(\\S)"),
"$1 => $2");
246inline std::string Pretty::inspect_object(
const O& o) {
258inline std::string Pretty::inspect_object<const char*>(
const char*
const& o) {
259 return std::format(
"(const char *) => \"{}\"", o);
270inline std::string Pretty::inspect_object<std::string>(
const std::string& o) {
271 return std::format(
"(std::string) => \"{}\"", o);
275inline std::string Pretty::inspect_object<std::string_view>(
const std::string_view& o) {
276 return std::format(
"(std::string_view) => \"{}\"", o);
the base class for all Matcher classes and objects
Definition matcher_base.hpp:37
virtual std::string description()
Get the description of the Matcher.
Definition matcher_base.hpp:138
Checks whether T can be streamed.
Definition util.hpp:81
A helper base class that assists in pretty-printing various objects.
Definition pretty_matchers.hpp:39
static std::string to_word(const T &item)
Formats an object as a string when operator<< is available.
Definition pretty_matchers.hpp:134
static std::string to_sentence(const T &item)
Take a single object and format it as a sentance.
Definition pretty_matchers.hpp:118
Utility functions and classes.
std::string demangle(const char *name)
Definition util.hpp:38