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

◆ c_str_mutable()

char * fl::basic_string::c_str_mutable ( )

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

42 {
43 // Inline mode — already mutable
44 if (mStorage.empty()) {
45 return inlineBufferPtr();
46 }
47 struct Visitor {
48 basic_string* self;
49 char* result;
50 void accept(NotNullStringHolderPtr& heap) {
51 if (heap.get().use_count() > 1) {
52 // COW: detach from shared data before returning mutable pointer
53 self->mStorage = NotNullStringHolderPtr(
54 fl::make_shared<StringHolder>(heap->data(), self->mLength));
55 result = self->heapData()->data();
56 } else {
57 result = heap->data();
58 }
59 }
60 void accept(ConstLiteral&) {
61 self->materialize();
62 result = self->hasHeapData() ? self->heapData()->data()
63 : self->inlineBufferPtr();
64 }
65 void accept(ConstView&) {
66 self->materialize();
67 result = self->hasHeapData() ? self->heapData()->data()
68 : self->inlineBufferPtr();
69 }
70 };
71 Visitor v{this, nullptr};
72 mStorage.visit(v);
73 return v.result;
74}
fl::variant< NotNullStringHolderPtr, ConstLiteral, ConstView > mStorage
char * inlineBufferPtr() FL_NOEXCEPT
fl::not_null< StringHolderPtr > NotNullStringHolderPtr
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References basic_string(), fl::not_null< T >::get(), hasHeapData(), heapData(), inlineBufferPtr(), fl::make_shared(), materialize(), mLength, mStorage, and fl::shared_ptr< T >::use_count().

Referenced by at(), begin(), clear(), end(), erase(), operator[](), pop_back(), and resize().

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