Normalize a demangled C++ type name for cross-platform consistency.
29 {
30 int status;
31 auto realname = std::unique_ptr<char, decltype( free )*>(
32 abi::__cxa_demangle( mangled_name, nullptr, nullptr, &status ), std::free );
33 if ( !realname ) return mangled_name;
34
35 std::string result = realname.get();
36
37
38 static const std::regex cxx11_string{
39 "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >( (?=>))?" };
40 result = std::regex_replace( result, cxx11_string, "std::string" );
41
42
43 static const std::regex libc_ns{ "std::__1::" };
44 result = std::regex_replace( result, libc_ns, "std::" );
45
46
47 static const std::regex basic_string{
48 "std::basic_string<char, std::char_traits<char>, std::allocator<char>>( (?=>))?" };
49 result = std::regex_replace( result, basic_string, "std::string" );
50
51
52 static const std::regex angle_brackets{ ">>" };
53 result = std::regex_replace( result, angle_brackets, "> >" );
54 result = std::regex_replace( result, angle_brackets, "> >" );
55
56
57 if ( normalize_commas ) {
58 static const std::regex comma_space{ ", " };
59 result = std::regex_replace( result, comma_space, "," );
60 }
61
62 return result;
63 }