From 50677a58d4d48160e223c2de53ddb8e8e56da030 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 29 Jun 2019 12:03:28 +0200 Subject: [PATCH] StringView: Make it easy to construct from a ByteBuffer. --- AK/StringView.cpp | 6 ++++++ AK/StringView.h | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 94cbf9d3568..1c67e2e28cb 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -10,6 +10,12 @@ StringView::StringView(const String& string) { } +StringView::StringView(const ByteBuffer& buffer) + : m_characters((const char*)buffer.data()) + , m_length(buffer.size()) +{ +} + Vector StringView::split_view(const char separator) const { if (is_empty()) diff --git a/AK/StringView.h b/AK/StringView.h index 76335eeb04b..e90aecb3846 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -4,6 +4,7 @@ namespace AK { +class ByteBuffer; class String; class StringImpl; @@ -28,7 +29,9 @@ public: ++m_length; } } - StringView(const String& string); + + StringView(const ByteBuffer&); + StringView(const String&); bool is_null() const { return !m_characters; } bool is_empty() const { return m_length == 0; }