diff --git a/AK/String.h b/AK/String.h index 061d697b09..52c006e0be 100644 --- a/AK/String.h +++ b/AK/String.h @@ -142,6 +142,7 @@ public: bool is_null() const { return !m_impl; } ALWAYS_INLINE bool is_empty() const { return length() == 0; } ALWAYS_INLINE size_t length() const { return m_impl ? m_impl->length() : 0; } + // Includes NUL-terminator, if non-nullptr. ALWAYS_INLINE const char* characters() const { return m_impl ? m_impl->characters() : nullptr; } ALWAYS_INLINE ReadonlyBytes bytes() const { return m_impl ? m_impl->bytes() : nullptr; } diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 47ae2c6905..e85798a06c 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -59,6 +59,7 @@ public: ~StringImpl(); size_t length() const { return m_length; } + // Includes NUL-terminator. const char* characters() const { return &m_inline_buffer[0]; } ALWAYS_INLINE ReadonlyBytes bytes() const { return { characters(), length() }; }