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

Method try_append

include/stringzilla/stringzilla.hpp:4347–4367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4345
4346template <typename char_type_, typename allocator_>
4347bool basic_string<char_type_, allocator_>::try_append(const_pointer str, size_type length) noexcept {
4348 auto result = _with_alloc([&](sz_alloc_type &alloc) {
4349 // Sometimes we are inserting part of this string into itself.
4350 // By the time `sz_string_expand` finished, the old `str` pointer may be invalidated,
4351 // so we need to handle that special case separately.
4352 auto this_span = span();
4353 if (str >= this_span.begin() && str < this_span.end()) {
4354 auto str_offset_in_this = str - data();
4355 sz_ptr_t start = sz_string_expand(&string_, SZ_SIZE_MAX, length, &alloc);
4356 if (!start) return sz_bad_alloc_k;
4357 sz_copy(start + this_span.size(), start + str_offset_in_this, length);
4358 }
4359 else {
4360 sz_ptr_t start = sz_string_expand(&string_, SZ_SIZE_MAX, length, &alloc);
4361 if (!start) return sz_bad_alloc_k;
4362 sz_copy(start + this_span.size(), str, length);
4363 }
4364 return sz_success_k;
4365 });
4366 return result == status_t::success_k;
4367}
4368
4369template <typename char_type_, typename allocator_>
4370template <typename pattern_type>

Callers 1

try_buildMethod · 0.45

Calls 7

_with_allocFunction · 0.85
spanClass · 0.85
sz_string_expandFunction · 0.85
sz_copyFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected