3 #include "tbb/concurrent_unordered_map.h" 18 std::regex
const reAllSpaces{
" +"};
19 std::regex
const reAssns{
"art::Assns"};
20 std::regex
const reBeginSpace{
"^ +"};
21 std::regex
const reComma{
","};
22 std::regex
const reEndSpace{
" +$"};
23 std::regex
const reParens{
"(\\(|\\))"};
24 std::regex
const reFirstTwoArgs{
"^([^,]+),([^,]+)"};
25 std::regex
const reLong{
"long "};
26 std::regex
const reLongLong{
"Long64_t"};
27 std::regex
const reMapVector{
"cet::map_vector"};
28 std::regex
const reMapVectorKey{
"cet::map_vector_key"};
29 std::regex
const reString{
"(?:std::basic_string<char>|std::string)"};
30 std::regex
const reTemplateArgs{
"([^<]*)<(.*)>$"};
31 std::regex
const reTemplateClass{
"([^<>,]+<[^<>]*>)"};
32 std::regex
const reULongLong{
"ULong64_t"};
33 std::regex
const reUnsigned{
"unsigned "};
34 std::regex
const reVector{
"std::vector"};
35 std::regex
const reWrapper{
"art::Wrapper<(.*)>"};
37 std::string
const emptyString{};
40 removeExtraSpaces(std::string
const&
in)
42 return std::regex_replace(std::regex_replace(in, reBeginSpace, emptyString),
48 removeAllSpaces(std::string
const& in)
50 return std::regex_replace(in, reAllSpaces, emptyString);
54 escapeParens(std::string
const& in)
56 return std::regex_replace(in, reParens,
"\\$1");
60 standardRenames(std::string
const& in)
62 std::string name{std::regex_replace(in, reWrapper,
"$1")};
63 name = std::regex_replace(name, reString,
"String");
64 name = std::regex_replace(name, reUnsigned,
"u");
65 name = std::regex_replace(name, reLong,
"l");
66 name = std::regex_replace(name, reULongLong,
"ull");
67 name = std::regex_replace(name, reLongLong,
"ll");
68 name = std::regex_replace(name, reVector,
"s");
69 name = std::regex_replace(name, reMapVectorKey,
"mvk");
70 name = std::regex_replace(name, reMapVector,
"mv");
76 std::string handleTemplateArguments(std::string
const&, std::string
const&);
78 subFriendlyName(std::string
const& iFullName)
80 std::string result{removeExtraSpaces(iFullName)};
83 if (std::regex_match(result, theMatch, reTemplateArgs)) {
84 std::string
const cMatch{theMatch.str(1)};
85 std::string
const aMatch{theMatch.str(2)};
86 std::string
const theSub{handleTemplateArguments(cMatch, aMatch)};
91 std::regex
const eMatch{std::string{
"^"} + escapeParens(cMatch) +
'<' +
92 escapeParens(aMatch) +
'>'};
93 result = std::regex_replace(result, eMatch, theSub + cMatch);
99 maybeSwapFirstTwoArgs(std::string& result)
101 std::smatch theMatch;
102 if (std::regex_search(result, theMatch, reFirstTwoArgs) &&
103 (theMatch.str(1) > theMatch.str(2))) {
104 result = std::regex_replace(result, reFirstTwoArgs,
"$2,$1");
109 handleTemplateArguments(std::string
const& cName, std::string
const& tArgs)
111 std::string result{removeExtraSpaces(tArgs)};
112 bool shouldStop{
false};
113 while (!shouldStop) {
114 if (std::string::npos != result.find_first_of(
"<")) {
115 std::smatch theMatch;
116 if (std::regex_search(result, theMatch, reTemplateClass)) {
117 std::string
const templateClass{theMatch.str(1)};
118 std::string
const friendlierName{
119 removeAllSpaces(subFriendlyName(templateClass))};
120 result = std::regex_replace(
121 result, std::regex(templateClass), friendlierName);
124 <<
"No template match for \"" << result <<
'"';
130 if (std::regex_match(cName, reAssns)) {
131 maybeSwapFirstTwoArgs(result);
133 result = std::regex_replace(result, reComma, emptyString);
141 static tbb::concurrent_unordered_map<std::string, std::string> s_nameMap;
142 auto entry = s_nameMap.find(iFullName);
143 if (s_nameMap.end() == entry) {
145 s_nameMap.emplace(iFullName, subFriendlyName(standardRenames(iFullName)))
148 return entry->second;
std::string friendlyName(std::string const &iFullName)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception