FastLED 3.9.15
Loading...
Searching...
No Matches

◆ erase() [1/3]

basic_string & fl::basic_string::erase ( fl::size pos = 0,
fl::size count = npos )

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

897 {
898 if (pos >= mLength) return *this;
899
900 fl::size actualCount = count;
901 if (actualCount == npos || pos + actualCount > mLength) {
902 actualCount = mLength - pos;
903 }
904 if (actualCount == 0) return *this;
905
906 // Handle COW
907 if (hasHeapData() && heapData().get().use_count() > 1) {
908 const NotNullStringHolderPtr& heap = heapData();
910 if (pos > 0) fl::memcpy(newData->data(), heap->data(), pos);
911 fl::size remainingLen = mLength - pos - actualCount;
912 if (remainingLen > 0) {
913 fl::memcpy(newData->data() + pos, heap->data() + pos + actualCount, remainingLen);
914 }
915 mLength = mLength - actualCount;
916 newData->data()[mLength] = '\0';
917 mStorage = newData;
918 return *this;
919 }
920
921 fl::size remainingLen = mLength - pos - actualCount;
922 if (remainingLen > 0) {
923 char* data = c_str_mutable();
924 fl::memmove(data + pos, data + pos + actualCount, remainingLen);
925 }
926 mLength -= actualCount;
927 c_str_mutable()[mLength] = '\0';
928 return *this;
929}
uint8_t pos
Definition Blur.ino:11
bool hasHeapData() const FL_NOEXCEPT
NotNullStringHolderPtr & heapData() FL_NOEXCEPT
static constexpr fl::size npos
const char * data() const FL_NOEXCEPT
fl::variant< NotNullStringHolderPtr, ConstLiteral, ConstView > mStorage
char * c_str_mutable() FL_NOEXCEPT
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
fl::not_null< StringHolderPtr > NotNullStringHolderPtr
void * memmove(void *dest, const void *src, size_t n) FL_NOEXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
pair_element< I, T1, T2 >::type & get(pair< T1, T2 > &p) FL_NOEXCEPT
Definition pair.h:115

References basic_string(), c_str_mutable(), data(), fl::get(), hasHeapData(), heapData(), fl::make_shared(), fl::memcpy(), fl::memmove(), mLength, mStorage, npos, and pos.

Referenced by erase(), erase(), replace(), replace(), and replace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: