The Gaudi Framework  master (69a68366)
Loading...
Searching...
No Matches
System::Detail Namespace Reference

Functions

std::string normalizeTypeName (const char *mangled_name, bool normalize_commas=false)
 Normalize a demangled C++ type name for cross-platform consistency.
 

Function Documentation

◆ normalizeTypeName()

std::string System::Detail::normalizeTypeName ( const char * mangled_name,
bool normalize_commas = false )
inline

Normalize a demangled C++ type name for cross-platform consistency.

Handles differences between libstdc++ and libc++:

  • Removes std::__cxx11:: and std::__1:: inline namespace prefixes
  • Converts basic_string<char,...> to std::string
  • Normalizes ">>" to "> >" (C++03 style spacing)
    Parameters
    normalize_commasIf true, also converts ", " to "," (legacy behavior)

Definition at line 29 of file TypeNormalization.h.

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 // Normalize libstdc++ (Linux) std::string representation
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 // Normalize libc++ inline namespace - remove std::__1:: prefix
43 static const std::regex libc_ns{ "std::__1::" };
44 result = std::regex_replace( result, libc_ns, "std::" );
45
46 // Normalize std::basic_string (after removing __1::)
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 // Normalize closing angle brackets: >> to > > (C++03 style)
52 static const std::regex angle_brackets{ ">>" };
53 result = std::regex_replace( result, angle_brackets, "> >" );
54 result = std::regex_replace( result, angle_brackets, "> >" ); // twice for >>>
55
56 // Optionally normalize commas: ", " to "," (legacy behavior)
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 }