|
4 | 4 | #include <string> |
5 | 5 | #include <vector> |
6 | 6 |
|
| 7 | +// Remove any `::` between brackets at the end to not mess with the URI |
| 8 | +// parsing |
| 9 | +// FIXME: Remove this bandaid when we migrate to structured benchmark metadata |
| 10 | +std::string sanitize_bench_args(std::string &text) { |
| 11 | + std::string search = "::"; |
| 12 | + std::string replace = "\\:\\:"; |
| 13 | + |
| 14 | + if (text.back() == ']') { |
| 15 | + size_t pos_open = text.rfind('['); |
| 16 | + if (pos_open != std::string::npos) { |
| 17 | + // Extract the substring between '[' and ']' |
| 18 | + size_t pos_close = text.size() - 1; |
| 19 | + std::string substring = |
| 20 | + text.substr(pos_open + 1, pos_close - pos_open - 1); |
| 21 | + |
| 22 | + // Perform the search and replace within the substring |
| 23 | + size_t pos = substring.find(search); |
| 24 | + while (pos != std::string::npos) { |
| 25 | + substring.replace(pos, search.length(), replace); |
| 26 | + pos = substring.find(search, pos + replace.length()); |
| 27 | + } |
| 28 | + |
| 29 | + // Replace the original substring with the modified one |
| 30 | + text.replace(pos_open + 1, pos_close - pos_open - 1, substring); |
| 31 | + } |
| 32 | + } |
| 33 | + return text; |
| 34 | +} |
| 35 | + |
7 | 36 | std::string join(const std::vector<std::string> &elements, |
8 | 37 | const std::string &delimiter) { |
9 | 38 | std::string result; |
@@ -40,6 +69,8 @@ void CodSpeed::pop_group() { |
40 | 69 | void CodSpeed::start_benchmark(const std::string &name) { |
41 | 70 | std::string uri = name; |
42 | 71 |
|
| 72 | + uri = sanitize_bench_args(uri); |
| 73 | + |
43 | 74 | // Sanity check URI and add a placeholder if format is wrong |
44 | 75 | if (name.find("::") == std::string::npos) { |
45 | 76 | std::string uri = "unknown_file::" + name; |
|
0 commit comments