| 4487 | |
| 4488 | template <typename char_type_, typename allocator_> |
| 4489 | bool basic_string<char_type_, allocator_>::try_preparing_replacement( // |
| 4490 | size_type offset, size_type length, size_type replacement_length) noexcept { |
| 4491 | |
| 4492 | // There are three cases: |
| 4493 | // 1. The replacement is the same length as the replaced range. |
| 4494 | // 2. The replacement is shorter than the replaced range. |
| 4495 | // 3. The replacement is longer than the replaced range. An allocation may occur. |
| 4496 | assert(offset + length <= size()); |
| 4497 | |
| 4498 | // 1. The replacement is the same length as the replaced range. |
| 4499 | if (replacement_length == length) return true; |
| 4500 | |
| 4501 | // 2. The replacement is shorter than the replaced range. |
| 4502 | else if (replacement_length < length) { |
| 4503 | sz_string_erase(&string_, offset + replacement_length, length - replacement_length); |
| 4504 | return true; |
| 4505 | } |
| 4506 | // 3. The replacement is longer than the replaced range. An allocation may occur. |
| 4507 | else { |
| 4508 | auto result = _with_alloc([&](sz_alloc_type &alloc) { |
| 4509 | return sz_string_expand(&string_, offset + length, replacement_length - length, &alloc) ? sz_success_k |
| 4510 | : sz_bad_alloc_k; |
| 4511 | }); |
| 4512 | return result == status_t::success_k; |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | /** |
| 4517 | * @brief Helper function-like object to order string-view convertible objects with StringZilla. |
nothing calls this directly
no test coverage detected