| 429 | } |
| 430 | |
| 431 | void string_replace_all(std::string & s, const std::string & search, const std::string & replace) { |
| 432 | if (search.empty()) { |
| 433 | return; |
| 434 | } |
| 435 | std::string builder; |
| 436 | builder.reserve(s.length()); |
| 437 | size_t pos = 0; |
| 438 | size_t last_pos = 0; |
| 439 | while ((pos = s.find(search, last_pos)) != std::string::npos) { |
| 440 | builder.append(s, last_pos, pos - last_pos); |
| 441 | builder.append(replace); |
| 442 | last_pos = pos + search.length(); |
| 443 | } |
| 444 | builder.append(s, last_pos, std::string::npos); |
| 445 | s = std::move(builder); |
| 446 | } |
| 447 | |
| 448 | bool string_ends_with(const std::string_view & str, const std::string_view & suffix) { |
| 449 | return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0; |
no test coverage detected