| 562 | } |
| 563 | |
| 564 | static void replaceSpecialChars(std::string& source) |
| 565 | { |
| 566 | // Support a few special characters to allow to specific formatting, see http://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=4&t=494&sid=21715d362c0dbafd3791da4d9522f814 |
| 567 | // Substitution should be done first so messages from cppcheck never get translated. |
| 568 | static const std::unordered_map<char, std::string> substitutionMap = { |
| 569 | {'b', "\b"}, |
| 570 | {'n', "\n"}, |
| 571 | {'r', "\r"}, |
| 572 | {'t', "\t"} |
| 573 | }; |
| 574 | |
| 575 | std::string::size_type index = 0; |
| 576 | while ((index = source.find('\\', index)) != std::string::npos) { |
| 577 | const char searchFor = source[index+1]; |
| 578 | const auto it = substitutionMap.find(searchFor); |
| 579 | if (it == substitutionMap.end()) { |
| 580 | index += 1; |
| 581 | continue; |
| 582 | } |
| 583 | const std::string& replaceWith = it->second; |
| 584 | source.replace(index, 2, replaceWith); |
| 585 | index += replaceWith.length(); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | static void replace(std::string& source, const std::unordered_map<std::string, std::string> &substitutionMap) |
| 590 | { |
no test coverage detected