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

Function replaceStr

lib/errorlogger.cpp:926–948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

924
925
926std::string replaceStr(std::string s, const std::string &from, const std::string &to)
927{
928 std::string::size_type pos1 = 0;
929 while (pos1 < s.size()) {
930 pos1 = s.find(from, pos1);
931 if (pos1 == std::string::npos)
932 return s;
933 if (pos1 > 0 && (s[pos1-1] == '_' || std::isalnum(s[pos1-1]))) {
934 pos1++;
935 continue;
936 }
937 const std::string::size_type pos2 = pos1 + from.size();
938 if (pos2 >= s.size())
939 return s.substr(0,pos1) + to;
940 if (s[pos2] == '_' || std::isalnum(s[pos2])) {
941 pos1++;
942 continue;
943 }
944 s.replace(pos1, from.size(), to);
945 pos1 += to.size();
946 }
947 return s;
948}
949
950void substituteTemplateFormatStatic(std::string& templateFormat, bool eraseColors)
951{

Callers 3

ErrorMessageMethod · 0.85
setmsgMethod · 0.85
getErrorPathMethod · 0.85

Calls 4

isalnumFunction · 0.85
sizeMethod · 0.45
findMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected