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

Method try_replace

include/stringzilla/stringzilla.hpp:3506–3514  ·  view source on GitHub ↗

* @brief Replaces @b (in-place) a range of characters with a given string. * @return `true` if the replacement was successful, `false` otherwise. */

Source from the content-addressed store, hash-verified

3504 * @return `true` if the replacement was successful, `false` otherwise.
3505 */
3506 bool try_replace(difference_type signed_start_offset, difference_type signed_end_offset,
3507 string_view replacement) noexcept {
3508
3509 sz_size_t normalized_offset, normalized_length;
3510 sz_ssize_clamp_interval(size(), signed_start_offset, signed_end_offset, &normalized_offset, &normalized_length);
3511 if (!try_preparing_replacement(normalized_offset, normalized_length, replacement.size())) return false;
3512 sz_copy(data() + normalized_offset, replacement.data(), replacement.size());
3513 return true;
3514 }
3515
3516 /**
3517 * @brief Resizes the string to a specified number of characters without initializing new elements.

Callers 1

Calls 4

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

Tested by

no test coverage detected