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