MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / replace_substring

Method replace_substring

lib/json/json.hpp:9915–9927  ·  view source on GitHub ↗

! @brief replace all occurrences of a substring by another string @param[in,out] s the string to manipulate @param[in] f the substring to replace with @a t @param[in] t the string to replace @a f @return The string @a s where all occurrences of @a f are replaced with @a t. @pre The search string @a f must not be empty.

Source from the content-addressed store, hash-verified

9913 @since version 2.0.0
9914 */
9915 static void replace_substring(std::string& s,
9916 const std::string& f,
9917 const std::string& t)
9918 {
9919 assert(not f.empty());
9920
9921 for (
9922 size_t pos = s.find(f); // find first occurrence of f
9923 pos != std::string::npos; // make sure f was found
9924 s.replace(pos, f.size(), t), // replace with t
9925 pos = s.find(f, pos + t.size()) // find next occurrence of f
9926 );
9927 }
9928
9929 /// escape tilde and slash
9930 static std::string escape(std::string s)

Callers

nothing calls this directly

Calls 4

findMethod · 0.80
replaceMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected