The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
TypeNormalization.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11// Dear emacs, this is -*- c++ -*-
12#pragma once
13
14#include <cstdlib>
15#include <cxxabi.h>
16#include <memory>
17#include <regex>
18#include <string>
19
20namespace System {
21 namespace Detail {
22
29 inline std::string normalizeTypeName( const char* mangled_name, bool normalize_commas = false ) {
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 }
64
65 } // namespace Detail
66} // namespace System
std::string normalizeTypeName(const char *mangled_name, bool normalize_commas=false)
Normalize a demangled C++ type name for cross-platform consistency.
Note: OS specific details for environment resolution.
Definition Environment.h:25