MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / try_insert

Method try_insert

include/stringzilla/stringzilla.hpp:3489–3500  ·  view source on GitHub ↗

* @brief Inserts @b (in-place) a range of characters at a given signed offset. * @return `true` if the insertion was successful, `false` otherwise. */

Source from the content-addressed store, hash-verified

3487 * @return `true` if the insertion was successful, `false` otherwise.
3488 */
3489 bool try_insert(difference_type signed_offset, string_view string) noexcept {
3490 sz_size_t normalized_offset, normalized_length;
3491 sz_ssize_clamp_interval(size(), signed_offset, 0, &normalized_offset, &normalized_length);
3492 if (_with_alloc([&](sz_alloc_type &alloc) {
3493 return sz_string_expand(&string_, normalized_offset, string.size(), &alloc) ? sz_success_k
3494 : sz_bad_alloc_k;
3495 }) != status_t::success_k)
3496 return false;
3497
3498 sz_copy(data() + normalized_offset, string.data(), string.size());
3499 return true;
3500 }
3501
3502 /**
3503 * @brief Replaces @b (in-place) a range of characters with a given string.

Callers

nothing calls this directly

Calls 6

sz_ssize_clamp_intervalFunction · 0.85
_with_allocFunction · 0.85
sz_string_expandFunction · 0.85
sz_copyFunction · 0.70
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected