-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuri.cpp
More file actions
48 lines (41 loc) · 1.5 KB
/
uri.cpp
File metadata and controls
48 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "codspeed.h"
#include <string>
#include <iostream>
// Example: auto outer::test12::(anonymous class)::operator()() const
// Returns: outer::test12::
std::string extract_namespace_clang(const std::string& pretty_func) {
std::size_t anon_class_pos = pretty_func.find("::(anonymous class)");
std::size_t space_pos = pretty_func.find(' ');
if (space_pos == std::string::npos || anon_class_pos == std::string::npos) {
return {};
}
space_pos += 1; // Skip the space
return pretty_func.substr(space_pos, anon_class_pos - space_pos) + "::";
}
// Example: outer::test12::<lambda()>
// Returns: outer::test12::
std::string extract_namespace_gcc(const std::string& pretty_func) {
auto lambda_pos = pretty_func.find("::<lambda()>");
if (lambda_pos == std::string::npos) {
return {};
}
return pretty_func.substr(0, lambda_pos) + "::";
}
// Has to pass the pretty function from a lambda:
// (([]() { return __PRETTY_FUNCTION__; })())
//
// Returns: An empty string if the namespace could not be extracted,
// otherwise the namespace with a trailing "::"
std::string extract_lambda_namespace(const std::string& pretty_func) {
if (pretty_func.find("(anonymous namespace)") != std::string::npos) {
std::cerr << "[ERROR] Anonymous namespace not supported in " << pretty_func << std::endl;
return {};
}
#ifdef __clang__
return extract_namespace_clang(pretty_func);
#elif __GNUC__
return extract_namespace_gcc(pretty_func);
#else
#error "Unsupported compiler"
#endif
}