| 440 | } |
| 441 | |
| 442 | void string_replace_all(std::string & s, const std::string & search, const std::string & replace) { |
| 443 | if (search.empty()) { |
| 444 | return; |
| 445 | } |
| 446 | std::string builder; |
| 447 | builder.reserve(s.length()); |
| 448 | size_t pos = 0; |
| 449 | size_t last_pos = 0; |
| 450 | while ((pos = s.find(search, last_pos)) != std::string::npos) { |
| 451 | builder.append(s, last_pos, pos - last_pos); |
| 452 | builder.append(replace); |
| 453 | last_pos = pos + search.length(); |
| 454 | } |
| 455 | builder.append(s, last_pos, std::string::npos); |
| 456 | s = std::move(builder); |
| 457 | } |
| 458 | |
| 459 | bool string_ends_with(const std::string_view & str, const std::string_view & suffix) { |
| 460 | return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0; |
no test coverage detected