summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-06 20:39:11 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-07 09:58:38 +0000
commitf23b55ae8681c818add83e025fca5a3e7282bda8 (patch)
tree035da09e31a5fbb531a97d04c2dcf8cad9641841
parentdaec065fdea58840444e61ccfdb71bf6514fa6d5 (diff)
downloadserenity-f23b55ae8681c818add83e025fca5a3e7282bda8.zip
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.
-rw-r--r--AK/StringView.cpp7
-rw-r--r--AK/StringView.h2
2 files changed, 9 insertions, 0 deletions
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 <AK/DeprecatedString.h>
# include <AK/FlyString.h>
+# include <AK/String.h>
#endif
namespace AK {
#ifndef KERNEL
+StringView::StringView(String const& string)
+ : m_characters(reinterpret_cast<char const*>(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