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;