3#include <boost/algorithm/string.hpp>
19 std::string
const& name,
20 std::vector<std::pair<std::string, std::string>>
const& replacers = {},
24 constexpr std::size_t bufferSize = 8 * 1024ull * 1024ull;
26 std::string demangled(bufferSize,
'\0');
27 std::size_t mutableLength = bufferSize;
31 abi::__cxa_demangle(name.c_str(), demangled.data(), &mutableLength, &status);
35 demangled.resize(mutableLength);
37 const auto pos = demangled.find(
'\0');
38 if (pos != std::string::npos)
39 demangled.resize(pos);
43 "std::__cxx11::basic_string<char, std::char_traits<char>, "
44 "std::allocator<char> >",
47 for (
auto const& [needle, replacement] : replacers)
49 boost::replace_all(demangled, needle, replacement);
55 std::string formatted;
56 auto addLineBreak = [&formatted, &indent](
int indentChange) {
57 formatted.push_back(
'\n');
58 indent += indentChange;
59 for (
int i = 0; i < indent; ++i)
65 for (
auto character : demangled)
69 formatted.push_back(character);
72 else if (character ==
'>')
75 formatted.push_back(character);
77 else if (character ==
' ')
79 else if (character ==
',')
81 formatted.push_back(character);
85 formatted.push_back(character);
87 demangled = formatted;
Definition authorization.hpp:10
std::string demangleCppSymbol(std::string const &name, std::vector< std::pair< std::string, std::string > > const &replacers={}, bool format=false)
Demangles a C++ symbol. Useful for tests or debugging purposes.
Definition demangle.hpp:18