diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-06-02 12:19:21 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-02 12:55:51 +0200 |
commit | b55b6cd7fcaa8518e4901d4ec5bd0a9da5b28fc0 (patch) | |
tree | 31cb4731fd477522fd6866b6433f6957d421cca4 /AK | |
parent | decf1afbaa44d9083137675159ae2fc280f2b1ac (diff) | |
download | serenity-b55b6cd7fcaa8518e4901d4ec5bd0a9da5b28fc0.zip |
AK: Add implicit String -> StringView conversion
And tidy up existing view() users.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/String.cpp | 2 | ||||
-rw-r--r-- | AK/StringView.cpp | 8 | ||||
-rw-r--r-- | AK/StringView.h | 1 |
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; } |