Skip to content

Commit 366d563

Browse files
author
Daniel Kroening
committed
add replace_all documentation
1 parent 5e68531 commit 366d563

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/util/string_utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,21 @@ std::string escape(const std::string &s)
162162

163163
/// Replace all occurrences of a string inside a string
164164
/// \param [out] str: string to search
165-
/// \param from: string to replace
165+
/// \param from: string to replace; must be non-empty
166166
/// \param to: string to replace with
167167
/// Copyright notice:
168168
/// Attributed to Gauthier Boaglio
169169
/// Source: https://stackoverflow.com/a/24315631/7501486
170170
/// 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().
171174
void replace_all(
172175
std::string &str,
173176
const std::string &from,
174177
const std::string &to)
175178
{
179+
PRECONDITION(!from.empty());
176180
size_t start_pos = 0;
177181
while((start_pos = str.find(from, start_pos)) != std::string::npos)
178182
{

0 commit comments

Comments
 (0)