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

◆ c_str_mutable()

char * fl::basic_string::c_str_mutable ( )

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

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