| 587 | } |
| 588 | |
| 589 | static void replace(std::string& source, const std::unordered_map<std::string, std::string> &substitutionMap) |
| 590 | { |
| 591 | std::string::size_type index = 0; |
| 592 | while ((index = source.find('{', index)) != std::string::npos) { |
| 593 | const std::string::size_type end = source.find('}', index); |
| 594 | if (end == std::string::npos) |
| 595 | break; |
| 596 | const std::string searchFor = source.substr(index, end-index+1); |
| 597 | const auto it = substitutionMap.find(searchFor); |
| 598 | if (it == substitutionMap.end()) { |
| 599 | index += 1; |
| 600 | continue; |
| 601 | } |
| 602 | const std::string& replaceWith = it->second; |
| 603 | source.replace(index, searchFor.length(), replaceWith); |
| 604 | index += replaceWith.length(); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static void replaceColors(std::string& source, bool erase) { |
| 609 | // TODO: colors are not applied when either stdout or stderr is not a TTY because we resolve them before the stream usage |
no test coverage detected