From 5d0fda3d39c978f06744863c8808218431665c94 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 10 Dec 2020 18:57:56 +0100 Subject: [PATCH] AK: Add String::substring(start) This is a convenience API when you just want the rest of the string starting at some index. We already had substring_view() in the same flavor, so this is a complement to that. --- AK/String.cpp | 7 +++++++ AK/String.h | 1 + 2 files changed, 8 insertions(+) diff --git a/AK/String.cpp b/AK/String.cpp index 3e188c49e8..c7315f2b5b 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -129,6 +129,13 @@ String String::isolated_copy() const return String(move(*impl)); } +String String::substring(size_t start) const +{ + ASSERT(m_impl); + ASSERT(start <= length()); + return { characters() + start, length() - start }; +} + String String::substring(size_t start, size_t length) const { if (!length) diff --git a/AK/String.h b/AK/String.h index f854911313..edeceeb87b 100644 --- a/AK/String.h +++ b/AK/String.h @@ -134,6 +134,7 @@ public: Vector split_limit(char separator, size_t limit, bool keep_empty = false) const; Vector split(char separator, bool keep_empty = false) const; + String substring(size_t start) const; String substring(size_t start, size_t length) const; Vector split_view(char separator, bool keep_empty = false) const;