FastLED 3.10.6
Loading...
Searching...
No Matches

◆ insert() [4/5]

basic_string & fl::basic_string::insert ( fl::size pos,
const char * s,
fl::size count )

Definition at line 858 of file basic_string.cpp.hpp.

858 {
859 if (pos > mLength) pos = mLength;
860 if (!s || count == 0) return *this;
861
862 // Materialize non-owning storage before modifying
863 if (isNonOwning()) {
864 materialize();
865 }
866
867 fl::size newLen = mLength + count;
868
869 // Handle COW
870 if (hasHeapData() && heapData().get().use_count() > 1) {
871 const NotNullStringHolderPtr& heap = heapData();
873 if (pos > 0) fl::memcpy(newData->data(), heap->data(), pos);
874 fl::memcpy(newData->data() + pos, s, count);
875 if (pos < mLength) fl::memcpy(newData->data() + pos + count, heap->data() + pos, mLength - pos);
876 newData->data()[newLen] = '\0';
877 mStorage = newData;
878 mLength = newLen;
879 return *this;
880 }
881
882 // Inline buffer
883 if (newLen + 1 <= mInlineCapacity && !hasHeapData()) {
884 if (pos < mLength) {
886 }
887 fl::memcpy(inlineBufferPtr() + pos, s, count);
888 mLength = newLen;
889 inlineBufferPtr()[mLength] = '\0';
890 return *this;
891 }
892
893 // Heap in-place or new allocation
894 bool canInsertInPlace = hasHeapData();
895 if (canInsertInPlace) {
897 canInsertInPlace = heap.get().use_count() <= 1 && heap->hasCapacity(newLen);
898 if (canInsertInPlace) {
899 char* data = heap->data();
900 if (pos < mLength) fl::memmove(data + pos + count, data + pos, mLength - pos);
901 fl::memcpy(data + pos, s, count);
902 mLength = newLen;
903 data[mLength] = '\0';
904 }
905 }
906 if (!canInsertInPlace) {
908 const char* src = c_str();
909 if (pos > 0) fl::memcpy(newData->data(), src, pos);
910 fl::memcpy(newData->data() + pos, s, count);
911 if (pos < mLength) fl::memcpy(newData->data() + pos + count, src + pos, mLength - pos);
912 newData->data()[newLen] = '\0';
913 mStorage = newData;
914 mLength = newLen;
915 }
916 return *this;
917}
uint8_t pos
Definition Blur.ino:11
bool isNonOwning() const FL_NO_EXCEPT
void materialize() FL_NO_EXCEPT
NotNullStringHolderPtr & heapData() FL_NO_EXCEPT
bool hasHeapData() const FL_NO_EXCEPT
fl::size mInlineCapacity
char * inlineBufferPtr() FL_NO_EXCEPT
fl::variant< NotNullStringHolderPtr, ConstLiteral, ConstView > mStorage
const char * c_str() const FL_NO_EXCEPT
const char * data() const FL_NO_EXCEPT
fl::not_null< StringHolderPtr > NotNullStringHolderPtr
void * memcpy(void *dest, const void *src, size_t n) FL_NO_EXCEPT
void * memmove(void *dest, const void *src, size_t n) FL_NO_EXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:414
pair_element< I, T1, T2 >::type & get(pair< T1, T2 > &p) FL_NO_EXCEPT
Definition pair.h:115

References basic_string(), c_str(), data(), fl::get(), fl::not_null< T >::get(), hasHeapData(), heapData(), inlineBufferPtr(), isNonOwning(), fl::make_shared(), materialize(), fl::memcpy(), fl::memmove(), mInlineCapacity, mLength, mStorage, pos, and fl::shared_ptr< T >::use_count().

+ Here is the call graph for this function: