ATLAS Offline Software
Loading...
Searching...
No Matches
normalizeFunctionName.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
13#include <cctype>
14#include <cstring>
15
16
17namespace CxxUtils {
18
19
24std::string clean_allocator (std::string f)
25{
26 std::string::size_type ipos = 0;
27 while ((ipos = f.find (", std::allocator", ipos)) != std::string::npos) {
28 const char* p = f.c_str() + ipos + 16;
29 while (isspace (*p)) ++p;
30 if (*p == '<') {
31 ++p;
32 int nest = 1;
33 while (nest > 0 && *p) {
34 if (*p == '<')
35 ++nest;
36 else if (*p == '>')
37 --nest;
38 ++p;
39 }
40 if (nest == 0) {
41 if (ipos > 0 && f[ipos-1] != '>') {
42 while (isspace (*p)) ++p;
43 }
44 f.erase (ipos, p-f.c_str()-ipos);
45 p = f.c_str() + ipos;
46 }
47 }
48 ipos = p - f.c_str();
49 }
50 return f;
51}
52
53
54std::string munge_string_name (const std::string& str_in)
55{
56 std::string s = str_in;
57
58 std::string::size_type ipos = 0;
59 while ((ipos = s.find ("std::basic_string<", ipos)) != std::string::npos) {
60 std::string::size_type beg = ipos;
61 ipos += 18;
62 int inest = 1;
63 while (inest > 0 && ipos < s.size()) {
64 if (s[ipos] == '<') ++inest;
65 else if (s[ipos] == '>') --inest;
66 ++ipos;
67 }
68 s.replace (beg, ipos-beg, "std::string");
69 ipos = beg+11;
70 }
71
72 for (size_t i = 0; i < s.size(); i++) {
73 if ((i == 0 || (s[i-1] != ':' && !isalnum(s[i-1]))) &&
74 strncmp (s.c_str()+i, "string", 6) == 0 &&
75 !isalnum(s[i+6]))
76 {
77 s.replace (i, 6, "std::string");
78 }
79 }
80 return s;
81}
82
83
84std::string munge_punct (const std::string& str_in)
85{
86 std::string s = str_in;
87 for (size_t i = 0; i < s.size()-1; i++) {
88 if (s[i] == ' ' && (s[i+1] == '*' || s[i+1] == '&'))
89 s.erase (i, 1);
90 }
91 return s;
92}
93
94
95std::string do_replace (std::string s,
96 const std::string& pat,
97 const std::string& rep)
98{
99 std::string::size_type ipos = 0;
100 while ((ipos = s.find (pat, ipos)) != std::string::npos)
101 s.replace (ipos, pat.size(), rep);
102 return s;
103}
104
105
106std::string munge_names (const std::string& str_in)
107{
108 std::string s =
109 do_replace (str_in, "SG::DataProxyStorageData::pointer", "void*");
110 s = do_replace (s, "DPSD::pointer", "void*");
111 s = do_replace (s, "SG::auxid_t", "unsigned long");
112 s = do_replace (s, "auxid_t", "unsigned long");
113 s = do_replace (s, "void* ", "void*");
114 s = do_replace (s, "CLID", "unsigned int");
115
116 if (s.compare (0, 8, "virtual ") == 0)
117 s.erase (0, 8);
118 return s;
119}
120
121
135std::string normalizeFunctionName (const std::string& fname)
136{
138}
139
140
141} // namespace CxxUtils
std::string do_replace(std::string s, const std::string &pat, const std::string &rep)
std::string normalizeFunctionName(const std::string &fname)
Normalize a pretty-printed C++ function name.
std::string munge_names(const std::string &str_in)
std::string munge_punct(const std::string &str_in)
std::string clean_allocator(std::string f)
Clean ‘allocator’ template arguments from the function f.
std::string munge_string_name(const std::string &str_in)
Normalize a pretty-printed C++ function name,.