MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / replaceSpecialChars

Function replaceSpecialChars

lib/errorlogger.cpp:564–587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

562}
563
564static 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
589static void replace(std::string& source, const std::unordered_map<std::string, std::string> &substitutionMap)
590{

Calls 3

findMethod · 0.45
endMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected