File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -148,3 +148,24 @@ std::string escape(const std::string &s)
148
148
149
149
return result;
150
150
}
151
+
152
+ // / Replace all occurrences of a string inside a string
153
+ // / \param [out] str: string to search
154
+ // / \param from: string to replace
155
+ // / \param to: string to replace with
156
+ // / Copyright notice:
157
+ // / Attributed to Gauthier Boaglio
158
+ // / Source: https://stackoverflow.com/a/24315631/7501486
159
+ // / Used under MIT license
160
+ void replace_all (
161
+ std::string &str,
162
+ const std::string &from,
163
+ const std::string &to)
164
+ {
165
+ size_t start_pos = 0 ;
166
+ while ((start_pos = str.find (from, start_pos)) != std::string::npos)
167
+ {
168
+ str.replace (start_pos, from.length (), to);
169
+ start_pos += to.length ();
170
+ }
171
+ }
Original file line number Diff line number Diff line change @@ -67,4 +67,6 @@ Stream &join_strings(
67
67
// / programming language.
68
68
std::string escape (const std::string &);
69
69
70
+ void replace_all (std::string &, const std::string &, const std::string &);
71
+
70
72
#endif
You can’t perform that action at this time.
0 commit comments