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.
This commit is contained in:
Andreas Kling 2020-12-10 18:57:56 +01:00
parent e9280cba13
commit 5d0fda3d39
2 changed files with 8 additions and 0 deletions

View file

@ -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)

View file

@ -134,6 +134,7 @@ public:
Vector<String> split_limit(char separator, size_t limit, bool keep_empty = false) const;
Vector<String> split(char separator, bool keep_empty = false) const;
String substring(size_t start) const;
String substring(size_t start, size_t length) const;
Vector<StringView> split_view(char separator, bool keep_empty = false) const;