Botcraft 1.21.4
Loading...
Searching...
No Matches
DemanglingUtilities.cpp
Go to the documentation of this file.
2
3#if __has_include(<cxxabi.h>)
4#include <cxxabi.h>
5#include <memory>
6#define DEMANGLE_AVAILABLE
7#endif
8
10{
11 std::string Demangle(const std::string& name, const bool simplify_output)
12 {
13#ifdef DEMANGLE_AVAILABLE
14 int status = 0;
15 std::unique_ptr<char, void(*)(void*)> result{
16 abi::__cxa_demangle(name.c_str(), NULL, NULL, &status),
17 std::free
18 };
19
20 const std::string demangled = status == 0 ? std::string(result.get()) : name;
21#else
22 const std::string& demangled = name;
23#endif
24 if (!simplify_output)
25 {
26 return demangled;
27 }
28
29 std::string output = demangled.substr(0, demangled.find('<'));
30 size_t match_pos = output.find("::");
31 if (match_pos != std::string::npos)
32 {
33 output = output.substr(match_pos + 2);
34 }
35 match_pos = output.find("class ");
36 if (match_pos != std::string::npos)
37 {
38 output = output.substr(match_pos + 6);
39 }
40
41 return output;
42 }
43}
std::string Demangle(const std::string &name, const bool simplify_output)
Demangle a class name.