replace_all_copy.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_MARKDOWN_REPLACE_ALL_COPY_HPP
13 #define MLPACK_BINDINGS_MARKDOWN_REPLACE_ALL_COPY_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 // Replaces all occurences of "from" in "str" to "to".
18 inline std::string ReplaceAllCopy(const std::string& str,
19  const std::string& from,
20  const std::string& to)
21 {
22  std::string strCopy = str;
23  size_t startPos = 0;
24  while ((startPos = strCopy.find(from, startPos)) != std::string::npos)
25  {
26  strCopy.replace(startPos, from.length(), to);
27  startPos += to.length(); // Handles case where 'to' is a substring of 'from'
28  }
29  return strCopy;
30 }
31 
32 #endif
The core includes that mlpack expects; standard C++ includes, Armadillo, cereal, and a few basic mlpa...
std::string ReplaceAllCopy(const std::string &str, const std::string &from, const std::string &to)