1 | // LAF Base Library |
2 | // Copyright (c) 2001-2016 David Capello |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "base/replace_string.h" |
12 | |
13 | namespace base { |
14 | |
15 | void replace_string( |
16 | std::string& subject, |
17 | const std::string& replace_this, |
18 | const std::string& with_that) |
19 | { |
20 | if (replace_this.empty()) // Do nothing case |
21 | return; |
22 | |
23 | std::size_t i = 0; |
24 | while (true) { |
25 | i = subject.find(replace_this, i); |
26 | if (i == std::string::npos) |
27 | break; |
28 | subject.replace(i, replace_this.size(), with_that); |
29 | i += with_that.size(); |
30 | } |
31 | } |
32 | |
33 | } // namespace base |
34 | |