From f23b55ae8681c818add83e025fca5a3e7282bda8 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 6 Dec 2022 20:39:11 +0000 Subject: [PATCH] AK: Add StringView(String const&) constructor This allows us to pass the new String type to functions that take a StringView directly, having to call bytes_as_string_view() every time gets old quickly. --- AK/StringView.cpp | 7 +++++++ AK/StringView.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/AK/StringView.cpp b/AK/StringView.cpp index f6b6c3648d..f299ab707b 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -16,11 +16,18 @@ #ifndef KERNEL # include # include +# include #endif namespace AK { #ifndef KERNEL +StringView::StringView(String const& string) + : m_characters(reinterpret_cast(string.bytes().data())) + , m_length(string.bytes().size()) +{ +} + StringView::StringView(DeprecatedString const& string) : m_characters(string.characters()) , m_length(string.length()) diff --git a/AK/StringView.h b/AK/StringView.h index d846e2eb08..f238601ae0 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -42,12 +42,14 @@ public: StringView(ByteBuffer const&); #ifndef KERNEL + StringView(String const&); StringView(DeprecatedString const&); StringView(FlyString const&); #endif explicit StringView(ByteBuffer&&) = delete; #ifndef KERNEL + explicit StringView(String&&) = delete; explicit StringView(DeprecatedString&&) = delete; explicit StringView(FlyString&&) = delete; #endif