mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Add String constructor from ReadonlyBytes.
This commit is contained in:
parent
42b4880653
commit
75cde94c6a
Notes:
sideshowbarker
2024-07-19 04:14:28 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/75cde94c6a7 Pull-request: https://github.com/SerenityOS/serenity/pull/3007 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/nico
3 changed files with 23 additions and 0 deletions
17
AK/String.h
17
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)
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue