From 78eff163eab995a731f7bf1c347a3240d9368d00 Mon Sep 17 00:00:00 2001 From: asynts Date: Tue, 1 Dec 2020 23:11:20 +0100 Subject: [PATCH] AK: Add String::substring_view(size_t). --- AK/String.cpp | 7 +++++++ AK/String.h | 1 + 2 files changed, 8 insertions(+) diff --git a/AK/String.cpp b/AK/String.cpp index 6d5ca976274..3e188c49e88 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -147,6 +147,13 @@ StringView String::substring_view(size_t start, size_t length) const return { characters() + start, length }; } +StringView String::substring_view(size_t start) const +{ + ASSERT(m_impl); + ASSERT(start <= length()); + return { characters() + start, length() - start }; +} + Vector String::split(char separator, bool keep_empty) const { return split_limit(separator, 0, keep_empty); diff --git a/AK/String.h b/AK/String.h index 51e3c51de02..f8549113130 100644 --- a/AK/String.h +++ b/AK/String.h @@ -138,6 +138,7 @@ public: Vector split_view(char separator, bool keep_empty = false) const; StringView substring_view(size_t start, size_t length) const; + StringView substring_view(size_t start) const; bool is_null() const { return !m_impl; } ALWAYS_INLINE bool is_empty() const { return length() == 0; }