summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-06-02 12:19:21 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-02 12:55:51 +0200
commitb55b6cd7fcaa8518e4901d4ec5bd0a9da5b28fc0 (patch)
tree31cb4731fd477522fd6866b6433f6957d421cca4 /AK
parentdecf1afbaa44d9083137675159ae2fc280f2b1ac (diff)
downloadserenity-b55b6cd7fcaa8518e4901d4ec5bd0a9da5b28fc0.zip
AK: Add implicit String -> StringView conversion
And tidy up existing view() users.
Diffstat (limited to 'AK')
-rw-r--r--AK/String.cpp2
-rw-r--r--AK/StringView.cpp8
-rw-r--r--AK/StringView.h1
3 files changed, 9 insertions, 2 deletions
diff --git a/AK/String.cpp b/AK/String.cpp
index 5ec6f355ee..ed3943318c 100644
--- a/AK/String.cpp
+++ b/AK/String.cpp
@@ -111,7 +111,7 @@ Vector<StringView> String::split_view(const char separator) const
if (taillen != 0)
v.append(substring_view(substart, taillen));
if (characters()[length() - 1] == separator)
- v.append(empty().view());
+ v.append(empty());
return v;
}
diff --git a/AK/StringView.cpp b/AK/StringView.cpp
index 77fc057c39..c2f538be84 100644
--- a/AK/StringView.cpp
+++ b/AK/StringView.cpp
@@ -3,6 +3,12 @@
namespace AK {
+StringView::StringView(const AK::String& string)
+ : m_characters(string.characters())
+ , m_length(string.length())
+{
+}
+
Vector<StringView> StringView::split_view(const char separator) const
{
if (is_empty())
@@ -23,7 +29,7 @@ Vector<StringView> StringView::split_view(const char separator) const
if (taillen != 0)
v.append(substring_view(substart, taillen));
if (characters()[length() - 1] == separator)
- v.append(String::empty().view());
+ v.append(String::empty());
return v;
}
diff --git a/AK/StringView.h b/AK/StringView.h
index ced68488a0..4ef404c8e0 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -27,6 +27,7 @@ public:
++m_length;
}
}
+ StringView(const AK::String& string);
bool is_empty() const { return m_length == 0; }
const char* characters() const { return m_characters; }