diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 74488b507..73840cb7f 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -360,30 +360,6 @@ static bool findPath(const CTU::FileInfo::FunctionCall &from, return false; } -static std::string replacestr(std::string s, const std::string &from, const std::string &to) -{ - std::string::size_type pos1 = 0; - while (pos1 < s.size()) { - pos1 = s.find(from, pos1); - if (pos1 == std::string::npos) - return s; - if (pos1 > 0 && (s[pos1-1] == '_' || std::isalnum(s[pos1-1]))) { - pos1++; - continue; - } - const std::string::size_type pos2 = pos1 + from.size(); - if (pos2 >= s.size()) - return s.substr(0,pos1) + to; - if (s[pos2] == '_' || std::isalnum(s[pos2])) { - pos1++; - continue; - } - s = s.substr(0,pos1) + to + s.substr(pos2); - pos1 += to.size(); - } - return s; -} - std::list CTU::FileInfo::getErrorPath(InvalidValueType invalidValue, const CTU::FileInfo::UnsafeUsage &unsafeUsage, const std::map> &nestedCallsMap, @@ -423,7 +399,7 @@ std::list CTU::FileInfo::getErrorPath(I ErrorLogger::ErrorMessage::FileLocation fileLoc2; fileLoc2.setfile(unsafeUsage.location.fileName); fileLoc2.line = unsafeUsage.location.linenr; - fileLoc2.setinfo(replacestr(info, "ARG", unsafeUsage.argumentName)); + fileLoc2.setinfo(replaceStr(info, "ARG", unsafeUsage.argumentName)); locationList.push_back(fileLoc1); locationList.push_back(fileLoc2); diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 424341750..5058c56c2 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -178,16 +178,6 @@ ErrorLogger::ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errms } } -static std::string replaceStr(std::string s, const std::string &from, const std::string &to) -{ - std::string::size_type pos = 0; - while (std::string::npos != (pos = s.find(from,pos))) { - s = s.substr(0, pos) + to + s.substr(pos + from.size()); - pos += to.size(); - } - return s; -} - void ErrorLogger::ErrorMessage::setmsg(const std::string &msg) { // If a message ends to a '\n' and contains only a one '\n' @@ -760,3 +750,27 @@ std::string ErrorLogger::plistData(const ErrorLogger::ErrorMessage &msg) return plist.str(); } + +std::string replaceStr(std::string s, const std::string &from, const std::string &to) +{ + std::string::size_type pos1 = 0; + while (pos1 < s.size()) { + pos1 = s.find(from, pos1); + if (pos1 == std::string::npos) + return s; + if (pos1 > 0 && (s[pos1-1] == '_' || std::isalnum(s[pos1-1]))) { + pos1++; + continue; + } + const std::string::size_type pos2 = pos1 + from.size(); + if (pos2 >= s.size()) + return s.substr(0,pos1) + to; + if (s[pos2] == '_' || std::isalnum(s[pos2])) { + pos1++; + continue; + } + s = s.substr(0,pos1) + to + s.substr(pos2); + pos1 += to.size(); + } + return s; +} diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 61554b8d1..cedda5ad7 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -391,6 +391,9 @@ public: } }; +/** Replace substring. Example replaceStr("1,NR,3", "NR", "2") => "1,2,3" */ +std::string replaceStr(std::string s, const std::string &from, const std::string &to); + /// @} //--------------------------------------------------------------------------- #endif // errorloggerH