File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -162,17 +162,21 @@ std::string escape(const std::string &s)
162
162
163
163
// / Replace all occurrences of a string inside a string
164
164
// / \param [out] str: string to search
165
- // / \param from: string to replace
165
+ // / \param from: string to replace; must be non-empty
166
166
// / \param to: string to replace with
167
167
// / Copyright notice:
168
168
// / Attributed to Gauthier Boaglio
169
169
// / Source: https://stackoverflow.com/a/24315631/7501486
170
170
// / Used under MIT license
171
+ // / Note that this is quadratic in str.size() if from.size() != to.size().
172
+ // / There is no guarantee that it is linear in str.size() if
173
+ // / from.size() == to.size().
171
174
void replace_all (
172
175
std::string &str,
173
176
const std::string &from,
174
177
const std::string &to)
175
178
{
179
+ PRECONDITION (!from.empty ());
176
180
size_t start_pos = 0 ;
177
181
while ((start_pos = str.find (from, start_pos)) != std::string::npos)
178
182
{
You can’t perform that action at this time.
0 commit comments