string_view: A non-owning view into a contiguous sequence of characters Provides std::string_view-like functionality for embedded environments Does NOT allocate memory or manage ownership Similar to span but with string-specific operations
| 15 | // Does NOT allocate memory or manage ownership |
| 16 | // Similar to span<const char> but with string-specific operations |
| 17 | class string_view { |
| 18 | public: |
| 19 | // ======= STANDARD CONTAINER TYPE ALIASES ======= |
| 20 | using element_type = const char; |
| 21 | using value_type = char; |
| 22 | using size_type = fl::size; |
| 23 | using difference_type = fl::i32; |
| 24 | using pointer = const char*; |
| 25 | using const_pointer = const char*; |
| 26 | using reference = const char&; |
| 27 | using const_reference = const char&; |
| 28 | using iterator = const char*; |
| 29 | using const_iterator = const char*; |
| 30 | using reverse_iterator = const char*; |
| 31 | using const_reverse_iterator = const char*; |
| 32 | |
| 33 | // Special value to indicate "not found" or "until end" |
| 34 | // Using constexpr for C++11 implicit inline semantics - no ODR definition needed |
| 35 | static constexpr fl::size npos = static_cast<fl::size>(-1); |
| 36 | |
| 37 | // ======= CONSTRUCTORS ======= |
| 38 | // Default constructor - empty view |
| 39 | constexpr string_view() FL_NOEXCEPT : mData(nullptr), mSize(0) {} |
| 40 | |
| 41 | // Constructor from null-terminated C string |
| 42 | constexpr string_view(const char* str) FL_NOEXCEPT |
| 43 | : mData(str), mSize(str ? strlen(str) : 0) {} |
| 44 | |
| 45 | // Constructor from pointer and length |
| 46 | constexpr string_view(const char* str, fl::size len) FL_NOEXCEPT |
| 47 | : mData(str), mSize(len) {} |
| 48 | |
| 49 | // Constructor from C-array |
| 50 | template <fl::size N> |
| 51 | constexpr string_view(const char (&arr)[N]) FL_NOEXCEPT |
| 52 | : mData(arr), mSize(N - 1) {} // Subtract 1 for null terminator |
| 53 | |
| 54 | // Constructor from fl::basic_string (and therefore fl::string). |
| 55 | // Defined in basic_string.cpp.hpp where basic_string is complete. |
| 56 | string_view(const basic_string& str) FL_NOEXCEPT; |
| 57 | |
| 58 | // Copy constructor |
| 59 | string_view(const string_view& other) FL_NOEXCEPT = default; |
| 60 | |
| 61 | // Assignment operator |
| 62 | string_view& operator=(const string_view& other) = default; |
| 63 | |
| 64 | // ======= ITERATORS ======= |
| 65 | constexpr iterator begin() const FL_NOEXCEPT { return mData; } |
| 66 | constexpr iterator end() const FL_NOEXCEPT { return mData + mSize; } |
| 67 | constexpr const_iterator cbegin() const FL_NOEXCEPT { return mData; } |
| 68 | constexpr const_iterator cend() const FL_NOEXCEPT { return mData + mSize; } |
| 69 | |
| 70 | constexpr reverse_iterator rbegin() const FL_NOEXCEPT { return mData + mSize - 1; } |
| 71 | constexpr reverse_iterator rend() const FL_NOEXCEPT { return mData - 1; } |
| 72 | constexpr const_reverse_iterator crbegin() const FL_NOEXCEPT { return mData + mSize - 1; } |
| 73 | constexpr const_reverse_iterator crend() const FL_NOEXCEPT { return mData - 1; } |
| 74 |
no outgoing calls