diff options
-rw-r--r-- | AK/String.h | 17 | ||||
-rw-r--r-- | AK/StringImpl.cpp | 5 | ||||
-rw-r--r-- | AK/StringImpl.h | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/AK/String.h b/AK/String.h index 3c175562d3..e1c5effef7 100644 --- a/AK/String.h +++ b/AK/String.h @@ -83,6 +83,11 @@ public: { } + explicit String(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp) + : m_impl(StringImpl::create(bytes, shouldChomp)) + { + } + String(const StringImpl& impl) : m_impl(const_cast<StringImpl&>(impl)) { @@ -196,6 +201,18 @@ public: return *this; } + String& operator=(std::nullptr_t) + { + m_impl = nullptr; + return *this; + } + + String& operator=(ReadonlyBytes bytes) + { + m_impl = StringImpl::create(bytes); + return *this; + } + u32 hash() const { if (!m_impl) diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 88b5b8f24e..f90d0e632a 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -133,6 +133,11 @@ RefPtr<StringImpl> StringImpl::create(const char* cstring, ShouldChomp shouldCho return create(cstring, strlen(cstring), shouldChomp); } +RefPtr<StringImpl> StringImpl::create(ReadonlyBytes bytes, ShouldChomp shouldChomp) +{ + return StringImpl::create(reinterpret_cast<const char*>(bytes.data()), bytes.size(), shouldChomp); +} + static inline bool is_ascii_lowercase(char c) { return c >= 'a' && c <= 'z'; diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 721144e68b..47ae2c6905 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -45,6 +45,7 @@ public: static NonnullRefPtr<StringImpl> create_uninitialized(size_t length, char*& buffer); static RefPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp); static RefPtr<StringImpl> create(const char* cstring, size_t length, ShouldChomp = NoChomp); + static RefPtr<StringImpl> create(ReadonlyBytes, ShouldChomp = NoChomp); NonnullRefPtr<StringImpl> to_lowercase() const; NonnullRefPtr<StringImpl> to_uppercase() const; |