mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
AK: Add String constructor from ReadonlyBytes.
This commit is contained in:
parent
42b4880653
commit
75cde94c6a
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)
|
String(const StringImpl& impl)
|
||||||
: m_impl(const_cast<StringImpl&>(impl))
|
: m_impl(const_cast<StringImpl&>(impl))
|
||||||
{
|
{
|
||||||
|
@ -196,6 +201,18 @@ public:
|
||||||
return *this;
|
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
|
u32 hash() const
|
||||||
{
|
{
|
||||||
if (!m_impl)
|
if (!m_impl)
|
||||||
|
|
|
@ -133,6 +133,11 @@ RefPtr<StringImpl> StringImpl::create(const char* cstring, ShouldChomp shouldCho
|
||||||
return create(cstring, strlen(cstring), shouldChomp);
|
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)
|
static inline bool is_ascii_lowercase(char c)
|
||||||
{
|
{
|
||||||
return c >= 'a' && c <= 'z';
|
return c >= 'a' && c <= 'z';
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
static NonnullRefPtr<StringImpl> create_uninitialized(size_t length, char*& buffer);
|
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, ShouldChomp = NoChomp);
|
||||||
static RefPtr<StringImpl> create(const char* cstring, size_t length, 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_lowercase() const;
|
||||||
NonnullRefPtr<StringImpl> to_uppercase() const;
|
NonnullRefPtr<StringImpl> to_uppercase() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue