| 9 | namespace jinja { |
| 10 | |
| 11 | static void string_replace_all(std::string & s, const std::string & search, const std::string & replace) { |
| 12 | if (search.empty()) { |
| 13 | return; |
| 14 | } |
| 15 | std::string builder; |
| 16 | builder.reserve(s.length()); |
| 17 | size_t pos = 0; |
| 18 | size_t last_pos = 0; |
| 19 | while ((pos = s.find(search, last_pos)) != std::string::npos) { |
| 20 | builder.append(s, last_pos, pos - last_pos); |
| 21 | builder.append(replace); |
| 22 | last_pos = pos + search.length(); |
| 23 | } |
| 24 | builder.append(s, last_pos, std::string::npos); |
| 25 | s = std::move(builder); |
| 26 | } |
| 27 | |
| 28 | // for displaying source code around error position |
| 29 | static std::string peak_source(const std::string & source, size_t pos, size_t max_peak_chars = 40) { |
no test coverage detected